Author: veithen
Date: Thu Dec 29 10:12:14 2011
New Revision: 1225488
URL: http://svn.apache.org/viewvc?rev=1225488&view=rev
Log:
Avoid using a fixed port number, so that the build can run concurrently with
other builds.
Modified:
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
Modified:
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java?rev=1225488&r1=1225487&r2=1225488&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java
(original)
+++
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/CommonsHTTPTransportSenderClientSideTest.java
Thu Dec 29 10:12:14 2011
@@ -22,6 +22,7 @@ import org.apache.http.message.BasicRequ
public class CommonsHTTPTransportSenderClientSideTest extends
AbstractHTTPServerTest {
public void testInvokeWithEPR() throws Exception {
+ int port = getBasicHttpServer().getPort();
RequestLine line = new BasicRequestLine("", "", new
ProtocolVersion("http", 1, 0));
MockHTTPResponse httpResponse = new MockAxisHttpResponse(line);
getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_OK_LOOP_BACK);
@@ -30,7 +31,7 @@ public class CommonsHTTPTransportSenderC
// client hence ignore the processing of response at client side.
try {
httpResponse = (MockAxisHttpResponse)
CommonsHTTPTransportSenderTest.configAndRun(
- httpResponse, (OutTransportInfo) httpResponse,
"http://localhost:8080");
+ httpResponse, (OutTransportInfo) httpResponse,
"http://localhost:" + port);
} catch (Exception e) {
}
@@ -48,6 +49,7 @@ public class CommonsHTTPTransportSenderC
* a 404 error. This is a regression test for AXIS2-5093.
*/
public void testConnectionReleaseWith404() throws Exception {
+ int port = getBasicHttpServer().getPort();
getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_404);
// If connections are not properly released then we will end up with a
// ConnectionPoolTimeoutException here.
@@ -58,7 +60,7 @@ public class CommonsHTTPTransportSenderC
null);
ServiceClient serviceClient = new ServiceClient(configurationContext,
null);
Options options = serviceClient.getOptions();
- options.setTo(new
EndpointReference("http://localhost:8080//nonexisting"));
+ options.setTo(new EndpointReference("http://localhost:" + port +
"//nonexisting"));
OMElement request = OMAbstractFactory.getOMFactory().createOMElement(
new QName("urn:test", "test"));
// If connections are not properly released then we will end up with a
Modified:
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java?rev=1225488&r1=1225487&r2=1225488&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
(original)
+++
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
Thu Dec 29 10:12:14 2011
@@ -74,8 +74,9 @@ public class HTTPSenderTest extends Abst
* @throws Exception the exception
*/
public void testSendViaGet() throws Exception {
+ int port = getBasicHttpServer().getPort();
sendViaHTTP(Constants.Configuration.HTTP_METHOD_GET, "urn:getService",
- "http://localhost:8080/getService", true);
+ "http://localhost:" + port + "/getService", true);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_GET,
getHTTPMethod());
assertEquals("Not the expected content",
"/getService?part=sample%20data",
@@ -85,7 +86,7 @@ public class HTTPSenderTest extends Abst
assertEquals("Not the expected HTTP Header value",
"application/x-www-form-urlencoded;action=\"urn:getService\";",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
@@ -98,8 +99,9 @@ public class HTTPSenderTest extends Abst
*/
public void testSendViaPost() throws Exception {
// test with REST payload
+ int port = getBasicHttpServer().getPort();
sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST,
"urn:postService",
- "http://localhost:8080/postService", true);
+ "http://localhost:" + port + "/postService", true);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_POST,
getHTTPMethod());
assertEquals("Not the expected content",
getEnvelope().getFirstElement().getFirstElement()
@@ -108,14 +110,14 @@ public class HTTPSenderTest extends Abst
getHeaders().get("SOAPAction"));
assertEquals("Not the expected HTTP Header value", "application/xml",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
// test with SOAP payload.
sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST,
"urn:postService",
- "http://localhost:8080/postService", false);
+ "http://localhost:" + port + "/postService", false);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_POST,
getHTTPMethod());
assertEquals("Not the expected content", getEnvelope().toString(),
getStringContent());
@@ -123,7 +125,7 @@ public class HTTPSenderTest extends Abst
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
@@ -136,8 +138,9 @@ public class HTTPSenderTest extends Abst
*/
public void testSendViaPut() throws Exception {
// test with REST payload
+ int port = getBasicHttpServer().getPort();
sendViaHTTP(Constants.Configuration.HTTP_METHOD_PUT, "urn:putService",
- "http://localhost:8080/putService", true);
+ "http://localhost:" + port + "/putService", true);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_PUT,
getHTTPMethod());
assertEquals("Not the expected content",
getEnvelope().getFirstElement().getFirstElement()
@@ -146,14 +149,14 @@ public class HTTPSenderTest extends Abst
getHeaders().get("SOAPAction"));
assertEquals("Not the expected HTTP Header value", "application/xml",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
// test with SOAP payload.
sendViaHTTP(Constants.Configuration.HTTP_METHOD_PUT, "urn:putService",
- "http://localhost:8080/putService", false);
+ "http://localhost:" + port + "/putService", false);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_PUT,
getHTTPMethod());
assertEquals("Not the expected content", getEnvelope().toString(),
getStringContent());
@@ -161,7 +164,7 @@ public class HTTPSenderTest extends Abst
getHeaders().get("SOAPAction").replace("\"", ""));
assertEquals("Not the expected HTTP Header value", "text/xml",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
@@ -174,8 +177,9 @@ public class HTTPSenderTest extends Abst
*/
public void testSendViaDelete() throws Exception {
// test with REST payload
+ int port = getBasicHttpServer().getPort();
sendViaHTTP(Constants.Configuration.HTTP_METHOD_DELETE,
"urn:deleteService",
- "http://localhost:8080/deleteService", true);
+ "http://localhost:" + port + "/deleteService", true);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_DELETE,
getHTTPMethod());
assertEquals("Not the expected content",
"/deleteService?part=sample%20data",
@@ -183,7 +187,7 @@ public class HTTPSenderTest extends Abst
assertEquals("Not the expected HTTP Header value",
"application/x-www-form-urlencoded;action=\"urn:deleteService\";", getHeaders()
.get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
@@ -197,15 +201,16 @@ public class HTTPSenderTest extends Abst
*/
public void testSendViaHead() throws Exception {
+ int port = getBasicHttpServer().getPort();
sendViaHTTP(Constants.Configuration.HTTP_METHOD_HEAD,
"urn:deleteService",
- "http://localhost:8080/deleteService", true);
+ "http://localhost:" + port + "/deleteService", true);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_POST,
getHTTPMethod());
assertEquals("Not the expected content",
getEnvelope().getFirstElement().getFirstElement()
.toString(), getStringContent());
assertEquals("Not the expected HTTP Header value", "application/xml",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
@@ -219,7 +224,8 @@ public class HTTPSenderTest extends Abst
*/
public void testSendNOHTTPMethod() throws Exception {
- sendViaHTTP(null, "urn:noService", "http://localhost:8080/noService",
true);
+ int port = getBasicHttpServer().getPort();
+ sendViaHTTP(null, "urn:noService", "http://localhost:" + port +
"/noService", true);
assertEquals("Not the expected HTTP Method",
Constants.Configuration.HTTP_METHOD_POST,
getHTTPMethod());
assertEquals("Not the expected content",
getEnvelope().getFirstElement().getFirstElement()
@@ -228,7 +234,7 @@ public class HTTPSenderTest extends Abst
getHeaders().get("SOAPAction"));
assertEquals("Not the expected HTTP Header value", "application/xml",
getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("Not the expected HTTP Header value", "localhost:8080",
+ assertEquals("Not the expected HTTP Header value", "localhost:" + port,
getHeaders().get(HttpHeaders.HOST));
assertEquals("Not the expected HTTP Header value", "Axis2",
getHeaders().get(HttpHeaders.USER_AGENT));
Modified:
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java?rev=1225488&r1=1225487&r2=1225488&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
(original)
+++
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
Thu Dec 29 10:12:14 2011
@@ -40,6 +40,13 @@ public interface BasicHttpServer {
public void start() throws Exception;
/**
+ * Get the port on which the HTTP server is listening.
+ *
+ * @return the HTTP port
+ */
+ public int getPort();
+
+ /**
* Stop the HTTP server.
*
* @throws Exception
Modified:
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java?rev=1225488&r1=1225487&r2=1225488&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
(original)
+++
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
Thu Dec 29 10:12:14 2011
@@ -73,7 +73,7 @@ import org.apache.http.util.EntityUtils;
*/
public class BasicHttpServerImpl implements BasicHttpServer {
- private Thread serverThread;
+ private RequestListenerThread serverThread;
private Map<String, String> headers;
private byte[] content;
private String method;
@@ -93,11 +93,15 @@ public class BasicHttpServerImpl impleme
* @see org.apache.axis2.transport.http.mock.server.BasicHttpServer#start()
*/
public void start() throws Exception {
- serverThread = new RequestListenerThread(8080, this);
+ serverThread = new RequestListenerThread(this);
serverThread.setDaemon(false);
serverThread.start();
}
+ public int getPort() {
+ return serverThread.getServersocket().getLocalPort();
+ }
+
/*
* (non-Javadoc)
*
@@ -105,7 +109,7 @@ public class BasicHttpServerImpl impleme
*/
public void stop() throws Exception {
if (close) {
- ((RequestListenerThread) serverThread).getServersocket().close();
+ serverThread.getServersocket().close();
}
}
@@ -257,8 +261,8 @@ public class BasicHttpServerImpl impleme
* @throws IOException
* Signals that an I/O exception has occurred.
*/
- public RequestListenerThread(int port, BasicHttpServer server) throws
IOException {
- this.serversocket = new ServerSocket(port);
+ public RequestListenerThread(BasicHttpServer server) throws
IOException {
+ this.serversocket = new ServerSocket(0);
this.params = new BasicHttpParams();
// Basic configuration.
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)