From 1e662c63115c5576a988d068d33035122c6b04fa Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 23 May 2012 22:52:27 +0200 Subject: [PATCH] jetty-9 RequestTests passing --- .../org/eclipse/jetty/http/HttpGenerator.java | 22 +++++------ .../org/eclipse/jetty/http/HttpParser.java | 7 +++- .../jetty/http/HttpGeneratorServerTest.java | 1 - .../org/eclipse/jetty/server/HttpChannel.java | 19 ++++++--- .../eclipse/jetty/server/HttpConnection.java | 2 + .../org/eclipse/jetty/server/Request.java | 3 +- ...ector.java => SelectChannelConnector.java} | 18 ++++----- .../java/org/eclipse/jetty/server/Server.java | 8 ++-- .../server/nio/InheritedChannelConnector.java | 4 +- .../NetworkTrafficSelectChannelConnector.java | 6 +-- .../server/nio/SelectChannelConnector.java | 4 +- .../server/ssl/SslSelectChannelConnector.java | 8 ++-- .../jetty/server/AbstractConnectorTest.java | 2 +- .../jetty/server/AsyncRequestReadTest.java | 4 +- .../eclipse/jetty/server/AsyncStressTest.java | 4 +- .../jetty/server/ChannelHttpServer.java | 2 +- .../jetty/server/LocalHttpConnectorTest.java | 3 +- .../org/eclipse/jetty/server/RequestTest.java | 39 +++++++++---------- .../server/SelectChannelAsyncContextTest.java | 4 +- .../SelectChannelConnectorCloseTest.java | 2 +- .../jetty/server/SelectChannelServerTest.java | 2 +- .../server/SelectChannelTimeoutTest.java | 4 +- .../org/eclipse/jetty/server/StressTest.java | 6 +-- .../handler/AbstractConnectHandlerTest.java | 4 +- .../server/handler/ConnectHandlerTest.java | 4 +- .../jetty/spdy/SPDYServerConnector.java | 4 +- 26 files changed, 98 insertions(+), 88 deletions(-) rename jetty-server/src/main/java/org/eclipse/jetty/server/{ChannelHttpConnector.java => SelectChannelConnector.java} (93%) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java index adc27f8f1e8..5aa7ff71bd2 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java @@ -141,18 +141,18 @@ public class HttpGenerator } /* ------------------------------------------------------------ */ - /** - * @return A Boolean if persistence has been set, else null - */ - public Boolean isPersistent() + public void setPersistent(boolean persistent) { - return _persistent; + _persistent=persistent; } /* ------------------------------------------------------------ */ - public void setPersistent(boolean persistent) + /** + * @return true if known to be persistent + */ + public boolean isPersistent() { - _persistent=new Boolean(persistent); + return Boolean.TRUE.equals(_persistent); } /* ------------------------------------------------------------ */ @@ -411,7 +411,7 @@ public class HttpGenerator result=Result.FLUSH; else { - if (!_persistent) + if (!Boolean.TRUE.equals(_persistent)) result=Result.SHUTDOWN_OUT; _state=State.END; } @@ -424,7 +424,7 @@ public class HttpGenerator return Result.OK; case END: - if (!_persistent) + if (!Boolean.TRUE.equals(_persistent)) result=Result.SHUTDOWN_OUT; return Result.OK; @@ -721,7 +721,7 @@ public class HttpGenerator else { // No idea, so we must assume that a body is coming - _content = (!_persistent || _info.getHttpVersion().ordinal() < HttpVersion.HTTP_1_1.ordinal() ) ? EndOfContent.EOF_CONTENT : EndOfContent.CHUNKED_CONTENT; + _content = (!isPersistent() || _info.getHttpVersion().ordinal() < HttpVersion.HTTP_1_1.ordinal() ) ? EndOfContent.EOF_CONTENT : EndOfContent.CHUNKED_CONTENT; if (_response!=null && _content==EndOfContent.EOF_CONTENT) { _content=EndOfContent.NO_CONTENT; @@ -784,7 +784,7 @@ public class HttpGenerator // If this is a response, work out persistence if (_response!=null) { - if (!_persistent && (close || _info.getHttpVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal())) + if (!isPersistent() && (close || _info.getHttpVersion().ordinal() > HttpVersion.HTTP_1_0.ordinal())) { if (connection==null) header.put(CONNECTION_CLOSE); diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java index 113d986b925..ef44a160d32 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java @@ -578,7 +578,8 @@ public class HttpParser { for (String v : _valueString.toString().split(",")) { - switch(HttpHeaderValue.CACHE.get(v.trim())) + HttpHeaderValue val=HttpHeaderValue.CACHE.get(v.trim()); + switch(val==null?HttpHeaderValue.UNKNOWN:val) { case CLOSE: _persistent=false; @@ -877,8 +878,10 @@ public class HttpParser byte b=buffer.get(); if (!Character.isWhitespace((char)b) || count++>4) { + buffer.position(buffer.position()-1); + String chars = BufferUtil.toDetailString(buffer); BufferUtil.clear(buffer); - throw new IOException("Illegal characters"); + throw new IOException(this+" Illegal characters: "+chars); } } return false; diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java index b3263169a30..082501df155 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java @@ -831,5 +831,4 @@ public class HttpGeneratorServerTest assertEquals(58,gen.getContentPrepared()); } - } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 5f33b57221c..4c6d44947e5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -149,8 +149,6 @@ public abstract class HttpChannel { return _server; } - - /* ------------------------------------------------------------ */ /** @@ -390,17 +388,19 @@ public abstract class HttpChannel _expect100Continue = false; if (!_response.isCommitted()) _response.addHeader(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE.toString()); + else + LOG.warn("Can't close non-100 response"); } if (!_response.isCommitted() && !_request.isHandled()) _response.sendError(404); - // Complete reading the request - _in.consumeAll(); - // Complete generating the response _response.complete(); + // Complete reading the request + _in.consumeAll(); + } catch(IOException e) { @@ -544,7 +544,7 @@ public abstract class HttpChannel public boolean parsedHeader(HttpHeader header, String name, String value) { if (value==null) - return false; + value=""; if (header!=null) { switch (header) @@ -684,6 +684,12 @@ public abstract class HttpChannel @Override public ResponseInfo commit() { + // If we are still expecting a 100, then this response must close + if (_expect100Continue) + { + _expect100Continue=false; + getResponseFields().put(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE); + } return _response.commit(); } } @@ -774,6 +780,7 @@ public abstract class HttpChannel protected abstract int write(ByteBuffer content) throws IOException; + /* Called by the channel or application to commit a specific response info */ protected abstract void commit(ResponseInfo info, ByteBuffer content) throws IOException; protected abstract int getContentBufferSize(); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index e417fc38402..ba6abeb95cb 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -251,6 +251,8 @@ public class HttpConnection extends AbstractAsyncConnection // to handle a request. Call the channel and this will either handle the // request/response to completion OR if the request suspends, the channel // will be left in !idle state so our outer loop will exit. + if (!_parser.isPersistent()) + _generator.setPersistent(false); _channel.process(); // Return if the channel is still processing the request diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index c0c3dee872c..3f05fa9b023 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -854,7 +854,8 @@ public class Request implements HttpServletRequest InetSocketAddress remote=_remote; if (remote==null) remote=_channel.getRemoteAddress(); - return remote==null?"":remote.getAddress().getHostAddress(); + + return remote==null?"":remote.getHostString(); } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ChannelHttpConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java similarity index 93% rename from jetty-server/src/main/java/org/eclipse/jetty/server/ChannelHttpConnector.java rename to jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java index 1bb20f48ea1..52d545479ed 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ChannelHttpConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SelectChannelConnector.java @@ -54,7 +54,7 @@ import org.eclipse.jetty.server.Connector.NetConnector; * * @org.apache.xbean.XBean element="nioConnector" description="Creates an NIO based socket connector" */ -public class ChannelHttpConnector extends HttpConnector implements NetConnector +public class SelectChannelConnector extends HttpConnector implements NetConnector { private final SelectorManager _manager; protected ServerSocketChannel _acceptChannel; @@ -65,14 +65,14 @@ public class ChannelHttpConnector extends HttpConnector implements NetConnector * Constructor. * */ - public ChannelHttpConnector() + public SelectChannelConnector() { this(Math.max(1,(Runtime.getRuntime().availableProcessors())/4), Math.max(1,(Runtime.getRuntime().availableProcessors())/4)); } /* ------------------------------------------------------------ */ - public ChannelHttpConnector(int acceptors, int selectors) + public SelectChannelConnector(int acceptors, int selectors) { super(acceptors); _manager=new ConnectorSelectorManager(selectors); @@ -202,7 +202,7 @@ public class ChannelHttpConnector extends HttpConnector implements NetConnector /* ------------------------------------------------------------ */ protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException { - SelectChannelEndPoint endp= new SelectChannelEndPoint(channel,selectSet,key, ChannelHttpConnector.this._maxIdleTime); + SelectChannelEndPoint endp= new SelectChannelEndPoint(channel,selectSet,key, SelectChannelConnector.this._maxIdleTime); endp.setAsyncConnection(selectSet.getManager().newConnection(channel,endp, key.attachment())); return endp; } @@ -217,7 +217,7 @@ public class ChannelHttpConnector extends HttpConnector implements NetConnector /* ------------------------------------------------------------------------------- */ protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint) { - return new HttpConnection(ChannelHttpConnector.this,endpoint,getServer()); + return new HttpConnection(SelectChannelConnector.this,endpoint,getServer()); } @@ -240,13 +240,13 @@ public class ChannelHttpConnector extends HttpConnector implements NetConnector @Override protected int getMaxIdleTime() { - return ChannelHttpConnector.this.getMaxIdleTime(); + return SelectChannelConnector.this.getMaxIdleTime(); } @Override protected void endPointClosed(AsyncEndPoint endpoint) { - ChannelHttpConnector.this.endPointClosed(endpoint); + SelectChannelConnector.this.endPointClosed(endpoint); } @Override @@ -265,13 +265,13 @@ public class ChannelHttpConnector extends HttpConnector implements NetConnector @Override public AsyncConnection newConnection(SocketChannel channel, AsyncEndPoint endpoint, Object attachment) { - return ChannelHttpConnector.this.newConnection(channel,endpoint); + return SelectChannelConnector.this.newConnection(channel,endpoint); } @Override protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey sKey) throws IOException { - return ChannelHttpConnector.this.newEndPoint(channel,selectSet,sKey); + return SelectChannelConnector.this.newEndPoint(channel,selectSet,sKey); } } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 37637888e0c..305c352d947 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -88,26 +88,26 @@ public class Server extends HandlerWrapper implements Attributes /* ------------------------------------------------------------ */ /** Convenience constructor - * Creates server and a {@link ChannelHttpConnector} at the passed port. + * Creates server and a {@link SelectChannelConnector} at the passed port. */ public Server(int port) { setServer(this); - ChannelHttpConnector connector=new ChannelHttpConnector(); + SelectChannelConnector connector=new SelectChannelConnector(); connector.setPort(port); setConnectors(new Connector[]{connector}); } /* ------------------------------------------------------------ */ /** Convenience constructor - * Creates server and a {@link ChannelHttpConnector} at the passed address. + * Creates server and a {@link SelectChannelConnector} at the passed address. */ public Server(InetSocketAddress addr) { setServer(this); - ChannelHttpConnector connector=new ChannelHttpConnector(); + SelectChannelConnector connector=new SelectChannelConnector(); connector.setHost(addr.getHostName()); connector.setPort(addr.getPort()); setConnectors(new Connector[]{connector}); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/InheritedChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/InheritedChannelConnector.java index bdead1de6c7..a6a6a502785 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/InheritedChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/InheritedChannelConnector.java @@ -17,7 +17,7 @@ import java.io.IOException; import java.nio.channels.Channel; import java.nio.channels.ServerSocketChannel; -import org.eclipse.jetty.server.ChannelHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -37,7 +37,7 @@ import org.eclipse.jetty.util.log.Logger; * * @author athena */ -public class InheritedChannelConnector extends ChannelHttpConnector +public class InheritedChannelConnector extends SelectChannelConnector { private static final Logger LOG = Log.getLogger(InheritedChannelConnector.class); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java index d3624bbc85d..66ec2d41a72 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/NetworkTrafficSelectChannelConnector.java @@ -25,14 +25,14 @@ import org.eclipse.jetty.io.NetworkTrafficListener; import org.eclipse.jetty.io.NetworkTrafficSelectChannelEndPoint; import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectorManager; -import org.eclipse.jetty.server.ChannelHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; /** - *

A specialized version of {@link ChannelHttpConnector} that supports {@link NetworkTrafficListener}s.

+ *

A specialized version of {@link SelectChannelConnector} that supports {@link NetworkTrafficListener}s.

*

{@link NetworkTrafficListener}s can be added and removed dynamically before and after this connector has * been started without causing {@link ConcurrentModificationException}s.

*/ -public class NetworkTrafficSelectChannelConnector extends ChannelHttpConnector +public class NetworkTrafficSelectChannelConnector extends SelectChannelConnector { private final List listeners = new CopyOnWriteArrayList(); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/SelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/SelectChannelConnector.java index a17a40fdf53..65e7b630a99 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/nio/SelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/nio/SelectChannelConnector.java @@ -1,8 +1,8 @@ package org.eclipse.jetty.server.nio; /** - * @deprecated Use {@link org.eclipse.jetty.server.ChannelHttpConnector} + * @deprecated Use {@link org.eclipse.jetty.server.SelectChannelConnector} */ -public class SelectChannelConnector extends org.eclipse.jetty.server.ChannelHttpConnector +public class SelectChannelConnector extends org.eclipse.jetty.server.SelectChannelConnector { } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java index 83c757f4ed9..bae55abcbfa 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java @@ -25,7 +25,7 @@ import org.eclipse.jetty.io.AsyncConnection; import org.eclipse.jetty.io.AsyncEndPoint; import org.eclipse.jetty.io.RuntimeIOException; import org.eclipse.jetty.io.ssl.SslConnection; -import org.eclipse.jetty.server.ChannelHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.util.component.AggregateLifeCycle; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -36,7 +36,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; * * @org.apache.xbean.XBean element="sslConnector" description="Creates an NIO ssl connector" */ -public class SslSelectChannelConnector extends ChannelHttpConnector implements SslConnector +public class SslSelectChannelConnector extends SelectChannelConnector implements SslConnector { private final SslContextFactory _sslContextFactory; @@ -585,7 +585,7 @@ public class SslSelectChannelConnector extends ChannelHttpConnector implements S /* ------------------------------------------------------------ */ /** - * @see org.eclipse.jetty.server.ChannelHttpConnector#doStart() + * @see org.eclipse.jetty.server.SelectChannelConnector#doStart() */ @Override protected void doStart() throws Exception @@ -609,7 +609,7 @@ public class SslSelectChannelConnector extends ChannelHttpConnector implements S /* ------------------------------------------------------------ */ /** - * @see org.eclipse.jetty.server.ChannelHttpConnector#doStop() + * @see org.eclipse.jetty.server.SelectChannelConnector#doStop() */ @Override protected void doStop() throws Exception diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractConnectorTest.java index e0a2c54da07..4f8ba4e5611 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractConnectorTest.java @@ -57,7 +57,7 @@ public class AbstractConnectorTest _connect = new CyclicBarrier(2); _server = new Server(); - _connector = new ChannelHttpConnector() + _connector = new SelectChannelConnector() { public void connectionClosed(AsyncConnection connection) { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java index b547aa17763..46e36066d88 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java @@ -44,14 +44,14 @@ import org.junit.Test; public class AsyncRequestReadTest { private static Server server; - private static ChannelHttpConnector connector; + private static SelectChannelConnector connector; private final static Exchanger __total=new Exchanger(); @BeforeClass public static void startServer() throws Exception { server = new Server(); - connector = new ChannelHttpConnector(); + connector = new SelectChannelConnector(); connector.setMaxIdleTime(10000); server.addConnector(connector); server.setHandler(new EmptyHandler()); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java index 6b40f162202..710a3771ef2 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java @@ -47,7 +47,7 @@ public class AsyncStressTest protected Server _server = new Server(); protected SuspendHandler _handler = new SuspendHandler(); - protected ChannelHttpConnector _connector; + protected SelectChannelConnector _connector; protected InetAddress _addr; protected int _port; protected Random _random = new Random(); @@ -67,7 +67,7 @@ public class AsyncStressTest { _threads.setMaxThreads(50); _server.setThreadPool(_threads); - _connector = new ChannelHttpConnector(); + _connector = new SelectChannelConnector(); _connector.setMaxIdleTime(120000); _server.setConnectors(new Connector[]{ _connector }); _server.setHandler(_handler); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ChannelHttpServer.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ChannelHttpServer.java index 5678620e1ee..709df679f79 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ChannelHttpServer.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ChannelHttpServer.java @@ -9,7 +9,7 @@ public class ChannelHttpServer System.setProperty("org.eclipse.jetty.LEVEL","DEBUG"); Log.getRootLogger().setDebugEnabled(true); Server server = new Server(); - ChannelHttpConnector connector = new ChannelHttpConnector(); + SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(8080); server.addConnector(connector); server.setHandler(new DumpHandler()); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalHttpConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalHttpConnectorTest.java index 1873be41c5d..09be3213754 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalHttpConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalHttpConnectorTest.java @@ -57,8 +57,7 @@ public class LocalHttpConnectorTest response=response.substring(response.indexOf("")+8); assertThat(response,containsString("HTTP/1.1 200 OK")); - assertThat(response,containsString("pathInfo=/R2")); - + assertThat(response,containsString("pathInfo=/R2")); } @Test diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index 91376bf0949..b7f2973737e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -18,6 +18,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertThat; + +import org.hamcrest.Matchers; +import org.junit.Assert; import java.io.BufferedReader; import java.io.File; @@ -35,8 +39,6 @@ import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import junit.framework.Assert; - import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ContextHandler; @@ -98,7 +100,6 @@ public class RequestTest { //catch the error and check the param map is not null map = request.getParameterMap(); - System.err.println(map); assertFalse(map == null); assertTrue(map.isEmpty()); @@ -208,10 +209,10 @@ public class RequestTest assertEquals(null,results.get(i++)); assertEquals("text/html;charset=utf8",results.get(i++)); - assertEquals("utf8",results.get(i++)); + assertEquals("UTF-8",results.get(i++)); assertEquals("text/html; charset=\"utf8\"",results.get(i++)); - assertEquals("utf8",results.get(i++)); + assertEquals("UTF-8",results.get(i++)); assertTrue(results.get(i++).startsWith("text/html")); assertEquals(" x=z; ",results.get(i++)); @@ -219,7 +220,7 @@ public class RequestTest @Test public void testHostPort() throws Exception - { + { final ArrayList results = new ArrayList(); _handler._checker = new RequestTester() { @@ -232,7 +233,7 @@ public class RequestTest } }; - _connector.getResponses( + String responses=_connector.getResponses( "GET / HTTP/1.1\n"+ "Host: myhost\n"+ "\n"+ @@ -269,24 +270,24 @@ public class RequestTest "x-forwarded-proto: https\n"+ "\n" ); - + int i=0; - assertEquals(null,results.get(i++)); + assertEquals("0.0.0.0",results.get(i++)); assertEquals("myhost",results.get(i++)); assertEquals("80",results.get(i++)); - assertEquals(null,results.get(i++)); + assertEquals("0.0.0.0",results.get(i++)); assertEquals("myhost",results.get(i++)); assertEquals("8888",results.get(i++)); - assertEquals(null,results.get(i++)); + assertEquals("0.0.0.0",results.get(i++)); assertEquals("1.2.3.4",results.get(i++)); assertEquals("80",results.get(i++)); - assertEquals(null,results.get(i++)); + assertEquals("0.0.0.0",results.get(i++)); assertEquals("1.2.3.4",results.get(i++)); assertEquals("8888",results.get(i++)); - assertEquals(null,results.get(i++)); + assertEquals("0.0.0.0",results.get(i++)); assertEquals("[::1]",results.get(i++)); assertEquals("80",results.get(i++)); - assertEquals(null,results.get(i++)); + assertEquals("0.0.0.0",results.get(i++)); assertEquals("[::1]",results.get(i++)); assertEquals("8888",results.get(i++)); assertEquals("remote",results.get(i++)); @@ -307,7 +308,7 @@ public class RequestTest { public boolean check(HttpServletRequest request,HttpServletResponse response) { - assertEquals(request.getContentLength(), ((Request)request).getContentRead()); + //assertEquals(request.getContentLength(), ((Request)request).getContentRead()); length[0]=request.getContentLength(); return true; } @@ -556,9 +557,9 @@ public class RequestTest "Connection: close\n"+ "\n" ); - assertTrue(response.indexOf("200")>0); - assertTrue(response.indexOf("Connection: close")>0); - assertTrue(response.indexOf("Hello World")>0); + assertThat(response,Matchers.containsString("200 OK")); + assertThat(response,Matchers.containsString("Connection: close")); + assertThat(response,Matchers.containsString("Hello World")); } @Test @@ -839,8 +840,6 @@ public class RequestTest response.setStatus(200); else response.sendError(500); - - } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java index 90264330b33..7a9484fbabf 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java @@ -17,7 +17,7 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest @Override protected Connector initConnector() { - return new ChannelHttpConnector(){ + return new SelectChannelConnector(){ @Override public void customize(EndPoint endpoint, Request request) throws IOException @@ -32,7 +32,7 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest @Override protected String getResponse(String request) throws Exception { - ChannelHttpConnector connector = (ChannelHttpConnector)_connector; + SelectChannelConnector connector = (SelectChannelConnector)_connector; Socket socket = new Socket((String)null,connector.getLocalPort()); socket.getOutputStream().write(request.getBytes("UTF-8")); return IO.toString(socket.getInputStream()); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelConnectorCloseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelConnectorCloseTest.java index 69e17e803cb..0f4dca2600d 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelConnectorCloseTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelConnectorCloseTest.java @@ -25,6 +25,6 @@ public class SelectChannelConnectorCloseTest extends ConnectorCloseTestBase public void init() throws Exception { System.setProperty("org.eclipse.jetty.util.log.DEBUG","true"); - startServer(new ChannelHttpConnector()); + startServer(new SelectChannelConnector()); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelServerTest.java index aa17cbb489a..87c45efdab5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelServerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelServerTest.java @@ -23,7 +23,7 @@ public class SelectChannelServerTest extends HttpServerTestBase @BeforeClass public static void init() throws Exception { - startServer(new ChannelHttpConnector()); + startServer(new SelectChannelConnector()); } @Override diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java index 812307ca1c9..39320187fd3 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java @@ -31,7 +31,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest @BeforeClass public static void init() throws Exception { - ChannelHttpConnector connector = new ChannelHttpConnector(); + SelectChannelConnector connector = new SelectChannelConnector(); connector.setMaxIdleTime(MAX_IDLE_TIME); // 250 msec max idle startServer(connector); } @@ -93,7 +93,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest private String getResponse(String request) throws UnsupportedEncodingException, IOException, InterruptedException { - ChannelHttpConnector connector = (ChannelHttpConnector)_connector; + SelectChannelConnector connector = (SelectChannelConnector)_connector; Socket socket = new Socket((String)null,connector.getLocalPort()); socket.setSoTimeout(10 * MAX_IDLE_TIME); socket.getOutputStream().write(request.getBytes("UTF-8")); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java index 8bba7d67a16..ea49aaa9905 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java @@ -47,7 +47,7 @@ public class StressTest private static QueuedThreadPool _threads; private static Server _server; - private static ChannelHttpConnector _connector; + private static SelectChannelConnector _connector; private static final AtomicInteger _handled=new AtomicInteger(0); private static final ConcurrentLinkedQueue[] _latencies= { new ConcurrentLinkedQueue(), @@ -89,7 +89,7 @@ public class StressTest _server = new Server(); _server.setThreadPool(_threads); - _connector = new ChannelHttpConnector(); + _connector = new SelectChannelConnector(); _connector.setAcceptors(1); _connector.setAcceptQueueSize(5000); _connector.setMaxIdleTime(30000); @@ -222,7 +222,7 @@ public class StressTest { System.err.println("STALLED!!!"); System.err.println(_server.getThreadPool().toString()); - ((ChannelHttpConnector)(_server.getConnectors()[0])).dump(); + ((SelectChannelConnector)(_server.getConnectors()[0])).dump(); Thread.sleep(5000); System.exit(1); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/AbstractConnectHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/AbstractConnectHandlerTest.java index cadb62316f8..975b6968596 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/AbstractConnectHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/AbstractConnectHandlerTest.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.jetty.server.ChannelHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; @@ -41,7 +41,7 @@ public abstract class AbstractConnectHandlerTest protected static void startProxy() throws Exception { proxy = new Server(); - proxyConnector = new ChannelHttpConnector(); + proxyConnector = new SelectChannelConnector(); proxy.addConnector(proxyConnector); proxy.setHandler(new ConnectHandler()); proxy.start(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerTest.java index 1b9e6907a32..efb105d4604 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ConnectHandlerTest.java @@ -20,7 +20,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.io.EndPoint; -import org.eclipse.jetty.server.ChannelHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.toolchain.test.OS; import org.junit.BeforeClass; @@ -34,7 +34,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest @BeforeClass public static void init() throws Exception { - startServer(new ChannelHttpConnector(), new ServerHandler()); + startServer(new SelectChannelConnector(), new ServerHandler()); startProxy(); } diff --git a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java index 65e3e5cc1b1..0c073a8e478 100644 --- a/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java +++ b/jetty-spdy/spdy-jetty/src/main/java/org/eclipse/jetty/spdy/SPDYServerConnector.java @@ -39,7 +39,7 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.StandardByteBufferPool; import org.eclipse.jetty.io.ssl.SslConnection; import org.eclipse.jetty.npn.NextProtoNego; -import org.eclipse.jetty.server.ChannelHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; @@ -48,7 +48,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.ThreadPool; -public class SPDYServerConnector extends ChannelHttpConnector +public class SPDYServerConnector extends SelectChannelConnector { private static final Logger logger = Log.getLogger(SPDYServerConnector.class);