Search in sources :

Example 21 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnNetty4RequestFactory.

@Test
public void connectTimeoutCanBeConfiguredOnNetty4RequestFactory() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(Netty4ClientHttpRequestFactory.class).setConnectTimeout(1234).build().getRequestFactory();
    assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")).isEqualTo(1234);
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) Test(org.junit.Test)

Example 22 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method customizersShouldBeAppliedLast.

@Test
public void customizersShouldBeAppliedLast() throws Exception {
    RestTemplate template = spy(new RestTemplate());
    this.builder.additionalCustomizers(new RestTemplateCustomizer() {

        @Override
        public void customize(RestTemplate restTemplate) {
            verify(restTemplate).setRequestFactory((ClientHttpRequestFactory) any());
        }
    });
    this.builder.configure(template);
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 23 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class TestRestTemplateTests method verifyRelativeUriHandling.

private void verifyRelativeUriHandling(TestRestTemplateCallback callback) throws IOException {
    ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
    MockClientHttpRequest request = new MockClientHttpRequest();
    request.setResponse(new MockClientHttpResponse(new byte[0], HttpStatus.OK));
    URI absoluteUri = URI.create("http://localhost:8080/a/b/c.txt?param=%7Bsomething%7D");
    given(requestFactory.createRequest(eq(absoluteUri), (HttpMethod) any())).willReturn(request);
    RestTemplate delegate = new RestTemplate();
    TestRestTemplate template = new TestRestTemplate(delegate);
    delegate.setRequestFactory(requestFactory);
    LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(new MockEnvironment());
    template.setUriTemplateHandler(uriTemplateHandler);
    callback.doWithTestRestTemplate(template, URI.create("/a/b/c.txt?param=%7Bsomething%7D"));
    verify(requestFactory).createRequest(eq(absoluteUri), (HttpMethod) any());
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) InterceptingClientHttpRequestFactory(org.springframework.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) CustomHttpComponentsClientHttpRequestFactory(org.springframework.boot.test.web.client.TestRestTemplate.CustomHttpComponentsClientHttpRequestFactory) MockEnvironment(org.springframework.mock.env.MockEnvironment) RestTemplate(org.springframework.web.client.RestTemplate) MockClientHttpRequest(org.springframework.mock.http.client.MockClientHttpRequest) URI(java.net.URI) MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse)

Aggregations

ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)23 Test (org.junit.Test)17 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)12 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)12 URI (java.net.URI)11 BufferingClientHttpRequestFactory (org.springframework.http.client.BufferingClientHttpRequestFactory)10 Netty4ClientHttpRequestFactory (org.springframework.http.client.Netty4ClientHttpRequestFactory)10 OkHttp3ClientHttpRequestFactory (org.springframework.http.client.OkHttp3ClientHttpRequestFactory)10 HttpMethod (org.springframework.http.HttpMethod)9 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)9 IOException (java.io.IOException)7 RestTemplate (org.springframework.web.client.RestTemplate)6 HttpHeaders (org.springframework.http.HttpHeaders)4 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)4 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 RequestConfig (org.apache.http.client.config.RequestConfig)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2