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

项目:Persephone    文件:DefaultRestTemplateConfig.java   
@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;
}
项目:Persephone    文件:DefaultRestTemplateConfig.java   
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;
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactory.java   
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());
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactory.java   
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());
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactory.java   
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;
}
项目:oma-riista-web    文件:MMLWebFeatureServiceRequestTemplate.java   
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);
}
项目: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);
}
项目:x-pipe    文件:RestTemplateFactory.java   
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));
}
项目:spring-vault    文件:ClientHttpRequestFactoryFactory.java   
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());
}
项目:spring-vault    文件:VaultTemplate.java   
/**
 * 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);
}
项目:spring-cloud-vault    文件:VaultRule.java   
/**
 * 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;
}
项目:bowman    文件:RestOperationsFactoryTest.java   
@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)));
}
项目:bowman    文件:RestOperationsFactoryTest.java   
@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);
}
项目:Zipkin    文件:TraceWebAsyncClientAutoConfiguration.java   
@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);
}
项目:spring-cloud-skipper    文件:HttpClientConfigurer.java   
public ClientHttpRequestFactory buildClientHttpRequestFactory() {
    if (useBasicAuth && targetHost != null) {
        return new PreemptiveBasicAuthHttpComponentsClientHttpRequestFactory(buildHttpClient(), targetHost);
    }
    else {
        return new HttpComponentsClientHttpRequestFactory(buildHttpClient());
    }
}
项目:incubator-servicecomb-java-chassis    文件:TestRestTemplateWrapper.java   
@Test
public void doNotSetRequestFactoryWithUnderlying() {
  ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);

  wrapper.setRequestFactory(requestFactory);

  assertThat(wrapper.getRequestFactory(), is(requestFactory));
  assertThat(wrapper.defaultRestTemplate.getRequestFactory(), is(requestFactory));

  verify(underlying, never()).setRequestFactory(requestFactory);
}
项目:cas-5.1.0    文件:CasRestAuthenticationConfiguration.java   
@Bean
@RefreshScope
public RestTemplate restAuthenticationTemplate() {
    try {
        final URI casHost = new URI(casProperties.getServer().getName());
        final HttpHost host = new HttpHost(casHost.getHost(), casHost.getPort(), casHost.getScheme());
        final ClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactoryBasicAuth(host);
        return new RestTemplate(factory);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
项目:spring-cloud-vault-connector    文件:VaultServiceConnectorConfig.java   
protected VaultServiceConnectorConfig(
        ClientHttpRequestFactory clientHttpRequestFactory) {

    Assert.notNull(clientHttpRequestFactory,
            "ClientHttpRequestFactory must not be null");

    this.clientHttpRequestFactory = clientHttpRequestFactory;
}
项目:spring-cloud-vault-connector    文件:VaultServiceConnectorConfig.java   
/**
 * Create {@link VaultServiceConnectorConfig} given {@link ClientHttpRequestFactory}.
 *
 * @param clientHttpRequestFactory must not be {@literal null}.
 * @return {@link VaultServiceConnectorConfig} for {@link ClientHttpRequestFactory}.
 */
public static VaultServiceConnectorConfig create(
        ClientHttpRequestFactory clientHttpRequestFactory) {

    Assert.notNull(clientHttpRequestFactory,
            "ClientHttpRequestFactory must not be null");

    return new VaultServiceConnectorConfig(clientHttpRequestFactory);
}
项目:spring-cloud-vault-connector    文件:VaultServiceConnectorConfig.java   
/**
 * Build a new {@link VaultServiceConnectorConfig} instance. The {@code build}
 * method creates {@link ClientHttpRequestFactory} which might be lifecycle-aware.
 * You need to initialize/dispose the resource according to the lifecycle.
 *
 * @return the {@link VaultServiceConnectorConfig}.
 */
