use of org.springframework.http.client.SimpleClientHttpRequestFactory in project spring-boot by spring-projects.
the class ServletWebServerMvcIntegrationTests method doTest.
private void doTest(AnnotationConfigServletWebServerApplicationContext context, String resourcePath) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI("http://localhost:" + context.getWebServer().getPort() + resourcePath), HttpMethod.GET);
ClientHttpResponse response = request.execute();
try {
String actual = StreamUtils.copyToString(response.getBody(), Charset.forName("UTF-8"));
assertThat(actual).isEqualTo("Hello World");
} finally {
response.close();
}
}
use of org.springframework.http.client.SimpleClientHttpRequestFactory in project spring-boot by spring-projects.
the class RemoteClientConfiguration method clientHttpRequestFactory.
@Bean
public ClientHttpRequestFactory clientHttpRequestFactory() {
List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(getSecurityInterceptor());
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = this.properties.getRemote().getProxy();
if (proxy.getHost() != null && proxy.getPort() != null) {
requestFactory.setProxy(new java.net.Proxy(Type.HTTP, new InetSocketAddress(proxy.getHost(), proxy.getPort())));
}
return new InterceptingClientHttpRequestFactory(requestFactory, interceptors);
}
use of org.springframework.http.client.SimpleClientHttpRequestFactory in project spring-boot by spring-projects.
the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnAWrappedRequestFactory.
@Test
public void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory)).setConnectTimeout(1234).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")).isEqualTo(1234);
}
use of org.springframework.http.client.SimpleClientHttpRequestFactory in project spring-boot by spring-projects.
the class RestTemplateBuilderTests method unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate.
@Test
public void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
RestTemplate template = this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory)).build();
assertThat(template.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}
use of org.springframework.http.client.SimpleClientHttpRequestFactory in project spring-boot by spring-projects.
the class EndpointWebMvcAutoConfigurationTests method hasHeader.
public boolean hasHeader(String url, int port, String header) throws Exception {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI("http://localhost:" + port + url), HttpMethod.GET);
ClientHttpResponse response = request.execute();
return response.getHeaders().containsKey(header);
}
Aggregations