Search in sources :

Example 1 with SimpleClientHttpRequestFactory

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();
    }
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Example 2 with SimpleClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Proxy(org.springframework.boot.devtools.autoconfigure.RemoteDevToolsProperties.Proxy) InetSocketAddress(java.net.InetSocketAddress) InterceptingClientHttpRequestFactory(org.springframework.http.client.InterceptingClientHttpRequestFactory) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with SimpleClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.Test)

Example 4 with SimpleClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.Test)

Example 5 with SimpleClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Aggregations

SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)10 URI (java.net.URI)5 Test (org.junit.Test)5 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)4 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)4 BufferingClientHttpRequestFactory (org.springframework.http.client.BufferingClientHttpRequestFactory)3 RestTemplate (org.springframework.web.client.RestTemplate)3 HttpURLConnection (java.net.HttpURLConnection)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Proxy (org.springframework.boot.devtools.autoconfigure.RemoteDevToolsProperties.Proxy)1 Bean (org.springframework.context.annotation.Bean)1 ClientHttpRequestExecution (org.springframework.http.client.ClientHttpRequestExecution)1 ClientHttpRequestInterceptor (org.springframework.http.client.ClientHttpRequestInterceptor)1 InterceptingClientHttpRequestFactory (org.springframework.http.client.InterceptingClientHttpRequestFactory)1 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)1