@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()); }
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 { 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 { 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); }
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); }
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);  }