use of okhttp3.Request in project spring-framework by spring-projects.
the class AbstractMockWebServerTestCase method jsonPostRequest.
private MockResponse jsonPostRequest(RecordedRequest request, String location, String contentType) {
if (request.getBodySize() > 0) {
assertTrue("Invalid request content-length", Integer.parseInt(request.getHeader("Content-Length")) > 0);
assertNotNull("No content-type", request.getHeader("Content-Type"));
}
return new MockResponse().setHeader("Location", baseUrl + location).setHeader("Content-Type", contentType).setHeader("Content-Length", request.getBody().size()).setBody(request.getBody()).setResponseCode(201);
}
use of okhttp3.Request in project spring-framework by spring-projects.
the class WebClientIntegrationTests method buildFilter.
@Test
public void buildFilter() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "text/plain").setBody("Hello Spring!"));
WebClient filteredClient = this.webClient.filter((request, next) -> {
ClientRequest filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
return next.exchange(filteredRequest);
});
Mono<String> result = filteredClient.get().uri("/greeting?name=Spring").exchange().then(response -> response.bodyToMono(String.class));
StepVerifier.create(result).expectNext("Hello Spring!").expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("bar", recordedRequest.getHeader("foo"));
}
use of okhttp3.Request in project spring-framework by spring-projects.
the class WebClientIntegrationTests method filter.
@Test
public void filter() throws Exception {
this.server.enqueue(new MockResponse().setHeader("Content-Type", "text/plain").setBody("Hello Spring!"));
WebClient filteredClient = this.webClient.filter((request, next) -> {
ClientRequest filteredRequest = ClientRequest.from(request).header("foo", "bar").build();
return next.exchange(filteredRequest);
});
Mono<String> result = filteredClient.get().uri("/greeting?name=Spring").exchange().then(response -> response.bodyToMono(String.class));
StepVerifier.create(result).expectNext("Hello Spring!").expectComplete().verify(Duration.ofSeconds(3));
RecordedRequest recordedRequest = server.takeRequest();
Assert.assertEquals(1, server.getRequestCount());
Assert.assertEquals("bar", recordedRequest.getHeader("foo"));
}
use of okhttp3.Request in project realm-java by realm.
the class OkHttpAuthenticationServer method logout.
private LogoutResponse logout(URL logoutUrl, String requestBody) throws Exception {
Request request = new Request.Builder().url(logoutUrl).addHeader("Content-Type", "application/json").addHeader("Accept", "application/json").post(RequestBody.create(JSON, requestBody)).build();
Call call = client.newCall(request);
Response response = call.execute();
return LogoutResponse.from(response);
}
use of okhttp3.Request in project muzei by romannurik.
the class FeaturedArtSource method fetchJsonObject.
private JSONObject fetchJsonObject(final String url) throws IOException, JSONException {
OkHttpClient client = new OkHttpClient.Builder().build();
Request request = new Request.Builder().url(url).build();
String json = client.newCall(request).execute().body().string();
JSONTokener tokener = new JSONTokener(json);
Object val = tokener.nextValue();
if (!(val instanceof JSONObject)) {
throw new JSONException("Expected JSON object.");
}
return (JSONObject) val;
}
Aggregations