org.apache.http.client.methods.Configurable Java Examples
The following examples show how to use
org.apache.http.client.methods.Configurable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpComponentsClientHttpRequestFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client); hrf.setConnectTimeout(5000); RequestConfig requestConfig = retrieveRequestConfig(hrf); assertEquals(5000, requestConfig.getConnectTimeout()); assertEquals(6789, requestConfig.getConnectionRequestTimeout()); assertEquals(-1, requestConfig.getSocketTimeout()); }
Example #2
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws IOException { RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; given(configurable.getConfig()).willReturn(defaultConfig); HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(client); HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("https://fake-service"); HttpPost httpPost = executor.createHttpPost(config); assertSame("Default client configuration is expected", defaultConfig, httpPost.getConfig()); executor.setConnectionRequestTimeout(4567); HttpPost httpPost2 = executor.createHttpPost(config); assertNotNull(httpPost2.getConfig()); assertEquals(4567, httpPost2.getConfig().getConnectionRequestTimeout()); // Default connection timeout merged assertEquals(1234, httpPost2.getConfig().getConnectTimeout()); }
Example #3
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From spring-analysis-note with MIT License | 6 votes |
@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; given(configurable.getConfig()).willReturn(defaultConfig); HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(client); executor.setConnectTimeout(5000); HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("https://fake-service"); HttpPost httpPost = executor.createHttpPost(config); RequestConfig requestConfig = httpPost.getConfig(); assertEquals(5000, requestConfig.getConnectTimeout()); assertEquals(6789, requestConfig.getConnectionRequestTimeout()); assertEquals(-1, requestConfig.getSocketTimeout()); }
Example #4
Source File: HttpComponentsClientHttpRequestFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception { RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; when(configurable.getConfig()).thenReturn(defaultConfig); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client); assertSame("Default client configuration is expected", defaultConfig, retrieveRequestConfig(hrf)); hrf.setConnectionRequestTimeout(4567); RequestConfig requestConfig = retrieveRequestConfig(hrf); assertNotNull(requestConfig); assertEquals(4567, requestConfig.getConnectionRequestTimeout()); // Default connection timeout merged assertEquals(1234, requestConfig.getConnectTimeout()); }
Example #5
Source File: HttpComponentsClientHttpRequestFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception { RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; given(configurable.getConfig()).willReturn(defaultConfig); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client); assertSame("Default client configuration is expected", defaultConfig, retrieveRequestConfig(hrf)); hrf.setConnectionRequestTimeout(4567); RequestConfig requestConfig = retrieveRequestConfig(hrf); assertNotNull(requestConfig); assertEquals(4567, requestConfig.getConnectionRequestTimeout()); // Default connection timeout merged assertEquals(1234, requestConfig.getConnectTimeout()); }
Example #6
Source File: HttpComponentsClientHttpRequestFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@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; given(configurable.getConfig()).willReturn(defaultConfig); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client); hrf.setConnectTimeout(5000); RequestConfig requestConfig = retrieveRequestConfig(hrf); assertEquals(5000, requestConfig.getConnectTimeout()); assertEquals(6789, requestConfig.getConnectionRequestTimeout()); assertEquals(-1, requestConfig.getSocketTimeout()); }
Example #7
Source File: HttpComponentsClientHttpRequestFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@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); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client); hrf.setConnectTimeout(5000); RequestConfig requestConfig = retrieveRequestConfig(hrf); assertEquals(5000, requestConfig.getConnectTimeout()); assertEquals(6789, requestConfig.getConnectionRequestTimeout()); assertEquals(-1, requestConfig.getSocketTimeout()); }
Example #8
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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); 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()); }
Example #9
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws IOException { RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; when(configurable.getConfig()).thenReturn(defaultConfig); HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(client); HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service"); HttpPost httpPost = executor.createHttpPost(config); assertSame("Default client configuration is expected", defaultConfig, httpPost.getConfig()); executor.setConnectionRequestTimeout(4567); HttpPost httpPost2 = executor.createHttpPost(config); assertNotNull(httpPost2.getConfig()); assertEquals(4567, httpPost2.getConfig().getConnectionRequestTimeout()); // Default connection timeout merged assertEquals(1234, httpPost2.getConfig().getConnectTimeout()); }
Example #10
Source File: HttpComponentsClientHttpRequestFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception { RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; when(configurable.getConfig()).thenReturn(defaultConfig); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client); assertSame("Default client configuration is expected", defaultConfig, retrieveRequestConfig(hrf)); hrf.setConnectionRequestTimeout(4567); RequestConfig requestConfig = retrieveRequestConfig(hrf); assertNotNull(requestConfig); assertEquals(4567, requestConfig.getConnectionRequestTimeout()); // Default connection timeout merged assertEquals(1234, requestConfig.getConnectTimeout()); }
Example #11
Source File: HttpComponentsAsyncClientHttpRequestFactory.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpAsyncClient asyncClient = getHttpAsyncClient(); startAsyncClient(); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(asyncClient); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context); }
Example #12
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws IOException { RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build(); CloseableHttpClient client = mock(CloseableHttpClient.class, withSettings().extraInterfaces(Configurable.class)); Configurable configurable = (Configurable) client; when(configurable.getConfig()).thenReturn(defaultConfig); HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(client); HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service"); HttpPost httpPost = executor.createHttpPost(config); assertSame("Default client configuration is expected", defaultConfig, httpPost.getConfig()); executor.setConnectionRequestTimeout(4567); HttpPost httpPost2 = executor.createHttpPost(config); assertNotNull(httpPost2.getConfig()); assertEquals(4567, httpPost2.getConfig().getConnectionRequestTimeout()); // Default connection timeout merged assertEquals(1234, httpPost2.getConfig().getConnectTimeout()); }
Example #13
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From java-technology-stack with MIT License | 6 votes |
@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); 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()); }
Example #14
Source File: HttpComponentsAsyncClientHttpRequestFactory.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { startAsyncClient(); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(getAsyncClient()); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } return new HttpComponentsAsyncClientHttpRequest(getAsyncClient(), httpRequest, context); }
Example #15
Source File: DefaultApacheHttpClientFactoryTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test public void createClient() throws Exception { final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(100) .setConnectTimeout(200).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build(); CloseableHttpClient httpClient = new DefaultApacheHttpClientFactory( HttpClientBuilder.create()).createBuilder() .setConnectionManager(mock(HttpClientConnectionManager.class)) .setDefaultRequestConfig(requestConfig).build(); BDDAssertions.then(httpClient).isInstanceOf(Configurable.class); RequestConfig config = ((Configurable) httpClient).getConfig(); then(config.getSocketTimeout()).isEqualTo(100); then(config.getConnectTimeout()).isEqualTo(200); then(config.getCookieSpec()).isEqualTo(CookieSpecs.IGNORE_COOKIES); }
Example #16
Source File: HttpComponentsClientHttpRequestFactory.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(getHttpClient()); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } if (this.bufferRequestBody) { return new HttpComponentsClientHttpRequest(getHttpClient(), httpRequest, context); } else { return new HttpComponentsStreamingClientHttpRequest(getHttpClient(), httpRequest, context); } }
Example #17
Source File: RequestConfigs.java From caravan with Apache License 2.0 | 5 votes |
public static RequestConfig getRequestConfig(Object client) { if (client == null) return null; if (client instanceof Configurable) return ((Configurable) client).getConfig(); return getRequestConfigFromField(client); }
Example #18
Source File: HttpComponentsClientHttpRequestFactory.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpClient client = getHttpClient(); Assert.state(client != null, "Synchronous execution requires an HttpClient to be set"); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(client); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } if (this.bufferRequestBody) { return new HttpComponentsClientHttpRequest(client, httpRequest, context); } else { return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context); } }
Example #19
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 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()); }
Example #20
Source File: HttpComponentsClientHttpRequestFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory() { @Override public HttpClient getHttpClient() { return client; } }; hrf.setReadTimeout(5000); RequestConfig requestConfig = retrieveRequestConfig(hrf); 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); hrf.setReadTimeout(7000); RequestConfig requestConfig2 = retrieveRequestConfig(hrf); assertEquals(1234, requestConfig2.getConnectTimeout()); assertEquals(-1, requestConfig2.getConnectionRequestTimeout()); assertEquals(7000, requestConfig2.getSocketTimeout()); }
Example #21
Source File: ClientConfigurationTest.java From riptide with MIT License | 5 votes |
@Test void shouldApplyTimeouts() { assertThat("Configurable http client expected", exampleHttpClient, is(instanceOf(Configurable.class))); final RequestConfig config = ((Configurable) exampleHttpClient).getConfig(); assertThat(config.getSocketTimeout(), is(34 * 60 * 60 * 1000)); assertThat(config.getConnectTimeout(), is(12 * 60 * 1000)); }
Example #22
Source File: HttpComponentsClientHttpRequestFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@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); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory() { @Override public HttpClient getHttpClient() { return client; } }; hrf.setReadTimeout(5000); RequestConfig requestConfig = retrieveRequestConfig(hrf); 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); hrf.setReadTimeout(7000); RequestConfig requestConfig2 = retrieveRequestConfig(hrf); assertEquals(1234, requestConfig2.getConnectTimeout()); assertEquals(-1, requestConfig2.getConnectionRequestTimeout()); assertEquals(7000, requestConfig2.getSocketTimeout()); }
Example #23
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From java-technology-stack with MIT License | 5 votes |
@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 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()); }
Example #24
Source File: HttpComponentsClientHttpRequestFactory.java From java-technology-stack with MIT License | 5 votes |
@Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpClient client = getHttpClient(); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(client); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } if (this.bufferRequestBody) { return new HttpComponentsClientHttpRequest(client, httpRequest, context); } else { return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context); } }
Example #25
Source File: HttpComponentsAsyncClientHttpRequestFactory.java From java-technology-stack with MIT License | 5 votes |
@Override public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpAsyncClient client = startAsyncClient(); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(client); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } return new HttpComponentsAsyncClientHttpRequest(client, httpRequest, context); }
Example #26
Source File: HttpComponentsClientHttpRequestFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@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; given(configurable.getConfig()).willReturn(defaultConfig); HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory() { @Override public HttpClient getHttpClient() { return client; } }; hrf.setReadTimeout(5000); RequestConfig requestConfig = retrieveRequestConfig(hrf); 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(); given(configurable.getConfig()).willReturn(updatedDefaultConfig); hrf.setReadTimeout(7000); RequestConfig requestConfig2 = retrieveRequestConfig(hrf); assertEquals(1234, requestConfig2.getConnectTimeout()); assertEquals(-1, requestConfig2.getConnectionRequestTimeout()); assertEquals(7000, requestConfig2.getSocketTimeout()); }
Example #27
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java From spring-analysis-note with MIT License | 5 votes |
@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; given(configurable.getConfig()).willReturn(defaultConfig); HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor() { @Override public HttpClient getHttpClient() { return client; } }; executor.setReadTimeout(5000); HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("https://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(); given(configurable.getConfig()).willReturn(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()); }
Example #28
Source File: HttpComponentsClientHttpRequestFactory.java From spring-analysis-note with MIT License | 5 votes |
@Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpClient client = getHttpClient(); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(client); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } if (this.bufferRequestBody) { return new HttpComponentsClientHttpRequest(client, httpRequest, context); } else { return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context); } }
Example #29
Source File: HttpComponentsAsyncClientHttpRequestFactory.java From spring-analysis-note with MIT License | 5 votes |
@Override public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException { HttpAsyncClient client = startAsyncClient(); HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri); postProcessHttpRequest(httpRequest); HttpContext context = createHttpContext(httpMethod, uri); if (context == null) { context = HttpClientContext.create(); } // Request configuration not set in the context if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) { // Use request configuration given by the user, when available RequestConfig config = null; if (httpRequest instanceof Configurable) { config = ((Configurable) httpRequest).getConfig(); } if (config == null) { config = createRequestConfig(client); } if (config != null) { context.setAttribute(HttpClientContext.REQUEST_CONFIG, config); } } return new HttpComponentsAsyncClientHttpRequest(client, httpRequest, context); }
Example #30
Source File: HttpComponentsHttpInvokerRequestExecutor.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Create a {@link RequestConfig} for the given configuration. Can return {@code null} * to indicate that no custom request config should be set and the defaults of the * {@link HttpClient} should be used. * <p>The default implementation tries to merge the defaults of the client with the * local customizations of the instance, if any. * @param config the HTTP invoker configuration that specifies the * target service * @return the RequestConfig to use */ protected RequestConfig createRequestConfig(HttpInvokerClientConfiguration config) { HttpClient client = getHttpClient(); if (client instanceof Configurable) { RequestConfig clientRequestConfig = ((Configurable) client).getConfig(); return mergeRequestConfig(clientRequestConfig); } return this.requestConfig; }