public VaultServiceConnectorConfig build() {

    ClientHttpRequestFactory clientHttpRequestFactory = ClientHttpRequestFactoryFactory
            .create(clientOptions, sslConfiguration);

    return VaultServiceConnectorConfig.create(clientHttpRequestFactory);
}
项目:cf-java-client-sap    文件:RestUtil.java   
public ClientHttpRequestFactory createRequestFactory(HttpProxyConfiguration httpProxyConfiguration, boolean
        trustSelfSignedCerts) {
    HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties();

    if (trustSelfSignedCerts) {
        httpClientBuilder.setSslcontext(buildSslContext());
        httpClientBuilder.setHostnameVerifier(BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    }

    if (httpProxyConfiguration != null) {
        HttpHost proxy = new HttpHost(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort());
        httpClientBuilder.setProxy(proxy);

        if (httpProxyConfiguration.isAuthRequired()) {
            BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(
                    new AuthScope(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort()),
                    new UsernamePasswordCredentials(httpProxyConfiguration.getUsername(), httpProxyConfiguration
                            .getPassword()));
            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }

        HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
        httpClientBuilder.setRoutePlanner(routePlanner);
    }

    HttpClient httpClient = httpClientBuilder.build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);

    return requestFactory;
}
项目:cf-java-client-sap    文件:CloudFoundryClientTest.java   
private void assertNetworkCallFails(RestTemplate restTemplate, ClientHttpRequestFactory requestFactory) {
    restTemplate.setRequestFactory(requestFactory);
    try {
        HttpStatus status = restTemplate.execute(CCNG_API_URL + "/info", HttpMethod.GET, null, new ResponseExtractor<HttpStatus>() {
            public HttpStatus extractData(ClientHttpResponse response) throws IOException {
                return response.getStatusCode();
            }
        });
        Assert.fail("Expected byteman rules to detect direct socket connections, status is:" + status);
    } catch (Exception e) {
        // good, byteman rejected it as expected
        // e.printStackTrace();
    }
    assertEquals("Not expecting Jetty to receive requests since we asked direct connections", 0, nbInJvmProxyRcvReqs.get());
}
项目:teamcity-hashicorp-vault-plugin    文件:VaultParametersResolverTest.java   
@Before
public void setUp() throws Exception {
    ClientHttpRequestFactory factory = new AbstractClientHttpRequestFactoryWrapper(createClientHttpRequestFactory()) {
        @Override
        protected ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod, ClientHttpRequestFactory requestFactory) throws IOException {
            myRequestedURIs.add(uri.getPath());
            return requestFactory.createRequest(uri, httpMethod);
        }
    };
    template = new VaultTemplate(vault.getEndpoint(), factory, vault.getSimpleSessionManager());
    resolver = new VaultParametersResolver();
    feature = new VaultFeatureSettings(vault.getUrl(), "", "");
}
项目:teamcity-hashicorp-vault-plugin    文件:VaultConnectorTest.java   
@Test
public void testVaultIsUpAndRunning() throws Exception {
    final ClientHttpRequestFactory factory = createClientHttpRequestFactory();

    final VaultTemplate template = new VaultTemplate(getVault().getEndpoint(), factory, () -> VaultToken.of(getVault().getToken()));

    final VaultHealth health = template.opsForSys().health();
    then(health.isInitialized()).isTrue();
    then(health.isSealed()).isFalse();
    then(health.isStandby()).isFalse();
    then(health.getVersion()).isEqualTo("0.7.3");
}
项目:teamcity-hashicorp-vault-plugin    文件:VaultConnectorTest.java   
private void doTestWrapperTokenCreated(String authMountPath) {
    final ClientHttpRequestFactory factory = createClientHttpRequestFactory();
    final VaultTemplate template = new VaultTemplate(getVault().getEndpoint(), factory, () -> VaultToken.of(getVault().getToken()));

    // Ensure approle auth enabled
    template.opsForSys().authMount(authMountPath, VaultMount.create("approle"));
    then(template.opsForSys().getAuthMounts()).containsKey(authMountPath + "/");
    template.write("auth/" + authMountPath + "/role/testrole", CollectionsUtil.asMap(
            "secret_id_ttl", "10m",
            "token_num_uses", "10",
            "token_ttl", "20m",
            "token_max_ttl", "30m",
            "secret_id_num_uses", "40"
    ));
    Pair<String, String> credentials = getAppRoleCredentials(template, "auth/" + authMountPath + "/role/testrole");


    final Pair<String, String> wrapped = VaultConnector.doRequestWrappedToken(new VaultFeatureSettings(getVault().getUrl(), authMountPath, credentials.getFirst(), credentials.getSecond()));

    then(wrapped.getFirst()).isNotNull();
    then(wrapped.getSecond()).isNotNull();


    final CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions.builder()
            .wrapped()
            .initialToken(VaultToken.of(wrapped.getFirst()))
            .build();
    final RestTemplate simpleTemplate = UtilKt.createRestTemplate(new VaultFeatureSettings(getVault().getUrl(), authMountPath, "", ""));
    final CubbyholeAuthentication authentication = new CubbyholeAuthentication(options, simpleTemplate);
    final TaskScheduler scheduler = new ConcurrentTaskScheduler();

    final MyLifecycleAwareSessionManager sessionManager = new MyLifecycleAwareSessionManager(authentication, simpleTemplate, scheduler);

    then(sessionManager.getSessionToken()).isNotNull();

    sessionManager.renewToken();

    then(sessionManager.getSessionToken()).isNotNull();
}
项目:logistimo-web-service    文件:RestConfig.java   
private static ClientHttpRequestFactory getClientHttpRequestFactory() {
  int timeout = ConfigUtil.getInt("api.client.timeout", 5000);
  RequestConfig config = RequestConfig.custom()
      .setConnectTimeout(timeout)
      .setConnectionRequestTimeout(timeout)
      .setSocketTimeout(timeout)
      .build();
  CloseableHttpClient client = HttpClientBuilder
      .create()
      .setDefaultRequestConfig(config)
      .build();
  return new HttpComponentsClientHttpRequestFactory(client);
}
项目:lams    文件:InterceptingHttpAccessor.java   
@Override
public ClientHttpRequestFactory getRequestFactory() {
    ClientHttpRequestFactory delegate = super.getRequestFactory();
    if (!CollectionUtils.isEmpty(getInterceptors())) {
        return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
    }
    else {
        return delegate;
    }
}
项目:spring-boot-readiness    文件:RestTemplateConfiguration.java   
@Bean
public ClientHttpRequestFactory clientHttpRequestFactory(HttpClient httpClient) {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    factory.setConnectTimeout(settings.getConnectionTimeout());
    factory.setReadTimeout(settings.getReadTimeout());
    factory.setConnectionRequestTimeout(settings.getConnectionRequestTimeout());
    return factory;
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactory.java   
/**
 * Create a {@link ClientHttpRequestFactory} for the given {@link ClientOptions}.
 *
 * @param options must not be {@literal null}
 * @return a new {@link ClientHttpRequestFactory}. Lifecycle beans must be initialized
 * after obtaining.
 */
public static ClientHttpRequestFactory create(ClientOptions options) {

    Assert.notNull(options, "ClientOptions must not be null");

    try {
        if (HTTP_COMPONENTS_PRESENT) {
            logger.info("Using Apache HttpComponents HttpClient for HTTP connections");
            return HttpComponents.usingHttpComponents(options);
        }

        if (OKHTTP3_PRESENT) {
            logger.info("Using OkHttp3 for HTTP connections");
            return OkHttp3.usingOkHttp3(options);
        }

        if (NETTY_PRESENT) {
            logger.info("Using Netty for HTTP connections");
            return Netty.usingNetty(options);
        }
    }
    catch (Exception e) {
        logger.warn("Exception caught while configuring HTTP connections", e);
    }

    logger.info("Defaulting to java.net.HttpUrlConnection for HTTP connections");
    return HttpURLConnection.usingJdk(options);
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactory.java   
static ClientHttpRequestFactory usingJdk(ClientOptions options) {
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();

    if (options.getConnectionTimeout() != null) {
        factory.setConnectTimeout(options.getConnectionTimeout());
    }
    if (options.getReadTimeout() != null) {
        factory.setReadTimeout(options.getReadTimeout());
    }

    return factory;
}
项目:spring-credhub    文件:CredHubClient.java   
/**
 * Create a {@link RestTemplate} configured for communication with a CredHub server.
 *
 * @param baseUri the base URI for the CredHub server
 * @param clientHttpRequestFactory the {@link ClientHttpRequestFactory} to use when
 * creating new connections
 * @return a configured {@link RestTemplate}
 */
public static RestTemplate createRestTemplate(String baseUri,
        ClientHttpRequestFactory clientHttpRequestFactory) {
    RestTemplate restTemplate = new RestTemplate();

    configureRestTemplate(restTemplate, baseUri, clientHttpRequestFactory);

    return restTemplate;
}
项目:spring-credhub    文件:CredHubClient.java   
/**
 * Configure a {@link RestTemplate} for communication with a CredHub server.
 * @param restTemplate an existing {@link RestTemplate} to configure
 * @param baseUri the base URI for the CredHub server
 * @param clientHttpRequestFactory the {@link ClientHttpRequestFactory} to use when
 * creating new connections
 */
public static void configureRestTemplate(RestTemplate restTemplate, String baseUri,
        ClientHttpRequestFactory clientHttpRequestFactory) {
    restTemplate.setRequestFactory(clientHttpRequestFactory);
    restTemplate.setUriTemplateHandler(createUriTemplateHandler(baseUri));
    restTemplate.setMessageConverters(createMessageConverters());
    restTemplate.setInterceptors(createInterceptors());
}
项目:spring-credhub    文件:OAuth2CredHubTemplate.java   
private static RestTemplate buildRestTemplate(OAuth2ProtectedResourceDetails resource,
        String apiUriBase, ClientHttpRequestFactory clientHttpRequestFactory) {
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resource);

    CredHubClient.configureRestTemplate(restTemplate, apiUriBase,
            clientHttpRequestFactory);

    return restTemplate;
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactoryTests.java   
@Test
public void okHttp3ClientCreated() throws Exception {
    ClientHttpRequestFactory factory = usingOkHttp3(new ClientOptions());

    assertThat(factory, instanceOf(OkHttp3ClientHttpRequestFactory.class));

    ((DisposableBean) factory).destroy();
}
项目:spring-credhub    文件:ClientHttpRequestFactoryFactoryTests.java   
@Test
public void nettyClientCreated() throws Exception {
    ClientHttpRequestFactory factory = usingNetty(new ClientOptions());

    assertThat(factory, instanceOf(Netty4ClientHttpRequestFactory.class));

    ((DisposableBean) factory).destroy();
}
项目:apollo-custom    文件:CtripUserService.java   
private ClientHttpRequestFactory clientHttpRequestFactory() {
  SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
  factory.setConnectTimeout(portalConfig.connectTimeout());
  factory.setReadTimeout(portalConfig.readTimeout());

  return factory;
}
项目:FastBootWeixin    文件:WxApiHttpRequestFactory.java   
/**
 * 获取连接工厂
 *
 * @return dummy
 */
private ClientHttpRequestFactory getClientHttpRequestFactory() {
    HttpClient httpClient = getHttpClient();
    // httpClient连接配置,底层是配置RequestConfig
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    // 连接超时
    clientHttpRequestFactory.setConnectTimeout(wxProperties.getInvoker().getConnectTimeout());
    // 数据读取超时时间,即SocketTimeout
    clientHttpRequestFactory.setReadTimeout(wxProperties.getInvoker().getReadTimeout());
    // 连接不够用的等待时间,不宜过长,必须设置,比如连接不够用时,时间过长将是灾难性的
    clientHttpRequestFactory.setConnectionRequestTimeout(wxProperties.getInvoker().getConnectionRequestTimeout());
    return clientHttpRequestFactory;
}
项目:ugc-bot-redux    文件:RestConfiguration.java   
@Bean
@Autowired
public ClientHttpRequestFactory httpRequestFactory(HttpClient httpClient) {
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(httpClient);
    return requestFactory;
}
项目:spring-boot-concourse    文件:DelayedLiveReloadTrigger.java   
DelayedLiveReloadTrigger(OptionalLiveReloadServer liveReloadServer,
        ClientHttpRequestFactory requestFactory, String url) {
    Assert.notNull(liveReloadServer, "LiveReloadServer must not be null");
    Assert.notNull(requestFactory, "RequestFactory must not be null");
    Assert.hasLength(url, "URL must not be empty");
    this.liveReloadServer = liveReloadServer;
    this.requestFactory = requestFactory;
    try {
        this.uri = new URI(url);
    }
    catch (URISyntaxException ex) {
        throw new IllegalArgumentException(ex);
    }
}
项目:log-sink    文件:InstanceLogsConfiguration.java   
@Bean
@ConditionalOnMissingBean(value = ClientHttpRequestFactory.class, name = "instanceLogsRequestFactory")
public ClientHttpRequestFactory instanceLogsRequestFactory(final Logbook logbook) {
    CloseableHttpClient client = HttpClientBuilder.create()
            .addInterceptorFirst(new LogbookHttpRequestInterceptor(logbook))
            .addInterceptorFirst(new LogbookHttpResponseInterceptor())
            .build();
    final HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
    httpRequestFactory.setHttpClient(client);
    return httpRequestFactory;
}