Example usage for org.apache.http.client.config RequestConfig getConnectTimeout

List of usage examples for org.apache.http.client.config RequestConfig getConnectTimeout

Introduction

In this page you can find the example usage for org.apache.http.client.config RequestConfig getConnectTimeout.

Prototype

public int getConnectTimeout() 

Source Link

Document

Determines the timeout in milliseconds until a connection is established.

Usage

From source file:com.baidubce.util.HttpUtils.java

public static void printRequest(HttpRequestBase request) {
    if (!HTTP_VERBOSE) {
        return;//from  www.j a v a  2 s  . com
    }
    System.out.println("\n-------------> ");
    System.out.println(request.getRequestLine());
    for (Header h : request.getAllHeaders()) {
        System.out.println(h.getName() + " : " + h.getValue());
    }
    RequestConfig config = request.getConfig();
    if (config != null) {
        System.out.println("getConnectionRequestTimeout: " + config.getConnectionRequestTimeout());
        System.out.println("getConnectTimeout: " + config.getConnectTimeout());
        System.out.println("getCookieSpec: " + config.getCookieSpec());
        System.out.println("getLocalAddress: " + config.getLocalAddress());

    }
}

From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutorTests.java

@Test
public void localSettingsOverrideClientDefaultSettings() throws Exception {
    RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234)
            .setConnectionRequestTimeout(6789).build();
    CloseableHttpClient client = mock(CloseableHttpClient.class,
            withSettings().extraInterfaces(Configurable.class));
    Configurable configurable = (Configurable) client;
    when(configurable.getConfig()).thenReturn(defaultConfig);

    HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(client);
    executor.setConnectTimeout(5000);/*from  ww  w .ja  v  a2s . co  m*/

    HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
    HttpPost httpPost = executor.createHttpPost(config);
    RequestConfig requestConfig = httpPost.getConfig();
    assertEquals(5000, requestConfig.getConnectTimeout());
    assertEquals(6789, requestConfig.getConnectionRequestTimeout());
    assertEquals(-1, requestConfig.getSocketTimeout());
}

From source file:org.springframework.boot.webservices.client.HttpWebServiceMessageSenderBuilderTests.java

@Test
public void buildUsesHttpComponentsByDefault() {
    ClientHttpRequestMessageSender messageSender = build(new HttpWebServiceMessageSenderBuilder()
            .setConnectTimeout(Duration.ofSeconds(5)).setReadTimeout(Duration.ofSeconds(2)));
    ClientHttpRequestFactory requestFactory = messageSender.getRequestFactory();
    assertThat(requestFactory).isInstanceOf(HttpComponentsClientHttpRequestFactory.class);
    RequestConfig requestConfig = (RequestConfig) ReflectionTestUtils.getField(requestFactory, "requestConfig");
    assertThat(requestConfig).isNotNull();
    assertThat(requestConfig.getConnectTimeout()).isEqualTo(5000);
    assertThat(requestConfig.getSocketTimeout()).isEqualTo(2000);
}

From source file:org.springframework.remoting.httpinvoker.HttpComponentsHttpInvokerRequestExecutorTests.java

@Test
public void mergeBasedOnCurrentHttpClient() throws Exception {
    RequestConfig defaultConfig = RequestConfig.custom().setSocketTimeout(1234).build();
    final CloseableHttpClient client = mock(CloseableHttpClient.class,
            withSettings().extraInterfaces(Configurable.class));
    Configurable configurable = (Configurable) client;
    when(configurable.getConfig()).thenReturn(defaultConfig);

    HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor() {
        @Override//from w  w  w.  j a  v a  2 s.com
        public HttpClient getHttpClient() {
            return client;
        }
    };
    executor.setReadTimeout(5000);
    HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
    HttpPost httpPost = executor.createHttpPost(config);
    RequestConfig requestConfig = httpPost.getConfig();
    assertEquals(-1, requestConfig.getConnectTimeout());
    assertEquals(-1, requestConfig.getConnectionRequestTimeout());
    assertEquals(5000, requestConfig.getSocketTimeout());

    // Update the Http client so that it returns an updated  config
    RequestConfig updatedDefaultConfig = RequestConfig.custom().setConnectTimeout(1234).build();
    when(configurable.getConfig()).thenReturn(updatedDefaultConfig);
    executor.setReadTimeout(7000);
    HttpPost httpPost2 = executor.createHttpPost(config);
    RequestConfig requestConfig2 = httpPost2.getConfig();
    assertEquals(1234, requestConfig2.getConnectTimeout());
    assertEquals(-1, requestConfig2.getConnectionRequestTimeout());
    assertEquals(7000, requestConfig2.getSocketTimeout());
}

