Java Code Examples for org.apache.http.client.methods.HttpPost#getConfig()

The following examples show how to use org.apache.http.client.methods.HttpPost#getConfig() . 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: HttpComponentsHttpInvokerRequestExecutorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 2
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 3
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 5
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 6
Source File: HttpComponentsHttpInvokerRequestExecutorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}