385306 added getURI method

This commit is contained in:
Greg Wilkins 2013-01-25 13:52:32 +11:00
parent 7fd04a186f
commit 5435cd3365
9 changed files with 132 additions and 98 deletions

View File

@ -109,7 +109,7 @@ public class BalancerServletTest
private int getServerPort(Server server)
{
return ((NetworkConnector)server.getConnectors()[0]).getLocalPort();
return server.getURI().getPort();
}
protected byte[] sendRequestToBalancer(String path) throws Exception

View File

@ -19,7 +19,11 @@
package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@ -35,14 +39,18 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.validation.Schema;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.AttributesMap;
@ -580,6 +588,49 @@ public class Server extends HandlerWrapper implements Attributes
_attributes.setAttribute(name, attribute);
}
/* ------------------------------------------------------------ */
/**
* @return The URI of the first {@link NetworkConnector} and first {@link ContextHandler}, or null
*/
public URI getURI()
{
NetworkConnector connector=null;
for (Connector c: _connectors)
{
if (c instanceof NetworkConnector)
{
connector=(NetworkConnector)c;
break;
}
}
if (connector==null)
return null;
ContextHandler context = getChildHandlerByClass(ContextHandler.class);
try
{
String scheme=connector.getDefaultConnectionFactory().getProtocol().startsWith("SSL-")?"https":"http";
String host=connector.getHost();
if (context!=null && context.getVirtualHosts()!=null && context.getVirtualHosts().length>0)
host=context.getVirtualHosts()[0];
if (host==null)
host=InetAddress.getLocalHost().getHostAddress();
String path=context==null?null:context.getContextPath();
if (path==null)
path="/";
return new URI(scheme,null,host,connector.getLocalPort(),path,null,null);
}
catch(Exception e)
{
LOG.warn(e);
return null;
}
}
/* ------------------------------------------------------------ */
@Override
public String toString()

View File

