当前位置: 首页>>代码示例>>Java>>正文


Java ClientHttpRequestFactory类代码示例

本文整理汇总了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;
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:21,代码来源:DefaultRestTemplateConfig.java

示例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));
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:24,代码来源:RestTemplateFactory.java

示例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;
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:12,代码来源:DefaultRestTemplateConfig.java

示例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());
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:22,代码来源:ClientHttpRequestFactoryFactory.java

示例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());
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:18,代码来源:ClientHttpRequestFactoryFactory.java

示例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;
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:18,代码来源:ClientHttpRequestFactoryFactory.java

示例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);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:23,代码来源:MMLWebFeatureServiceRequestTemplate.java

示例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);
}
 
开发者ID:HomeAdvisor,项目名称:Robusto,代码行数:22,代码来源:SpringRestClient.java

示例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());
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:18,代码来源:ClientHttpRequestFactoryFactory.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:27,代码来源:VaultTemplate.java

示例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;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-vault,代码行数:23,代码来源:VaultRule.java

示例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)));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:19,代码来源:RestOperationsFactoryTest.java

示例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);
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:17,代码来源:RestOperationsFactoryTest.java

示例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);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:17,代码来源:TraceWebAsyncClientAutoConfiguration.java


注:本文中的org.springframework.http.client.ClientHttpRequestFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。