diff --git a/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java b/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java index ff0e61772..f85fc0a27 100644 --- a/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java +++ b/module-client/src/test/java/org/apache/http/client/protocol/TestRedirects.java @@ -476,7 +476,7 @@ public void testPostRedirect() throws Exception { public void testRelativeRedirect() throws Exception { int port = this.localServer.getServicePort(); - String host = "localhost"; + String host = this.localServer.getServiceHostName(); this.localServer.register("*", new RelativeRedirectService()); DefaultHttpClient client = new DefaultHttpClient(); @@ -505,7 +505,7 @@ public void testRelativeRedirect() throws Exception { public void testRelativeRedirect2() throws Exception { int port = this.localServer.getServicePort(); - String host = "localhost"; + String host = this.localServer.getServiceHostName(); this.localServer.register("*", new RelativeRedirectService2()); DefaultHttpClient client = new DefaultHttpClient(); diff --git a/module-client/src/test/java/org/apache/http/localserver/LocalTestServer.java b/module-client/src/test/java/org/apache/http/localserver/LocalTestServer.java index 4b795895a..3972b9f4a 100644 --- a/module-client/src/test/java/org/apache/http/localserver/LocalTestServer.java +++ b/module-client/src/test/java/org/apache/http/localserver/LocalTestServer.java @@ -290,6 +290,20 @@ public int getServicePort() { } + /** + * Obtains the hostname of the server. + * + * @return the hostname + */ + public String getServiceHostName() { + ServerSocket ssock = servicedSocket; // avoid synchronization + if (ssock == null) + throw new IllegalStateException("not running"); + + return ((InetSocketAddress) ssock.getLocalSocketAddress()).getHostName(); + } + + /** * Obtains the local address the server is listening on *