@ -123,23 +123,6 @@ public class HandlerWrapper extends AbstractHandlerContainer
expandHandler(_handler,list,byClass);
}
/* ------------------------------------------------------------ */
public <H extends Handler> H getNestedHandlerByClass(Class<H> byclass)
{
HandlerWrapper h=this;
while (h!=null)
{
if (byclass.isInstance(h))
return (H)h;
Handler w = h.getHandler();
if (w instanceof HandlerWrapper)
h=(HandlerWrapper)w;
else break;
}
return null;
}
/* ------------------------------------------------------------ */
@Override
public void destroy()

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -59,7 +60,8 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
configureServer(new HelloWorldHandler());
Socket client = newSocket(HOST,_connector.getLocalPort());
URI uri = _server.getURI();
Socket client = newSocket(uri.getHost(),uri.getPort());
try
{
OutputStream os = client.getOutputStream();
@ -101,7 +103,7 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
String request =
"GET /data?writes=1&block=16&id="+pipeline+" HTTP/1.1\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+uri.getHost()+":"+uri.getPort()+"\r\n"+
"user-agent: testharness/1.0 (blah foo/bar)\r\n"+
"accept-encoding: nothing\r\n"+
"cookie: aaa=1234567890\r\n"+
@ -135,7 +137,8 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
{
configureServer(new EchoHandler());
Socket client = newSocket(HOST,_connector.getLocalPort());
URI uri = _server.getURI();
Socket client = newSocket(uri.getHost(),uri.getPort());
try
{
OutputStream os = client.getOutputStream();
@ -148,7 +151,7 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
os.write((
"POST /echo?charset=utf-8 HTTP/1.1\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+uri.getHost()+":"+uri.getPort()+"\r\n"+
"content-type: text/plain; charset=utf-8\r\n"+
"content-length: "+bytes.length+"\r\n"+
"\r\n"

View File

@ -60,7 +60,8 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
public void testMaxIdleWithRequest10() throws Exception
{
configureServer(new HelloWorldHandler());
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -70,7 +71,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: keep-alive\r\n"+
"\r\n").getBytes("utf-8"));
os.flush();
@ -89,7 +90,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
public void testMaxIdleWithRequest11() throws Exception
{
configureServer(new EchoHandler());
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -101,7 +102,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
byte[] contentB=content.getBytes("utf-8");
os.write((
"POST /echo HTTP/1.1\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"content-type: text/plain; charset=utf-8\r\n"+
"content-length: "+contentB.length+"\r\n"+
"\r\n").getBytes("utf-8"));
@ -140,7 +141,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
}
});
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -150,7 +151,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: close\r\n"+
"\r\n").getBytes("utf-8"));
os.flush();
@ -177,7 +178,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: keep-alive\r\n"+
"\r\n").getBytes("utf-8"));
os.flush();
@ -214,7 +215,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
}
});
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -224,7 +225,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: close\r\n"+
"\r\n").getBytes("utf-8"));
os.flush();
@ -290,7 +291,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
}
});
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -302,7 +303,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
byte[] contentB=content.getBytes("utf-8");
os.write((
"POST /echo HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: " + contentB.length + "\r\n" +
"connection: close\r\n" +
@ -329,7 +330,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
{
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: keep-alive\r\n"+
"\r\n").getBytes("utf-8"));
os.flush();
@ -349,7 +350,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
public void testMaxIdleNoRequest() throws Exception
{
configureServer(new EchoHandler());
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
InputStream is=client.getInputStream();
assertFalse(client.isClosed());
@ -377,7 +378,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
public void testMaxIdleWithSlowRequest() throws Exception
{
configureServer(new EchoHandler());
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -389,7 +390,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
byte[] contentB=content.getBytes("utf-8");
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: keep-alive\r\n"+
"Content-Length: "+(contentB.length*20)+"\r\n"+
"Content-Type: text/plain\r\n"+
@ -417,7 +418,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
public void testMaxIdleWithSlowResponse() throws Exception
{
configureServer(new SlowResponseHandler());
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -427,7 +428,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: keep-alive\r\n"+
"Connection: close\r\n"+
"\r\n").getBytes("utf-8"));
@ -446,7 +447,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
public void testMaxIdleWithWait() throws Exception
{
configureServer(new WaitHandler());
Socket client=newSocket(HOST,_connector.getLocalPort());
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
client.setSoTimeout(10000);
assertFalse(client.isClosed());
@ -456,7 +457,7 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.write((
"GET / HTTP/1.0\r\n"+
"host: "+HOST+":"+_connector.getLocalPort()+"\r\n"+
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
"connection: keep-alive\r\n"+
"Connection: close\r\n"+
"\r\n").getBytes("utf-8"));

View File

@ -118,7 +118,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(true);
((StdErrLog)Log.getLogger(HttpConnection.class)).info("expect request is too large, then ISE extra data ...");
@ -149,7 +149,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(true);
((StdErrLog)Log.getLogger(HttpConnection.class)).info("expect URI is too large, then ISE extra data ...");
@ -192,7 +192,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
StringBuffer request = new StringBuffer("GET / HTTP/1.0\r\n");
request.append("Host: localhost\r\n\r\n");
Socket client = newSocket(HOST, _connector.getLocalPort());
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
OutputStream os = client.getOutputStream();
try
@ -246,7 +246,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
request.append("Content-length: 6\n\n");
request.append("foo");
Socket client = newSocket(HOST, _connector.getLocalPort());
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
OutputStream os = client.getOutputStream();
os.write(request.toString().getBytes());
@ -269,7 +269,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(true);
((StdErrLog)Log.getLogger(HttpConnection.class)).info("expect header is too large, then ISE extra data ...");
@ -317,7 +317,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -337,7 +337,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new EchoHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -367,7 +367,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new EchoHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -396,7 +396,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -426,7 +426,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
byte[] bytes = REQUEST2.getBytes();
for (int i = 0; i < LOOPS; i++)
{
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -474,7 +474,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// Sort the list
Arrays.sort(points);
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -505,7 +505,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// Sort the list
Arrays.sort(points);
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
@ -537,7 +537,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
String test = encoding[e] + "x" + b + "x" + w + "x" + c;
try
{
URL url = new URL(_scheme + "://" + HOST + ":" + _connector.getLocalPort() + "/?writes=" + w + "&block=" + b + (e == 0 ? "" : ("&encoding=" + encoding[e])) + (c == 0 ? "&chars=true" : ""));
URL url = new URL(_scheme + "://" + _serverURI.getHost() + ":" + _serverURI.getPort() + "/?writes=" + w + "&block=" + b + (e == 0 ? "" : ("&encoding=" + encoding[e])) + (c == 0 ? "&chars=true" : ""));
InputStream in = (InputStream)url.getContent();
String response = IO.toString(in, e == 0 ? null : encoding[e]);
@ -562,14 +562,14 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
configureServer(new DataHandler());
long start = System.currentTimeMillis();
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write((
"GET /data?writes=1024&block=256 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"connection: close\r\n" +
"content-type: unknown\r\n" +
"content-length: 30\r\n" +
@ -624,14 +624,14 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
long start = System.currentTimeMillis();
int total = 0;
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write((
"GET /data?writes=256&block=1024 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"connection: close\r\n" +
"content-type: unknown\r\n" +
"\r\n"
@ -665,7 +665,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new BigBlockHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
client.setSoTimeout(20000);
@ -674,10 +674,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
os.write((
"GET /r1 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"\r\n" +
"GET /r2 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"connection: close\r\n" +
"\r\n"
).getBytes());
@ -797,7 +797,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
//for (int pipeline=1;pipeline<32;pipeline++)
for (int pipeline = 1; pipeline < 32; pipeline++)
{
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
client.setSoTimeout(5000);
OutputStream os = client.getOutputStream();
@ -807,7 +807,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
for (int i = 1; i < pipeline; i++)
request +=
"GET /data?writes=1&block=16&id=" + i + " HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"user-agent: testharness/1.0 (blah foo/bar)\r\n" +
"accept-encoding: nothing\r\n" +
"cookie: aaa=1234567890\r\n" +
@ -815,7 +815,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
request +=
"GET /data?writes=1&block=16 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"user-agent: testharness/1.0 (blah foo/bar)\r\n" +
"accept-encoding: nothing\r\n" +
"cookie: aaa=bbbbbb\r\n" +
@ -844,14 +844,14 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
public void testRecycledWriters() throws Exception
{
configureServer(new EchoHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write((
"POST /echo?charset=utf-8 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"\r\n").getBytes("iso-8859-1"));
@ -862,7 +862,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
os.write((
"POST /echo?charset=utf-8 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"\r\n"
@ -876,7 +876,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
byte[] contentB = content.getBytes("utf-8");
os.write((
"POST /echo?charset=utf-16 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: " + contentB.length + "\r\n" +
"connection: close\r\n" +
@ -928,28 +928,28 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new EchoHandler(false));
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write((
"POST /R1 HTTP/1.1\015\012" +
"Host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"\015\012" +
"123456789\n" +
"HEAD /R1 HTTP/1.1\015\012" +
"Host: " + HOST + ":" + _connector.getLocalPort() + "\015\012" +
"Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\015\012" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"\015\012" +
"123456789\n" +
"POST /R1 HTTP/1.1\015\012" +
"Host: " + HOST + ":" + _connector.getLocalPort() + "\015\012" +
"Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\015\012" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"Connection: close\015\012" +
@ -976,14 +976,14 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new EchoHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write((
"POST /echo?charset=utf-8 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"\r\n").getBytes("iso-8859-1"));
@ -994,7 +994,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
os.write((
"POST /echo?charset=utf-8 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-8\r\n" +
"content-length: 10\r\n" +
"\r\n"
@ -1008,7 +1008,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
byte[] contentB = content.getBytes("utf-16");
os.write((
"POST /echo?charset=utf-8 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"content-type: text/plain; charset=utf-16\r\n" +
"content-length: " + contentB.length + "\r\n" +
"connection: close\r\n" +
@ -1030,7 +1030,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new HelloWorldHandler());
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
@ -1038,7 +1038,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// Send a request with chunked input and expect 100
os.write((
"GET / HTTP/1.1\r\n" +
"Host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"Transfer-Encoding: chunked\r\n" +
"Expect: 100-continue\r\n" +
"Connection: Keep-Alive\r\n" +
@ -1066,7 +1066,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
CommittedErrorHandler handler = new CommittedErrorHandler();
configureServer(handler);
Socket client = newSocket(HOST, _connector.getLocalPort());
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
try
{
((StdErrLog)Log.getLogger(HttpChannel.class)).setHideStacks(true);
@ -1076,7 +1076,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// Send a request
os.write(("GET / HTTP/1.1\r\n" +
"Host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"\r\n"
).getBytes());
os.flush();
@ -1206,14 +1206,14 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
AvailableHandler ah = new AvailableHandler();
configureServer(ah);
try (Socket client = newSocket(HOST, _connector.getLocalPort()))
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
os.write((
"GET /data?writes=1024&block=256 HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"connection: close\r\n" +
"content-type: unknown\r\n" +
"content-length: 30\r\n" +
@ -1251,7 +1251,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
configureServer(new HelloWorldHandler());
try (Socket client1 = newSocket(HOST, _connector.getLocalPort()); Socket client2 = newSocket(HOST, _connector.getLocalPort()))
try (Socket client1 = newSocket(_serverURI.getHost(), _serverURI.getPort()); Socket client2 = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os1 = client1.getOutputStream();
OutputStream os2 = client2.getOutputStream();
@ -1345,7 +1345,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
new String(fill);
final byte[] bytes = content.getBytes();
Socket client = newSocket(HOST, _connector.getLocalPort());
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
final OutputStream out = client.getOutputStream();
new Thread()
@ -1405,7 +1405,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
configureServer(suspend);
long start = System.currentTimeMillis();
Socket client = newSocket(HOST, _connector.getLocalPort());
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
client.setSoTimeout(5000);
try
{
@ -1414,7 +1414,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// write an initial request
os.write((
"GET / HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"\r\n"
).getBytes());
os.flush();
@ -1424,7 +1424,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
// write an pipelined request
os.write((
"GET / HTTP/1.1\r\n" +
"host: " + HOST + ":" + _connector.getLocalPort() + "\r\n" +
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
"connection: close\r\n" +
"\r\n"
).getBytes());

View File

@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.Socket;
import java.net.URI;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
@ -42,9 +43,9 @@ public class HttpServerTestFixture
{ // Useful constants
protected static final long PAUSE=10L;
protected static final int LOOPS=50;
protected static final String HOST="localhost";
protected Server _server;
protected URI _serverURI;
protected NetworkConnector _connector;
protected String _scheme="http";
@ -69,6 +70,7 @@ public class HttpServerTestFixture
_server.addConnector(_connector);
_server.setHandler(new HandlerWrapper());
_server.start();
_serverURI = _server.getURI();
}
@After

View File

@ -24,6 +24,7 @@ import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;
import java.net.URI;
import java.security.KeyStore;
import java.util.Arrays;
@ -153,7 +154,8 @@ public class SelectChannelServerSslTest extends HttpServerTestBase
// Sort the list
Arrays.sort(points);
Socket client=newSocket(HOST,_connector.getLocalPort());
URI uri=_server.getURI();
Socket client=newSocket(uri.getHost(),uri.getPort());
try
{
OutputStream os=client.getOutputStream();

View File

@ -120,15 +120,7 @@ public class GzipWithPipeliningTest
// Start Server
server.start();
NetworkConnector conn = (NetworkConnector)server.getConnectors()[0];
String host = conn.getHost();
if (host == null)
{
host = "localhost";
}
int port = conn.getLocalPort();
serverUri = new URI(String.format("ws://%s:%d/",host,port));
// System.out.printf("Server URI: %s%n",serverUri);
serverUri = server.getURI();
}
@After