Server { private SubmitTransactionResponse submitTransaction(Transaction transaction, String url) throws IOException { URI transactionsUri = getUri(url); RequestBody formBody = new FormBody.Builder() .add("tx", transaction.toEnvelopeXdrBase64()) .build(); Request request = new Request.Builder() .url(transactionsUri.toString()) .post(formBody) .build(); Response response = null; try { response = httpClient.newCall(request).execute(); if (response != null) { String location = response.header(LOCATION_HEADER); if (response.code() == TEMPORARY_REDIRECT && location != null) { return submitTransaction(transaction, location); } else { ResponseBody body = response.body(); if (body != null) { String responseString = body.string(); return GsonSingleton.getInstance().fromJson(responseString, SubmitTransactionResponse.class); } } } } finally { if (response != null) { response.close(); } } return null; } Server(String uri);  Server(String uri, OkHttpClient client); AccountsRequestBuilder accounts(); EffectsRequestBuilder effects(); LedgersRequestBuilder ledgers(); OffersRequestBuilder offers(); OperationsRequestBuilder operations(); OrderBookRequestBuilder orderBook(); TradesRequestBuilder trades(); PathsRequestBuilder paths(); PaymentsRequestBuilder payments(); TransactionsRequestBuilder transactions(); SubmitTransactionResponse submitTransaction(Transaction transaction);  }
@Test public void testSubmitTransactionSuccess() throws IOException { mockWebServer.enqueue( new MockResponse() .setResponseCode(200) .setBody(successResponse) ); SubmitTransactionResponse response = server.submitTransaction(this.buildTransaction()); assertTrue(response.isSuccess()); assertEquals(response.getLedger(), new Long(826150L)); assertEquals(response.getHash(), "2634d2cf5adcbd3487d1df042166eef53830115844fdde1588828667bf93ff42"); assertNull(response.getExtras()); }
@Test public void test_ResponseCodeHttp307_SubmitTransactionSuccess() throws IOException { MockWebServer mockWebServerHttp307 = new MockWebServer(); mockWebServerHttp307.start(); String location = mockWebServerHttp307.url("/").url().toString(); mockWebServer.enqueue( new MockResponse() .setResponseCode(307) .setHeader("Location", location) ); mockWebServerHttp307.enqueue( new MockResponse() .setResponseCode(200) .setBody(successResponse) ); SubmitTransactionResponse response = server.submitTransaction(this.buildTransaction()); assertTrue(response.isSuccess()); assertEquals(response.getLedger(), new Long(826150L)); assertEquals(response.getHash(), "2634d2cf5adcbd3487d1df042166eef53830115844fdde1588828667bf93ff42"); assertNull(response.getExtras()); }
@Test public void testSubmitTransactionFail() throws IOException { mockWebServer.enqueue( new MockResponse() .setResponseCode(400) .setBody(failureResponse) ); SubmitTransactionResponse response = server.submitTransaction(this.buildTransaction()); assertFalse(response.isSuccess()); assertNull(response.getLedger()); assertNull(response.getHash()); assertEquals(response.getExtras().getEnvelopeXdr(), "AAAAAK4Pg4OEkjGmSN0AN37K/dcKyKPT2DC90xvjjawKp136AAAAZAAKsZQAAAABAAAAAAAAAAEAAAAJSmF2YSBGVFchAAAAAAAAAQAAAAAAAAABAAAAAG9wfBI7rRYoBlX3qRa0KOnI75W5BaPU6NbyKmm2t71MAAAAAAAAAAABMS0AAAAAAAAAAAEKp136AAAAQOWEjL+Sm+WP2puE9dLIxWlOibIEOz8PsXyG77jOCVdHZfQvkgB49Mu5wqKCMWWIsDSLFekwUsLaunvmXrpyBwQ="); assertEquals(response.getExtras().getResultXdr(), "AAAAAAAAAGT assertNotNull(response.getExtras()); assertEquals("tx_failed", response.getExtras().getResultCodes().getTransactionResultCode()); assertEquals("op_no_destination", response.getExtras().getResultCodes().getOperationsResultCodes().get(0)); }