Java 类org.springframework.http.client.BufferingClientHttpRequestFactory 实例源码

项目:bowman    文件:AbstractIT.java   
protected AbstractIT() {
    clientFactory = Configuration.builder()
            .setBaseUri(System.getProperty("baseUrl"))
            .setClientHttpRequestFactory(new BufferingClientHttpRequestFactory(
                    new HttpComponentsClientHttpRequestFactory()))
            .setRestTemplateConfigurer(new RestTemplateConfigurer() {

                @Override
                public void configure(RestTemplate restTemplate) {
                    restTemplate.getInterceptors().addAll(asList(
                        new LoggingClientHttpRequestInterceptor(),
                        createdEntityRecordingInterceptor
                    ));
                }
            })
            .build()
            .buildClientFactory();
}
项目:Robusto    文件:SpringRestClient.java   
/**
 * Extension point for plugging in different HTTP factories.
 * @return Default is a {@link BufferingClientHttpRequestFactory}
 */
protected ClientHttpRequestFactory createHttpFactory(
      int connectTimeout,
      int requestTimeout)
{
   SimpleClientHttpRequestFactory scrf = new SimpleClientHttpRequestFactory();
   scrf.setConnectTimeout(connectTimeout);
   scrf.setReadTimeout(requestTimeout);

   //
   // Wrap the default request factory in a BufferingClientHttpRequestFactory
   // which allows us to read response bodies multiple times. This is needed
   // because some interceptors will need to consume the body before the final
   // response gets to the caller.
   //

   return new BufferingClientHttpRequestFactory(scrf);
}
项目:Robusto    文件:SpringRestClient.java   
/**
 * Extension point for plugging in different HTTP factories.
 * @return Default is a {@link BufferingClientHttpRequestFactory}
 */
protected ClientHttpRequestFactory createHttpFactory(
      int connectTimeout,
      int requestTimeout)
{
   SimpleClientHttpRequestFactory scrf = new SimpleClientHttpRequestFactory();
   scrf.setConnectTimeout(connectTimeout);
   scrf.setReadTimeout(requestTimeout);

   //
   // Wrap the default request factory in a BufferingClientHttpRequestFactory
   // which allows us to read response bodies multiple times. This is needed
   // because some interceptors will need to consume the body before the final
   // response gets to the caller.
   //

   return new BufferingClientHttpRequestFactory(scrf);
}
项目:xm-uaa    文件:TemplateUtil.java   
public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
    RestTemplate restTemplate = new RestTemplate();

    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(interceptor);
    restTemplate.setInterceptors(ris);
    SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
    httpFactory.setOutputStreaming(false);
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}
项目:xm-uaa    文件:TemplateUtil.java   
public static void disableSSL(RestTemplate restTemplate) {
    try {
        SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
            .loadTrustMaterial(null, (X509Certificate[] chain, String authType) -> true)
            .build();
        CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
            .build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(requestFactory));
    } catch (Exception e) {
        log.error("Exception occurred while creating http factory, error={}", e.getMessage(), e);
    }
}
项目:Settings    文件:ApiClient.java   
/**
 * Build the RestTemplate used to make HTTP requests.
 * @return RestTemplate
 */
protected RestTemplate buildRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    // This allows us to read the response more than once - Necessary for debugging.
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
    return restTemplate;
}
项目:xm-ms-entity    文件:TemplateUtil.java   
public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
    RestTemplate restTemplate = new RestTemplate();

    List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
    ris.add(interceptor);
    restTemplate.setInterceptors(ris);
    SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
    httpFactory.setOutputStreaming(false);
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
    restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    return restTemplate;
}
项目:xm-ms-entity    文件:TemplateUtil.java   
public static void disableSSL(RestTemplate restTemplate) {
    try {
        SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
            .loadTrustMaterial(null, (X509Certificate[] chain, String authType) -> true)
            .build();
        CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
            .build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(requestFactory));
    } catch (Exception e) {
        log.error("Exception occurred while creating http factory, error={}", e.getMessage(), e);
    }
}
项目:spring-rest-basis    文件:LoggingRequestFactoryFactory.java   
private static LoggingRequestFactory interceptorToRequestFactory(LoggingRequestInterceptor lri) {
    List<ClientHttpRequestInterceptor> lInterceptors = new ArrayList<>();
    lInterceptors.add(lri);
    SimpleClientHttpRequestFactory chrf = new SimpleClientHttpRequestFactory();
    chrf.setOutputStreaming(false);
    return new LoggingRequestFactory(
            new BufferingClientHttpRequestFactory(chrf),
            lInterceptors
    );
}
项目:spring-rest-basis    文件:Zg2proRestTemplate.java   
@Override
protected void interceptorsIntegration(List<ClientHttpRequestInterceptor> lInterceptors, Object sslConfiguration) {
    this.setInterceptors(lInterceptors);
    SimpleClientHttpRequestFactory chrf = new SimpleClientHttpRequestFactory();
    chrf.setOutputStreaming(false);
    this.setRequestFactory(
            new InterceptingClientHttpRequestFactory(
                    new BufferingClientHttpRequestFactory(chrf),
                    lInterceptors
            )
    );
}
项目:spring-rest-basis    文件:LogsTest.java   
/**
 * hard to check the logs provided by the interceptor when there's no error
 * however this unit test garantees the interceptor does not alter the reply
 * from the rest service.
 */