From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClientTests.java

@Test
public void testTimeouts() throws Exception {
    RequestConfig result = getBuiltRequestConfig(Timeouts.class, null);
    assertThat(result.getConnectTimeout(), is(60000));
    assertThat(result.getSocketTimeout(), is(50000));
}

From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItemAsyncTest.java

@Test
public void testTimeoutSettings() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(CONNECT_TIMEOUT_PROPERTY, 9)
                    .put(SOCKET_TIMEOUT_PROPERTY, 99).build());

    HttpClientItem item = new HttpClientItem(config);
    HttpAsyncClient client = item.getHttpAsyncClient();
    RequestConfig requestConfig = HttpClientTestUtils.getDefaultRequestConfig(client);
    assertEquals(9, requestConfig.getConnectTimeout());
    assertEquals(99, requestConfig.getSocketTimeout());
    item.close();/*from  w  ww  . j  a va2 s.  c o m*/
}

From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpClientItemAsyncTest.java

@Test
public void testTimeoutSettings() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(CONNECT_TIMEOUT_PROPERTY, 9)
                    .put(SOCKET_TIMEOUT_PROPERTY, 99).build());

    HttpAsyncClientItem item = new HttpAsyncClientItem(config);
    HttpAsyncClient client = item.getHttpAsyncClient();
    RequestConfig requestConfig = HttpClientTestUtils.getDefaultRequestConfig(client);
    assertEquals(9, requestConfig.getConnectTimeout());
    assertEquals(99, requestConfig.getSocketTimeout());
    item.close();/*from   w  w w  .  j  a  v  a  2  s .co m*/
}

From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClientTests.java

@Test
public void testUpdatedTimeouts() throws Exception {
    SpringClientFactory factory = new SpringClientFactory();
    RequestConfig result = getBuiltRequestConfig(Timeouts.class, null, factory);
    assertThat(result.getConnectTimeout(), is(60000));
    assertThat(result.getSocketTimeout(), is(50000));
    IClientConfig config = factory.getClientConfig("service");
    config.set(CommonClientConfigKey.ConnectTimeout, 60);
    config.set(CommonClientConfigKey.ReadTimeout, 50);
    result = getBuiltRequestConfig(Timeouts.class, null, factory);
    assertThat(result.getConnectTimeout(), is(60));
    assertThat(result.getSocketTimeout(), is(50));
}

From source file:io.cloudslang.content.httpclient.build.RequestConfigBuilderTest.java

@Test
public void buildNoProxyRoute() throws URISyntaxException, HttpException {
    RequestConfig reqConfig = requestConfigBuilder.buildRequestConfig();

    assertNotNull(reqConfig);//from   w ww . ja v  a  2 s.  c om
    assertTrue(reqConfig.isRedirectsEnabled());
    assertEquals("0", String.valueOf(reqConfig.getConnectTimeout()));
    assertEquals("0", String.valueOf(reqConfig.getSocketTimeout()));
    assertNull(reqConfig.getProxy());
}

From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItemTest.java

@Test
public void testTimeoutSettings() {
    HttpClientConfigImpl config = context.registerInjectActivateService(new HttpClientConfigImpl(),
            ImmutableMap.<String, Object>builder().put(CONNECT_TIMEOUT_PROPERTY, 9)
                    .put(SOCKET_TIMEOUT_PROPERTY, 99).build());

    HttpClientItem item = new HttpClientItem(config);
    HttpClient client = item.getHttpClient();
    RequestConfig requestConfig = HttpClientTestUtils.getDefaultRequestConfig(client);
    assertEquals(9, requestConfig.getConnectTimeout());
    assertEquals(99, requestConfig.getSocketTimeout());
    item.close();//  w  w w.j ava 2 s .c om
}