本文整理汇总了Java中org.springframework.http.client.BufferingClientHttpRequestFactory类的典型用法代码示例。如果您正苦于以下问题:Java BufferingClientHttpRequestFactory类的具体用法?Java BufferingClientHttpRequestFactory怎么用?Java BufferingClientHttpRequestFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BufferingClientHttpRequestFactory类属于org.springframework.http.client包,在下文中一共展示了BufferingClientHttpRequestFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTemplate
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
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;
}
示例2: AbstractIT
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
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();
}
示例3: createHttpFactory
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
/**
* 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);
}
示例4: disableSSL
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
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);
}
}
示例5: buildRestTemplate
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
/**
* 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;
}
示例6: interceptorToRequestFactory
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
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
);
}
示例7: interceptorsIntegration
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
@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
)
);
}
示例8: testInterceptor
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
/**
* 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);
}
示例9: normalTemplate
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
@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;
}
示例10: connectTimeoutCanBeConfiguredOnAWrappedRequestFactory
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory))
.setConnectTimeout(1234).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
.isEqualTo(1234);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:RestTemplateBuilderTests.java
示例11: readTimeoutCanBeConfiguredOnAWrappedRequestFactory
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void readTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(new BufferingClientHttpRequestFactory(requestFactory))
.setReadTimeout(1234).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
.isEqualTo(1234);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:RestTemplateBuilderTests.java
示例12: setUp
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
@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();
}
示例13: RamlRestTemplate
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
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)));
}
示例14: customize
import org.springframework.http.client.BufferingClientHttpRequestFactory; //导入依赖的package包/类
@Override
public void customize(RestTemplate restTemplate)
{
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
restTemplate.getInterceptors().add(new LoggingInterceptor(log));
}