本文整理汇总了Java中org.springframework.http.client.ClientHttpRequestFactory类的典型用法代码示例。如果您正苦于以下问题:Java ClientHttpRequestFactory类的具体用法?Java ClientHttpRequestFactory怎么用?Java ClientHttpRequestFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientHttpRequestFactory类属于org.springframework.http.client包,在下文中一共展示了ClientHttpRequestFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestFactory
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
@Bean
public ClientHttpRequestFactory requestFactory() {
// Disable auto redirect on 3xx HTTP responses
CloseableHttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling().build();
HttpComponentsClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient);
// read timeout
if(!StringUtils.isEmpty(readTimeout)) {
rf.setReadTimeout(Integer.valueOf(readTimeout) * 1000);
}
// connect timeout
if(!StringUtils.isEmpty(connectTimeout)) {
rf.setConnectTimeout(Integer.valueOf(connectTimeout) * 1000);
}
return rf;
}
示例2: createCommonsHttpRestTemplate
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
public static RestOperations createCommonsHttpRestTemplate(int maxConnPerRoute, int maxConnTotal,
int connectTimeout, int soTimeout, int retryTimes, RetryPolicyFactory retryPolicyFactory) {
HttpClient httpClient = HttpClientBuilder.create()
.setMaxConnPerRoute(maxConnPerRoute)
.setMaxConnTotal(maxConnTotal)
.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(soTimeout).build())
.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(connectTimeout).build())
.build();
ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
RestTemplate restTemplate = new RestTemplate(factory);
//set jackson mapper
for (HttpMessageConverter<?> hmc : restTemplate.getMessageConverters()) {
if (hmc instanceof MappingJackson2HttpMessageConverter) {
ObjectMapper objectMapper = createObjectMapper();
MappingJackson2HttpMessageConverter mj2hmc = (MappingJackson2HttpMessageConverter) hmc;
mj2hmc.setObjectMapper(objectMapper);
}
}
return (RestOperations) Proxy.newProxyInstance(RestOperations.class.getClassLoader(),
new Class[]{RestOperations.class},
new RetryableRestOperationsHandler(restTemplate, retryTimes, retryPolicyFactory));
}
示例3: restTemplate
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
public RestTemplate restTemplate(ClientHttpRequestFactory requestFactory, List<MediaType> types) {
RestTemplate rt = new RestTemplate(requestFactory);
// Override default error handler to consider HTTP 3xx 4xx and 5xx as errors
rt.setErrorHandler(restErrorHandler);
// Default HTTP 'Accept' header value will be application/json
rt.getInterceptors().add(new AcceptRequestInterceptor(types));
return rt;
}
示例4: usingHttpComponents
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options)
throws GeneralSecurityException, IOException {
HttpClientBuilder httpClientBuilder = HttpClients.custom()
.setSSLContext(SSLContext.getDefault())
.useSystemProperties();
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setAuthenticationEnabled(true);
if (options.getConnectionTimeout() != null) {
requestConfigBuilder.setConnectTimeout(options.getConnectionTimeout());
}
if (options.getReadTimeout() != null) {
requestConfigBuilder.setSocketTimeout(options.getReadTimeout());
}
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
示例5: usingOkHttp3
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
static ClientHttpRequestFactory usingOkHttp3(ClientOptions options)
throws IOException, GeneralSecurityException {
SSLSocketFactory socketFactory = SSLContext.getDefault().getSocketFactory();
X509TrustManager trustManager = getTrustManager();
Builder builder = new Builder().sslSocketFactory(socketFactory, trustManager);
if (options.getConnectionTimeout() != null) {
builder.connectTimeout(options.getConnectionTimeout(), TimeUnit.MILLISECONDS);
}
if (options.getReadTimeout() != null) {
builder.readTimeout(options.getReadTimeout(), TimeUnit.MILLISECONDS);
}
return new OkHttp3ClientHttpRequestFactory(builder.build());
}
示例6: usingNetty
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
static ClientHttpRequestFactory usingNetty(ClientOptions options)
throws IOException, GeneralSecurityException {
SslContext sslContext = new JdkSslContext(SSLContext.getDefault(), true, ClientAuth.REQUIRE);
final Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();
requestFactory.setSslContext(sslContext);
if (options.getConnectionTimeout() != null) {
requestFactory.setConnectTimeout(options.getConnectionTimeout());
}
if (options.getReadTimeout() != null) {
requestFactory.setReadTimeout(options.getReadTimeout());
}
return requestFactory;
}
示例7: MMLWebFeatureServiceRequestTemplate
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
public MMLWebFeatureServiceRequestTemplate(MMLProperties mmlProperties, ClientHttpRequestFactory clientHttpRequestFactory) {
this.mmlProperties = mmlProperties;
this.restTemplate = new RestTemplate(clientHttpRequestFactory);
final List<MediaType> xmlMediaTypes = Lists.newArrayList(
MediaType.APPLICATION_XML, MediaType.TEXT_XML,
new MediaType("application", "*+xml"),
new MediaType("application", "vnd.ogc.se_xml"));
final SourceHttpMessageConverter<Source> xmlConverter = new SourceHttpMessageConverter<>();
xmlConverter.setSupportedMediaTypes(xmlMediaTypes);
final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(xmlConverter);
final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new BasicAuthenticationClientInterceptor(
mmlProperties.getWfsUsername(), mmlProperties.getWfsPassword()));
this.restTemplate.setMessageConverters(messageConverters);
this.restTemplate.setInterceptors(interceptors);
}
示例8: createHttpFactory
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的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);
}
示例9: usingOkHttp3
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
static ClientHttpRequestFactory usingOkHttp3(ClientOptions options,
SslConfiguration sslConfiguration) throws GeneralSecurityException,
IOException {
Builder builder = new Builder();
if (hasSslConfiguration(sslConfiguration)) {
builder.sslSocketFactory(getSSLContext(sslConfiguration)
.getSocketFactory());
}
builder.connectTimeout(options.getConnectionTimeout().toMillis(),
TimeUnit.MILLISECONDS).readTimeout(
options.getReadTimeout().toMillis(), TimeUnit.MILLISECONDS);
return new OkHttp3ClientHttpRequestFactory(builder.build());
}
示例10: VaultTemplate
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
/**
* Create a new {@link VaultTemplate} with a {@link VaultEndpointProvider},
* {@link ClientHttpRequestFactory} and {@link SessionManager}.
*
* @param endpointProvider must not be {@literal null}.
* @param clientHttpRequestFactory must not be {@literal null}.
* @param sessionManager must not be {@literal null}.
* @since 1.1
*/
public VaultTemplate(VaultEndpointProvider endpointProvider,
ClientHttpRequestFactory clientHttpRequestFactory,
SessionManager sessionManager) {
Assert.notNull(endpointProvider, "VaultEndpointProvider must not be null");
Assert.notNull(clientHttpRequestFactory,
"ClientHttpRequestFactory must not be null");
Assert.notNull(sessionManager, "SessionManager must not be null");
this.sessionManager = sessionManager;
this.dedicatedSessionManager = false;
this.sessionTemplate = createSessionTemplate(endpointProvider,
clientHttpRequestFactory);
this.plainTemplate = VaultClients.createRestTemplate(endpointProvider,
clientHttpRequestFactory);
}
示例11: clientHttpRequestFactory
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
@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);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:RemoteClientConfiguration.java
示例12: VaultRule
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
/**
* Create a new {@link VaultRule} with the given {@link SslConfiguration} and
* {@link VaultEndpoint}.
*
* @param sslConfiguration must not be {@literal null}.
* @param vaultEndpoint must not be {@literal null}.
*/
public VaultRule(SslConfiguration sslConfiguration, VaultEndpoint vaultEndpoint) {
Assert.notNull(sslConfiguration, "SslConfiguration must not be null");
Assert.notNull(vaultEndpoint, "VaultEndpoint must not be null");
ClientHttpRequestFactory requestFactory = TestRestTemplateFactory.create(
sslConfiguration).getRequestFactory();
VaultTemplate vaultTemplate = new VaultTemplate(vaultEndpoint, requestFactory,
new PreparingSessionManager());
this.token = Settings.token();
this.prepareVault = new PrepareVault(vaultTemplate);
this.vaultEndpoint = vaultEndpoint;
}
示例13: createInstantiatesObjectMapperWithInlineAssociationDeserializerAwareHandlerInstantiator
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void createInstantiatesObjectMapperWithInlineAssociationDeserializerAwareHandlerInstantiator() {
ObjectMapper mapper = new ObjectMapper();
RestTemplate restTemplate = new RestTemplate();
when(mapperFactory.create(any(HandlerInstantiator.class))).thenReturn(mapper);
when(restTemplateFactory.create(any(ClientHttpRequestFactory.class), any(ObjectMapper.class)))
.thenReturn(restTemplate);
factory.create();
ArgumentCaptor<HandlerInstantiator> handlerInstantiator = ArgumentCaptor.forClass(HandlerInstantiator.class);
verify(mapperFactory).create(handlerInstantiator.capture());
assertThat(handlerInstantiator.getValue().deserializerInstance(null, null, InlineAssociationDeserializer.class),
is(anInlineAssociationDeserializerMatching(aRestOperationsMatching(restTemplate, mapper),
proxyFactory)));
}
示例14: createInvokesConfigurerOnRestTemplateIfPresent
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
@Test
public void createInvokesConfigurerOnRestTemplateIfPresent() {
RestTemplateConfigurer restTemplateConfigurer = mock(RestTemplateConfigurer.class);
Configuration configuration = Configuration.builder()
.setRestTemplateConfigurer(restTemplateConfigurer)
.build();
RestTemplate restTemplate = new RestTemplate();
when(restTemplateFactory.create(any(ClientHttpRequestFactory.class), any(ObjectMapper.class)))
.thenReturn(restTemplate);
new RestOperationsFactory(configuration, proxyFactory, mapperFactory, restTemplateFactory)
.create();
verify(restTemplateConfigurer).configure(restTemplate);
}
示例15: traceAsyncClientHttpRequestFactory
import org.springframework.http.client.ClientHttpRequestFactory; //导入依赖的package包/类
@Bean
@Primary
@ConditionalOnProperty(value = "spring.sleuth.web.async.client.factory.enabled", matchIfMissing = true)
public TraceAsyncClientHttpRequestFactoryWrapper traceAsyncClientHttpRequestFactory() {
ClientHttpRequestFactory clientFactory = this.clientHttpRequestFactory;
AsyncClientHttpRequestFactory asyncClientFactory = this.asyncClientHttpRequestFactory;
if (clientFactory == null) {
clientFactory = defaultClientHttpRequestFactory(this.tracer);
}
if (asyncClientFactory == null) {
asyncClientFactory = clientFactory instanceof AsyncClientHttpRequestFactory ?
(AsyncClientHttpRequestFactory) clientFactory : defaultClientHttpRequestFactory(this.tracer);
}
return new TraceAsyncClientHttpRequestFactoryWrapper(this.tracer, this.spanInjector,
asyncClientFactory, clientFactory, this.httpTraceKeysInjector);
}