Upgrade HttpComponentsHIRE to HttpComponents 4.3

Previously, HttpComponentsHttpInvokerRequestExecutor was not compatible
with the new API of HttpComponents 4.3. Specifically, it is not possible
to update the socket and read timeouts on the HttpClient itself anymore.

We actually already updated HttpComponentsClientHttpRequestFactory for a
similar problem in SPR-11442: if we detect an older HttpClient
implementation, we update the timeout directly on the client. If that's
not the case, we keep the value in the factory itself and use it when a
new HttpRequest needs to be created.

This commit also uses the new API to create a default HttpClient and
therefore requires HttpComponents 4.3. As mentioned above, it is still
possible to use deprecated HttpClient instances against this executor.

Issue: SPR-11113
This commit is contained in:
Stephane Nicoll
2014-01-17 12:17:48 +01:00
committed by Stephane Nicoll
parent abc3cc4dc4
commit fbe6051233
2 changed files with 122 additions and 12 deletions

View File

@@ -0,0 +1,43 @@
package org.springframework.remoting.httpinvoker;
import java.io.IOException;
import org.apache.http.client.methods.HttpPost;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
*
* @author Stephane Nicoll
*/
public class HttpComponentsHttpInvokerRequestExecutorTests {
@Test
public void customizeConnectionTimeout() throws IOException {
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor();
executor.setConnectTimeout(5000);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
assertEquals(5000, httpPost.getConfig().getConnectTimeout());
}
@Test
public void customizeReadTimeout() throws IOException {
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor();
executor.setReadTimeout(10000);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
assertEquals(10000, httpPost.getConfig().getSocketTimeout());
}
private HttpInvokerClientConfiguration mockHttpInvokerClientConfiguration(String serviceUrl) {
HttpInvokerClientConfiguration config = mock(HttpInvokerClientConfiguration.class);
when(config.getServiceUrl()).thenReturn(serviceUrl);
return config;
}
}