use of cn.taketoday.http.client.SimpleClientHttpRequestFactory in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method bufferRequestBodyCanBeConfiguredOnAWrappedRequestFactory.
@Test
void bufferRequestBodyCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setBufferRequestBody(false).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", false);
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setBufferRequestBody(true).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
}
use of cn.taketoday.http.client.SimpleClientHttpRequestFactory in project today-infrastructure by TAKETODAY.
the class RestTemplateTests method keepGivenAcceptHeaderOnPut.
@Test
// gh-23740
void keepGivenAcceptHeaderOnPut() throws Exception {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
server.start();
HttpHeaders headers = HttpHeaders.create();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<>(headers);
template.setRequestFactory(new SimpleClientHttpRequestFactory());
template.exchange(server.url("/internal/server/error").uri(), PUT, entity, Void.class);
RecordedRequest request = server.takeRequest();
final List<List<String>> accepts = request.getHeaders().toMultimap().entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase("accept")).map(Entry::getValue).collect(Collectors.toList());
assertThat(accepts).hasSize(1);
assertThat(accepts.get(0)).hasSize(1);
assertThat(accepts.get(0).get(0)).isEqualTo("application/json");
}
}
use of cn.taketoday.http.client.SimpleClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateTests method keepGivenAcceptHeaderOnPut.
@Test
// gh-23740
void keepGivenAcceptHeaderOnPut() throws Exception {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
server.start();
HttpHeaders headers = HttpHeaders.create();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<>(headers);
template.setRequestFactory(new SimpleClientHttpRequestFactory());
template.exchange(server.url("/internal/server/error").uri(), PUT, entity, Void.class);
RecordedRequest request = server.takeRequest();
final List<List<String>> accepts = request.getHeaders().toMultimap().entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase("accept")).map(Entry::getValue).collect(Collectors.toList());
assertThat(accepts).hasSize(1);
assertThat(accepts.get(0)).hasSize(1);
assertThat(accepts.get(0).get(0)).isEqualTo("application/json");
}
}
use of cn.taketoday.http.client.SimpleClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateTests method headerAcceptAllOnDelete.
@Test
// gh-23740
void headerAcceptAllOnDelete() throws Exception {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setResponseCode(500).setBody("internal server error"));
server.start();
template.setRequestFactory(new SimpleClientHttpRequestFactory());
template.delete(server.url("/internal/server/error").uri());
assertThat(server.takeRequest().getHeader("Accept")).isEqualTo("*/*");
}
}
use of cn.taketoday.http.client.SimpleClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnAWrappedRequestFactory.
@Test
void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setConnectTimeout(Duration.ofMillis(1234)).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 1234);
}
Aggregations