Example usage for org.springframework.web.client RestTemplate getRequestFactory

List of usage examples for org.springframework.web.client RestTemplate getRequestFactory

Introduction

In this page you can find the example usage for org.springframework.web.client RestTemplate getRequestFactory.

Prototype

@Override
public ClientHttpRequestFactory getRequestFactory() 

Source Link

Document

Overridden to expose an InterceptingClientHttpRequestFactory if necessary.

Usage

From source file:com.feedeo.rest.client.AbstractOAuth2RestClient.java

@Override
protected RestOperations createRestOperations(ObjectMapper objectMapper,
        ClientHttpRequestFactory clientHttpRequestFactory) {
    RestTemplate restTemplate = (RestTemplate) super.createRestOperations(objectMapper,
            clientHttpRequestFactory);/*from  w  ww . j  av  a 2 s  .  com*/

    OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(new BaseOAuth2ProtectedResourceDetails(),
            new DefaultOAuth2ClientContext());
    oAuth2RestTemplate.setRequestFactory(restTemplate.getRequestFactory());
    oAuth2RestTemplate.setMessageConverters(restTemplate.getMessageConverters());
    oAuth2RestTemplate.setInterceptors(restTemplate.getInterceptors());

    return oAuth2RestTemplate;
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void buildShouldDetectRequestFactory() throws Exception {
    RestTemplate restTemplate = this.builder.build();
    assertThat(restTemplate.getRequestFactory()).isInstanceOf(HttpComponentsClientHttpRequestFactory.class);
}

From source file:org.esupportail.filex.web.WebController.java

@Autowired
public void setRestTemplate(RestTemplate restTemplate) {
    this.restTemplate = restTemplate;
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(50 * 1000)
            .setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
    HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
    HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) restTemplate
            .getRequestFactory();//  w  w  w. ja v  a  2 s  .  c o  m
    factory.setHttpClient(httpClient);
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void detectRequestFactoryWhenFalseShouldDisableDetection() throws Exception {
    RestTemplate restTemplate = this.builder.detectRequestFactory(false).build();
    assertThat(restTemplate.getRequestFactory()).isInstanceOf(SimpleClientHttpRequestFactory.class);
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void requestFactoryShouldApply() throws Exception {
    ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
    RestTemplate template = this.builder.requestFactory(requestFactory).build();
    assertThat(template.getRequestFactory()).isSameAs(requestFactory);
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void configureShouldApply() throws Exception {
    RestTemplate template = new RestTemplate();
    this.builder.configure(template);
    assertThat(template.getRequestFactory()).isInstanceOf(HttpComponentsClientHttpRequestFactory.class);
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void requestFactoryPackagePrivateClassShouldApply() throws Exception {
    RestTemplate template = this.builder.requestFactory(TestClientHttpRequestFactory.class).build();
    assertThat(template.getRequestFactory()).isInstanceOf(TestClientHttpRequestFactory.class);
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void requestFactoryClassShouldApply() throws Exception {
    RestTemplate template = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).build();
    assertThat(template.getRequestFactory()).isInstanceOf(SimpleClientHttpRequestFactory.class);
}

From source file:org.springframework.social.linkedin.api.impl.LinkedInTemplate.java

private void registerJsonFormatInterceptor() {
    RestTemplate restTemplate = getRestTemplate();
    if (interceptorsSupported) {
        List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
        interceptors.add(new JsonFormatInterceptor());
    } else {/*from   w  w w.  j a v  a 2s.co  m*/
        // for Spring 3.0.x where interceptors aren't supported
        ClientHttpRequestFactory originalRequestFactory = restTemplate.getRequestFactory();
        JsonFormatHeaderRequestFactory newRequestFactory = new JsonFormatHeaderRequestFactory(
                originalRequestFactory);
        restTemplate.setRequestFactory(newRequestFactory);
    }
}

From source file:org.springframework.boot.web.client.RestTemplateBuilderTests.java

@Test
public void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    RestTemplate template = this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory))
            .build();//from  ww  w  .  ja  va2 s.  com
    assertThat(template.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}