Polish upgrade to HttpComponents 4.3
Polish fbe605123 to make explicit the fact that a null RequestConfig
can be used to force the defaults of the current HttpClient.
Issue: SPR-11113
This commit is contained in:
@@ -2,7 +2,11 @@ package org.springframework.remoting.httpinvoker;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -14,6 +18,21 @@ import static org.mockito.Mockito.*;
|
||||
*/
|
||||
public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void assertLegacyCustomConfig() {
|
||||
HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); // Does not support RequestConfig
|
||||
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(httpClient);
|
||||
|
||||
executor.setConnectTimeout(1234);
|
||||
assertEquals(1234, httpClient.getParams().getIntParameter(
|
||||
org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, 0));
|
||||
|
||||
executor.setReadTimeout(4567);
|
||||
assertEquals(4567, httpClient.getParams().getIntParameter(
|
||||
org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizeConnectionTimeout() throws IOException {
|
||||
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor();
|
||||
@@ -34,6 +53,21 @@ public class HttpComponentsHttpInvokerRequestExecutorTests {
|
||||
assertEquals(10000, httpPost.getConfig().getSocketTimeout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ignoreFactorySettings() throws IOException {
|
||||
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
||||
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(httpClient) {
|
||||
@Override
|
||||
protected RequestConfig createRequestConfig(HttpInvokerClientConfiguration config) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
|
||||
HttpPost httpPost = executor.createHttpPost(config);
|
||||
assertNull("custom request config should not be set", httpPost.getConfig());
|
||||
}
|
||||
|
||||
private HttpInvokerClientConfiguration mockHttpInvokerClientConfiguration(String serviceUrl) {
|
||||
HttpInvokerClientConfiguration config = mock(HttpInvokerClientConfiguration.class);
|
||||
when(config.getServiceUrl()).thenReturn(serviceUrl);
|
||||
|
||||
Reference in New Issue
Block a user