@Test
public void testInterceptor() {
    List<ClientHttpRequestInterceptor> lInterceptors = new ArrayList<>();
    //spring boot default log level is info
    lInterceptors.add(new LoggingRequestInterceptor(StandardCharsets.ISO_8859_1, 100, Level.ERROR));
    SimpleClientHttpRequestFactory chrf = new SimpleClientHttpRequestFactory();
    chrf.setOutputStreaming(false);
    rt.getRestTemplate().setRequestFactory(new InterceptingClientHttpRequestFactory(
            new BufferingClientHttpRequestFactory(chrf),
            lInterceptors
    ));
    ResponseEntity<String> resp = rt.getForEntity(MockedControllers.TEST_URL_GET, String.class);
    assertThat(resp.getBody()).isEqualTo(MockedControllers.TEST_RETURN_VALUE);
}
项目:steve-plugsurfing    文件:PlugSurfingConfiguration.java   
@Bean
public RestTemplate normalTemplate() {
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(new ClientApiKeyHeaderInterceptor());
    interceptors.add(new ClientLogInterceptor());

    // Out-going serialization
    RestTemplate restTemplate = new RestTemplate(Collections.singletonList(getMessageConverter()));
    restTemplate.setInterceptors(interceptors);
    restTemplate.setRequestFactory(
            new BufferingClientHttpRequestFactory(
                    new HttpComponentsClientHttpRequestFactory()));

    return restTemplate;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestTemplateBuilderTests.java   
@Test
public void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory))
            .setConnectTimeout(1234).build();
    assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
            .isEqualTo(1234);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RestTemplateBuilderTests.java   
@Test
public void readTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory))
            .setReadTimeout(1234).build();
    assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
            .isEqualTo(1234);
}
项目:spring-social-slideshare    文件:AbstractSlideshareTemplateTest.java   
@Before
public void setUp() {
    SlideShareTemplate slideShareTemplate = new SlideShareTemplate("key", "secret");
    RestTemplate restTemplate = slideShareTemplate.getRestTemplate();
    mockServer = MockRestServiceServer.createServer(restTemplate);

    // creating mockServer replaces RequestFactory in restTemplate to RequestMatcherClientHttpRequestFactory.
    // in order to support multiple reads in test, re-wrap the mock requestFactory and set to restTemplate.
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
    slideshowOperations = slideShareTemplate.slideshowOperations();
}
项目:raml-tester    文件:RamlRestTemplate.java   
private RamlRestTemplate(RamlChecker ramlChecker, boolean notSending, ReportStore reportStore, ClientHttpRequestFactory requestFactory) {
    this.ramlChecker = ramlChecker;
    this.notSending = notSending;
    this.reportStore = reportStore;
    this.originalRequestFactory = requestFactory;
    final RamlRequestInterceptor interceptor = new RamlRequestInterceptor(ramlChecker, notSending, reportStore);
    setRequestFactory(new InterceptingClientHttpRequestFactory(
            new BufferingClientHttpRequestFactory(requestFactory), Collections.<ClientHttpRequestInterceptor>singletonList(interceptor)));
}
项目:spring-rest-template-logger    文件:LoggingCustomizer.java   
@Override
public void customize(RestTemplate restTemplate)
{
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
    restTemplate.getInterceptors().add(new LoggingInterceptor(log));
}