@Test public void executeUnsafely_does_not_throw_HttpException_if_response_code_is_not_2xx() { server.enqueue(new MockResponse().setResponseCode(404).setBody("<error>")); HttpResponse response = newCall("api/system/ping").executeUnsafely(); assertThat(response.getCode()).isEqualTo(404); assertThat(response.getBodyAsString()).isEqualTo("<error>"); }
public HttpResponse executeUnsafely() { Request okRequest = buildOkHttpRequest(); try (Response okResponse = doExecute(okRequest)) { return HttpResponse.from(okResponse); } catch (IOException e) { throw new IllegalStateException(format("Can not call %s due to network failure", okRequest.url()), e); } }
HttpCall { public HttpResponse executeUnsafely() { Request okRequest = buildOkHttpRequest(); try (Response okResponse = doExecute(okRequest)) { return HttpResponse.from(okResponse); } catch (IOException e) { throw new IllegalStateException(format("Can not call %s due to network failure", okRequest.url()), e); } } }
HttpCall { public HttpResponse executeUnsafely() { Request okRequest = buildOkHttpRequest(); try (Response okResponse = doExecute(okRequest)) { return HttpResponse.from(okResponse); } catch (IOException e) { throw new IllegalStateException(format("Can not call %s due to network failure", okRequest.url()), e); } } HttpCall(OkHttpClient okClient, HttpUrl baseUrl); }
HttpCall { public HttpResponse executeUnsafely() { Request okRequest = buildOkHttpRequest(); try (Response okResponse = doExecute(okRequest)) { return HttpResponse.from(okResponse); } catch (IOException e) { throw new IllegalStateException(format("Can not call %s due to network failure", okRequest.url()), e); } } HttpCall(OkHttpClient okClient, HttpUrl baseUrl); HttpUrl getBaseUrl(); HttpCall setMethod(HttpMethod m); HttpCall setCredentials(String login, @Nullable String password); HttpCall setAdminCredentials(); HttpCall setAuthenticationToken(String token); HttpCall setParam(String key, @Nullable String value); HttpCall setParams(String key1, @Nullable String value1, String... otherKeysAndNames); HttpCall setHeader(String key, String value); HttpCall setTimeoutMs(long timeoutMs); HttpResponse execute(); HttpResponse executeUnsafely(); void downloadToFile(File file); File downloadToDirectory(File dir); }
HttpCall { public HttpResponse executeUnsafely() { Request okRequest = buildOkHttpRequest(); try (Response okResponse = doExecute(okRequest)) { return HttpResponse.from(okResponse); } catch (IOException e) { throw new IllegalStateException(format("Can not call %s due to network failure", okRequest.url()), e); } } HttpCall(OkHttpClient okClient, HttpUrl baseUrl); HttpUrl getBaseUrl(); HttpCall setMethod(HttpMethod m); HttpCall setCredentials(String login, @Nullable String password); HttpCall setAdminCredentials(); HttpCall setAuthenticationToken(String token); HttpCall setParam(String key, @Nullable String value); HttpCall setParams(String key1, @Nullable String value1, String... otherKeysAndNames); HttpCall setHeader(String key, String value); HttpCall setTimeoutMs(long timeoutMs); HttpResponse execute(); HttpResponse executeUnsafely(); void downloadToFile(File file); File downloadToDirectory(File dir);  }