Commit 6cfbcafc authored by Dave Syer's avatar Dave Syer

Switch to httpcomponents for better error handling in tests

parent 5661f8fc
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
<activemq.version>5.4.0</activemq.version> <activemq.version>5.4.0</activemq.version>
<aspectj.version>1.7.3</aspectj.version> <aspectj.version>1.7.3</aspectj.version>
<commons-dbcp.version>1.4</commons-dbcp.version> <commons-dbcp.version>1.4</commons-dbcp.version>
<commons-httpclient.version>3.1</commons-httpclient.version>
<gradle.version>1.6</gradle.version> <gradle.version>1.6</gradle.version>
<groovy.version>2.1.6</groovy.version> <groovy.version>2.1.6</groovy.version>
<h2.version>1.3.172</h2.version> <h2.version>1.3.172</h2.version>
...@@ -18,6 +17,8 @@ ...@@ -18,6 +17,8 @@
<hibernate-entitymanager.version>4.2.1.Final</hibernate-entitymanager.version> <hibernate-entitymanager.version>4.2.1.Final</hibernate-entitymanager.version>
<hibernate-jpa-api.version>1.0.1.Final</hibernate-jpa-api.version> <hibernate-jpa-api.version>1.0.1.Final</hibernate-jpa-api.version>
<hibernate-validator.version>4.3.1.Final</hibernate-validator.version> <hibernate-validator.version>4.3.1.Final</hibernate-validator.version>
<httpclient.version>4.3.1</httpclient.version>
<httpasyncclient.version>4.0</httpasyncclient.version>
<hsqldb.version>2.2.9</hsqldb.version> <hsqldb.version>2.2.9</hsqldb.version>
<jackson.version>2.2.2</jackson.version> <jackson.version>2.2.2</jackson.version>
<jetty.version>8.1.9.v20130131</jetty.version> <jetty.version>8.1.9.v20130131</jetty.version>
...@@ -79,11 +80,6 @@ ...@@ -79,11 +80,6 @@
<artifactId>commons-dbcp</artifactId> <artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version> <version>${commons-dbcp.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>${commons-httpclient.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.lambdaworks</groupId> <groupId>com.lambdaworks</groupId>
<artifactId>lettuce</artifactId> <artifactId>lettuce</artifactId>
...@@ -134,6 +130,16 @@ ...@@ -134,6 +130,16 @@
<artifactId>activemq-pool</artifactId> <artifactId>activemq-pool</artifactId>
<version>${activemq.version}</version> <version>${activemq.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>${httpasyncclient.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.tomcat.embed</groupId> <groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId> <artifactId>tomcat-embed-core</artifactId>
......
...@@ -91,8 +91,13 @@ ...@@ -91,8 +91,13 @@
</dependency> </dependency>
<!-- Test --> <!-- Test -->
<dependency> <dependency>
<groupId>commons-httpclient</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>commons-httpclient</artifactId> <artifactId>httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -24,17 +24,14 @@ import java.net.URISyntaxException; ...@@ -24,17 +24,14 @@ import java.net.URISyntaxException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.junit.After; import org.junit.After;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
...@@ -44,9 +41,11 @@ import org.springframework.http.HttpMethod; ...@@ -44,9 +41,11 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.util.concurrent.ListenableFuture;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
...@@ -115,25 +114,26 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -115,25 +114,26 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
} }
@Test @Test
@Ignore
public void restartWithKeepAlive() throws Exception { public void restartWithKeepAlive() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); ConfigurableEmbeddedServletContainerFactory factory = getFactory();
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
this.container.start(); this.container.start();
MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory();
HttpClient client = new HttpClient(connectionManager); ListenableFuture<ClientHttpResponse> response1 = clientHttpRequestFactory
GetMethod get1 = new GetMethod("http://localhost:8080/hello"); .createAsyncRequest(new URI("http://localhost:8080/hello"),
assertThat(client.executeMethod(get1), equalTo(200)); HttpMethod.GET).executeAsync();
get1.releaseConnection(); assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode(), equalTo(200));
this.container.stop(); this.container.stop();
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
this.container.start();
GetMethod get2 = new GetMethod("http://localhost:8080/hello"); ListenableFuture<ClientHttpResponse> response2 = clientHttpRequestFactory
assertThat(client.executeMethod(get2), equalTo(200)); .createAsyncRequest(new URI("http://localhost:8080/hello"),
get2.releaseConnection(); HttpMethod.GET).executeAsync();
assertThat(response2.get(10, TimeUnit.SECONDS).getRawStatusCode(), equalTo(200));
} }
@Test @Test
...@@ -267,9 +267,6 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -267,9 +267,6 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
} }
@Test @Test
@Ignore
// FIXME: how to test an error response (maybe java.net.HttpUrlConnection isn't going
// to cut it)
public void errorPage() throws Exception { public void errorPage() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); ConfigurableEmbeddedServletContainerFactory factory = getFactory();
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello")); factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello"));
...@@ -292,7 +289,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -292,7 +289,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
protected ClientHttpResponse getClientResponse(String url) throws IOException, protected ClientHttpResponse getClientResponse(String url) throws IOException,
URISyntaxException { URISyntaxException {
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory(); HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(url), ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(url),
HttpMethod.GET); HttpMethod.GET);
ClientHttpResponse response = request.execute(); ClientHttpResponse response = request.execute();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment