From e70df19248d36f713aeaf9477092ee1282b9c4ff Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 13 Jul 2012 22:55:40 +1000 Subject: [PATCH 1/2] jetty-9 progress on more unit tests --- example-jetty-embedded/pom.xml | 21 - .../org/eclipse/jetty/http/HttpFields.java | 14 +- .../org/eclipse/jetty/http/HttpTester.java | 345 +++++++++++ .../org/eclipse/jetty/http/MimeTypes.java | 2 + jetty-proxy/pom.xml | 93 +++ .../eclipse/jetty/proxy}/ProxyServlet.java | 2 +- .../jetty/proxy}/AsyncProxyServer.java | 2 +- .../jetty/proxy}/ProxyServletTest.java | 3 +- .../jetty/servlet/ServletContextHandler.java | 2 +- .../eclipse/jetty/servlet/ServletTester.java | 203 ++++++ jetty-servlets/pom.xml | 11 - .../jetty/servlets/CloseableDoSFilter.java | 20 +- .../eclipse/jetty/servlets/GzipFilter.java | 6 +- .../jetty/servlets/AbstractDoSFilterTest.java | 13 +- .../jetty/servlets/CrossOriginFilterTest.java | 3 +- .../servlets/IncludableGzipFilterTest.java | 38 +- .../jetty/servlets/MultipartFilterTest.java | 15 +- .../eclipse/jetty/servlets/PutFilterTest.java | 60 +- .../eclipse/jetty/servlets/QoSFilterTest.java | 5 +- .../websocket/protocol/WebSocketFrame.java | 1 + pom.xml | 2 +- test-jetty-servlet/pom.xml | 23 - .../src/main/java/Jetty400Repro.java | 128 ---- .../org/eclipse/jetty/testing/HttpTester.java | 585 ------------------ .../eclipse/jetty/testing/ServletTester.java | 374 ----------- .../eclipse/jetty/testing/HttpTesterTest.java | 56 -- .../eclipse/jetty/testing/ServletTest.java | 343 ---------- test-jetty-webapp/pom.xml | 6 - 28 files changed, 729 insertions(+), 1647 deletions(-) create mode 100644 jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java create mode 100644 jetty-proxy/pom.xml rename {jetty-servlets/src/main/java/org/eclipse/jetty/servlets => jetty-proxy/src/main/java/org/eclipse/jetty/proxy}/ProxyServlet.java (99%) rename {jetty-servlets/src/test/java/org/eclipse/jetty/servlets => jetty-proxy/src/test/java/org/eclipse/jetty/proxy}/AsyncProxyServer.java (98%) rename {jetty-servlets/src/test/java/org/eclipse/jetty/servlets => jetty-proxy/src/test/java/org/eclipse/jetty/proxy}/ProxyServletTest.java (98%) create mode 100644 jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java delete mode 100644 test-jetty-servlet/pom.xml delete mode 100644 test-jetty-servlet/src/main/java/Jetty400Repro.java delete mode 100644 test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/HttpTester.java delete mode 100644 test-jetty-servlet/src/main/java/org/eclipse/jetty/testing/ServletTester.java delete mode 100644 test-jetty-servlet/src/test/java/org/eclipse/jetty/testing/HttpTesterTest.java delete mode 100644 test-jetty-servlet/src/test/java/org/eclipse/jetty/testing/ServletTest.java diff --git a/example-jetty-embedded/pom.xml b/example-jetty-embedded/pom.xml index c7112d9f8af..794e77c0285 100644 --- a/example-jetty-embedded/pom.xml +++ b/example-jetty-embedded/pom.xml @@ -24,11 +24,6 @@ jetty-servlets ${project.version} - - org.eclipse.jetty - jetty-rewrite - ${project.version} - org.eclipse.jetty jetty-deploy @@ -38,32 +33,16 @@ org.eclipse.jetty jetty-jmx ${project.version} - - - org.eclipse.jetty - jetty-ajp - ${project.version} org.eclipse.jetty.toolchain jetty-test-helper test - - org.eclipse.jetty - jetty-websocket - ${project.version} - junit junit test - - org.eclipse.jetty - test-jetty-servlet - ${project.version} - test - diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index f1081bb81e0..2c636bfaefa 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -382,7 +382,19 @@ public class HttpFields implements Iterable /* -------------------------------------------------------------- */ public String getStringField(HttpHeader header) { - return getStringField(header.toString()); + return getStringField(header.asString()); + } + + /* -------------------------------------------------------------- */ + public String get(HttpHeader header) + { + return getStringField(header.asString()); + } + + /* -------------------------------------------------------------- */ + public String get(String header) + { + return getStringField(header); } /* -------------------------------------------------------------- */ diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java new file mode 100644 index 00000000000..1cef9256142 --- /dev/null +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java @@ -0,0 +1,345 @@ +package org.eclipse.jetty.http; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; + +import org.eclipse.jetty.io.RuntimeIOException; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.StringUtil; + +public class HttpTester +{ + private Message _message; + private Request _request; + private Response _response; + + public void setMethod(String method) + { + if (_request==null) + _request=new Request(); + _message=_request; + _request._method=method; + } + + public void setVersion(HttpVersion version) + { + if (_message==null) + _message=_response=new Response(); + _message._version=version; + } + + public void setVersion(String version) + { + setVersion(HttpVersion.CACHE.get(version)); + } + + public void setHeader(String name, String value) + { + _message.put(name,value); + + } + + public void setURI(String uri) + { + if (_request==null) + _request=new Request(); + _message=_request; + _request._uri=uri; + } + + public void setContent(String content) + { + try + { + _message._content=new ByteArrayOutputStream(); + _message._content.write(StringUtil.getBytes(content)); + } + catch (IOException e) + { + throw new RuntimeIOException(e); + } + } + + public void setContent(ByteBuffer content) + { + try + { + _message._content=new ByteArrayOutputStream(); + _message._content.write(BufferUtil.toArray(content)); + } + catch (IOException e) + { + throw new RuntimeIOException(e); + } + } + + public ByteBuffer generate() + { + try + { + HttpGenerator generator = new HttpGenerator(); + HttpGenerator.Info info = _message.getInfo(); + System.err.println(info.getClass()); + System.err.println(info); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ByteBuffer header=BufferUtil.allocate(8192); + ByteBuffer buffer=BufferUtil.allocate(8192); + ByteBuffer chunk=BufferUtil.allocate(16); + ByteBuffer content=_message._content==null?null:ByteBuffer.wrap(_message._content.toByteArray()); + + + loop: while(true) + { + HttpGenerator.Result result = generator.generate(info,header,chunk,buffer,content,HttpGenerator.Action.COMPLETE); + switch(result) + { + case NEED_BUFFER: + case NEED_HEADER: + case NEED_CHUNK: + case NEED_INFO: + throw new IllegalStateException(); + + case FLUSH: + if (BufferUtil.hasContent(header)) + { + out.write(BufferUtil.toArray(header)); + BufferUtil.clear(header); + } + if (BufferUtil.hasContent(chunk)) + { + out.write(BufferUtil.toArray(chunk)); + BufferUtil.clear(chunk); + } + if (BufferUtil.hasContent(buffer)) + { + out.write(BufferUtil.toArray(buffer)); + BufferUtil.clear(buffer); + } + break; + + case FLUSH_CONTENT: + if (BufferUtil.hasContent(header)) + { + out.write(BufferUtil.toArray(header)); + BufferUtil.clear(header); + } + if (BufferUtil.hasContent(chunk)) + { + out.write(BufferUtil.toArray(chunk)); + BufferUtil.clear(chunk); + } + if (BufferUtil.hasContent(content)) + { + out.write(BufferUtil.toArray(content)); + BufferUtil.clear(content); + } + break; + case OK: + case SHUTDOWN_OUT: + break loop; + } + } + + return ByteBuffer.wrap(out.toByteArray()); + } + catch (IOException e) + { + throw new RuntimeIOException(e); + } + + } + + public String toString() + { + return String.format("%s %s",_request,_response); + } + + public static Request parseRequest(String request) + { + Request r=new Request(); + HttpParser parser =new HttpParser(r); + parser.parseNext(BufferUtil.toBuffer(request)); + return r; + } + + public static Request parseRequest(ByteBuffer request) + { + Request r=new Request(); + HttpParser parser =new HttpParser(r); + parser.parseNext(request); + return r; + } + + public static Response parseResponse(String response) + { + Response r=new Response(); + HttpParser parser =new HttpParser(r); + parser.parseNext(BufferUtil.toBuffer(response)); + return r; + } + + public static Response parseResponse(ByteBuffer response) + { + Response r=new Response(); + HttpParser parser =new HttpParser(r); + parser.parseNext(response); + return r; + } + + + public abstract static class Message extends HttpFields implements HttpParser.HttpHandler + { + ByteArrayOutputStream _content; + HttpVersion _version=HttpVersion.HTTP_1_0; + + public HttpVersion getVersion() + { + return _version; + } + + @Override + public boolean parsedHeader(HttpHeader header, String name, String value) + { + put(name,value); + return false; + } + + @Override + public boolean messageComplete(long contentLength) + { + return true; + } + + @Override + public boolean headerComplete(boolean hasBody, boolean persistent) + { + if (hasBody) + _content=new ByteArrayOutputStream(); + return false; + } + + @Override + public boolean earlyEOF() + { + return true; + } + + @Override + public boolean content(ByteBuffer ref) + { + try + { + _content.write(BufferUtil.toArray(ref)); + } + catch (IOException e) + { + throw new RuntimeIOException(e); + } + return false; + } + + @Override + public void badMessage(int status, String reason) + { + throw new RuntimeIOException(reason); + } + + abstract public HttpGenerator.Info getInfo(); + + } + + public static class Request extends Message implements HttpParser.RequestHandler + { + private String _method; + private String _uri; + + @Override + public boolean startRequest(HttpMethod method, String methodString, String uri, HttpVersion version) + { + _method=methodString; + _uri=uri; + _version=version; + return false; + } + + public String getMethod() + { + return _method; + } + + public String getUri() + { + return _uri; + } + + @Override + public HttpGenerator.RequestInfo getInfo() + { + return new HttpGenerator.RequestInfo(_version,this,_content==null?0:_content.size(),_method,_uri); + } + + public String toString() + { + return String.format("%s %s %s\n%s\n",_method,_uri,_version,super.toString()); + } + } + + public static class Response extends Message implements HttpParser.ResponseHandler + { + private int _status; + private String _reason; + + @Override + public boolean startResponse(HttpVersion version, int status, String reason) + { + _version=version; + _status=status; + _reason=reason; + return false; + } + + public int getStatus() + { + return _status; + } + + public String getReason() + { + return _reason; + } + + public byte[] getContentBytes() + { + if (_content==null) + return null; + return _content.toByteArray(); + } + + public String getContent() + { + if (_content==null) + return null; + byte[] bytes=_content.toByteArray(); + + String content_type=get(HttpHeader.CONTENT_TYPE); + String encoding=MimeTypes.getCharsetFromContentType(content_type); + Charset charset=encoding==null?StringUtil.__UTF8_CHARSET:Charset.forName(encoding); + + return new String(bytes,charset); + } + + @Override + public HttpGenerator.ResponseInfo getInfo() + { + return new HttpGenerator.ResponseInfo(_version,this,_content==null?-1:_content.size(),_status,_reason,false); + } + + public String toString() + { + return String.format("%s %s %s\n%s\n",_version,_status,_reason,super.toString()); + } + } +} diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java index 1cb4e4563d1..fde1ea69340 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java @@ -250,6 +250,8 @@ public class MimeTypes /* ------------------------------------------------------------ */ public static String getCharsetFromContentType(String value) { + if (value==null) + return null; int end=value.length(); int state=0; int start=0; diff --git a/jetty-proxy/pom.xml b/jetty-proxy/pom.xml new file mode 100644 index 00000000000..59451bc6228 --- /dev/null +++ b/jetty-proxy/pom.xml @@ -0,0 +1,93 @@ + + + + jetty-project + org.eclipse.jetty + 9.0.0-SNAPSHOT + + 4.0.0 + jetty-proxy + Jetty :: Proxy + Jetty Proxy + + ${project.groupId}.servlets + + + + + org.apache.felix + maven-bundle-plugin + true + + + + manifest + + + + javax.servlet.*;version="2.6.0",* + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.codehaus.mojo + findbugs-maven-plugin + + org.eclipse.jetty.servlets.* + + + + + + + junit + junit + test + + + org.eclipse.jetty.toolchain + jetty-test-helper + test + + + org.eclipse.jetty + jetty-continuation + ${project.version} + + + org.eclipse.jetty + jetty-webapp + ${project.version} + provided + + + org.eclipse.jetty + jetty-client + ${project.version} + + + org.eclipse.jetty + jetty-util + ${project.version} + + + org.eclipse.jetty.orbit + javax.servlet + provided + + + diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java similarity index 99% rename from jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java rename to jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java index 782d16765b1..03cdb85c15f 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/ProxyServlet.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ProxyServlet.java @@ -11,7 +11,7 @@ // You may elect to redistribute this code under either of these licenses. // ======================================================================== -package org.eclipse.jetty.servlets; +package org.eclipse.jetty.proxy; import java.io.IOException; import java.io.InputStream; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncProxyServer.java similarity index 98% rename from jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java rename to jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncProxyServer.java index c30133c1ab2..5c56d63c0a2 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AsyncProxyServer.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncProxyServer.java @@ -11,7 +11,7 @@ // You may elect to redistribute this code under either of these licenses. // ======================================================================== -package org.eclipse.jetty.servlets; +package org.eclipse.jetty.proxy; import java.util.EnumSet; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java similarity index 98% rename from jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java rename to jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java index 68a3b97e49f..208ebe5b1e0 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ProxyServletTest.java @@ -1,4 +1,4 @@ -package org.eclipse.jetty.servlets; +package org.eclipse.jetty.proxy; import java.io.File; import java.io.FileInputStream; @@ -20,6 +20,7 @@ import org.eclipse.jetty.client.HttpExchange; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.io.Buffer; +import org.eclipse.jetty.proxy.ProxyServlet; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.HandlerCollection; diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index cc5fd070c21..7eded4175a1 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -84,7 +84,7 @@ public class ServletContextHandler extends ContextHandler protected JspConfigDescriptor _jspConfig; protected Object _restrictedContextListeners; private boolean _restrictListeners = true; - + /* ------------------------------------------------------------ */ public ServletContextHandler() { diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java new file mode 100644 index 00000000000..43877344434 --- /dev/null +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java @@ -0,0 +1,203 @@ +package org.eclipse.jetty.servlet; + +import java.io.IOException; +import java.net.InetAddress; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.util.EnumSet; +import java.util.Enumeration; +import java.util.Map; + +import javax.servlet.DispatcherType; +import javax.servlet.Filter; +import javax.servlet.Servlet; + +import org.eclipse.jetty.http.HttpFields; +import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpParser; +import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.LocalHttpConnector; +import org.eclipse.jetty.server.SelectChannelConnector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.Attributes; +import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.component.AggregateLifeCycle; +import org.eclipse.jetty.util.resource.Resource; + +public class ServletTester extends AggregateLifeCycle +{ + private final Server _server=new Server(); + private final LocalHttpConnector _connector=new LocalHttpConnector(); + private final ServletContextHandler _context; + public void setVirtualHosts(String[] vhosts) + { + _context.setVirtualHosts(vhosts); + } + + public void addVirtualHosts(String[] virtualHosts) + { + _context.addVirtualHosts(virtualHosts); + } + + public ServletHolder addServlet(String className, String pathSpec) + { + return _context.addServlet(className,pathSpec); + } + + public ServletHolder addServlet(Class servlet, String pathSpec) + { + return _context.addServlet(servlet,pathSpec); + } + + public void addServlet(ServletHolder servlet, String pathSpec) + { + _context.addServlet(servlet,pathSpec); + } + + public void addFilter(FilterHolder holder, String pathSpec, EnumSet dispatches) + { + _context.addFilter(holder,pathSpec,dispatches); + } + + public FilterHolder addFilter(Class filterClass, String pathSpec, EnumSet dispatches) + { + return _context.addFilter(filterClass,pathSpec,dispatches); + } + + public FilterHolder addFilter(String filterClass, String pathSpec, EnumSet dispatches) + { + return _context.addFilter(filterClass,pathSpec,dispatches); + } + + public Object getAttribute(String name) + { + return _context.getAttribute(name); + } + + public Enumeration getAttributeNames() + { + return _context.getAttributeNames(); + } + + public Attributes getAttributes() + { + return _context.getAttributes(); + } + + public String getContextPath() + { + return _context.getContextPath(); + } + + public String getInitParameter(String name) + { + return _context.getInitParameter(name); + } + + public String setInitParameter(String name, String value) + { + return _context.setInitParameter(name,value); + } + + public Enumeration getInitParameterNames() + { + return _context.getInitParameterNames(); + } + + public Map getInitParams() + { + return _context.getInitParams(); + } + + public void removeAttribute(String name) + { + _context.removeAttribute(name); + } + + public void setAttribute(String name, Object value) + { + _context.setAttribute(name,value); + } + + public void setContextPath(String contextPath) + { + _context.setContextPath(contextPath); + } + + public Resource getBaseResource() + { + return _context.getBaseResource(); + } + + public String getResourceBase() + { + return _context.getResourceBase(); + } + + public void setResourceBase(String resourceBase) + { + _context.setResourceBase(resourceBase); + } + + private final ServletHandler _handler; + + public ServletTester() + { + this("/",ServletContextHandler.SECURITY|ServletContextHandler.SESSIONS); + } + + public ServletTester(String ctxPath) + { + this(ctxPath,ServletContextHandler.SECURITY|ServletContextHandler.SESSIONS); + } + + public ServletTester(String contextPath,int options) + { + _context=new ServletContextHandler(_server,contextPath,options); + _handler=_context.getServletHandler(); + _server.setConnectors(new Connector[]{_connector}); + addBean(_server); + } + + public ServletContextHandler getContext() + { + return _context; + } + + public String getResponses(String request) throws Exception + { + return _connector.getResponses(request); + } + + public ByteBuffer getResponses(ByteBuffer request) throws Exception + { + return _connector.getResponses(request); + } + + /* ------------------------------------------------------------ */ + /** Create a port based connector. + * This methods adds a port connector to the server + * @return A URL to access the server via the connector. + * @throws Exception + */ + public String createConnector(boolean localhost) throws Exception + { + SelectChannelConnector connector = new SelectChannelConnector(); + if (localhost) + connector.setHost("127.0.0.1"); + _server.addConnector(connector); + if (_server.isStarted()) + connector.start(); + else + connector.open(); + + return "http://"+(localhost?"127.0.0.1": + InetAddress.getLocalHost().getHostAddress() + )+":"+connector.getLocalPort(); + } + + + +} \ No newline at end of file diff --git a/jetty-servlets/pom.xml b/jetty-servlets/pom.xml index 994ee308c1d..470aba43077 100644 --- a/jetty-servlets/pom.xml +++ b/jetty-servlets/pom.xml @@ -74,11 +74,6 @@ ${project.version} provided - - org.eclipse.jetty - jetty-client - ${project.version} - org.eclipse.jetty jetty-util @@ -89,11 +84,5 @@ javax.servlet provided - - org.eclipse.jetty - test-jetty-servlet - ${project.version} - test - diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CloseableDoSFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CloseableDoSFilter.java index 9b2b659dcff..f742c7f563f 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CloseableDoSFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/CloseableDoSFilter.java @@ -13,15 +13,11 @@ package org.eclipse.jetty.servlets; -import java.io.IOException; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.server.AbstractHttpConnection; +import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; /* ------------------------------------------------------------ */ /** Closeable DoS Filter. @@ -31,18 +27,10 @@ import org.eclipse.jetty.util.log.Logger; public class CloseableDoSFilter extends DoSFilter { - private static final Logger LOG = Log.getLogger(CloseableDoSFilter.class); - + @Override protected void closeConnection(HttpServletRequest request, HttpServletResponse response, Thread thread) { - try - { - Request base_request=(request instanceof Request)?(Request)request:AbstractHttpConnection.getCurrentConnection().getRequest(); - base_request.getConnection().getEndPoint().close(); - } - catch(IOException e) - { - LOG.warn(e); - } + Request base_request=(request instanceof Request)?(Request)request:HttpChannel.getCurrentHttpChannel().getRequest(); + base_request.getHttpChannel().getConnection().getEndPoint().close(); } } diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java index cf2a898ef54..507615d766b 100644 --- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java +++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/GzipFilter.java @@ -32,7 +32,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.continuation.Continuation; import org.eclipse.jetty.continuation.ContinuationListener; import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.http.HttpMethods; +import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.gzip.GzipResponseWrapper; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -108,6 +108,7 @@ public class GzipFilter extends UserAgentFilter /** * @see org.eclipse.jetty.servlets.UserAgentFilter#destroy() */ + @Override public void destroy() { } @@ -116,6 +117,7 @@ public class GzipFilter extends UserAgentFilter /** * @see org.eclipse.jetty.servlets.UserAgentFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain) */ + @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { @@ -124,7 +126,7 @@ public class GzipFilter extends UserAgentFilter String ae = request.getHeader("accept-encoding"); if (ae != null && ae.indexOf("gzip")>=0 && !response.containsHeader("Content-Encoding") - && !HttpMethods.HEAD.equalsIgnoreCase(request.getMethod())) + && !HttpMethod.HEAD.is(request.getMethod())) { if (_excluded!=null) { diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java index c2b09772b7c..c308d226496 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java @@ -16,7 +16,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.testing.ServletTester; +import org.eclipse.jetty.servlet.ServletTester; import org.eclipse.jetty.util.IO; import org.junit.After; import org.junit.AfterClass; @@ -37,15 +37,14 @@ public abstract class AbstractDoSFilterTest public static void startServer(Class filter) throws Exception { - _tester = new ServletTester(); - HttpURI uri = new HttpURI(_tester.createChannelConnector(true)); + _tester = new ServletTester("/ctx"); + HttpURI uri = new HttpURI(_tester.createConnector(true)); _host = uri.getHost(); _port = uri.getPort(); - _tester.setContextPath("/ctx"); - _tester.addServlet(TestServlet.class, "/*"); + _tester.getContext().addServlet(TestServlet.class, "/*"); - _dosFilter = _tester.addFilter(filter, "/dos/*", EnumSet.allOf(DispatcherType.class)); + _dosFilter = _tester.getContext().addFilter(filter, "/dos/*", EnumSet.allOf(DispatcherType.class)); _dosFilter.setInitParameter("maxRequestsPerSec", "4"); _dosFilter.setInitParameter("delayMs", "200"); _dosFilter.setInitParameter("throttledRequests", "1"); @@ -54,7 +53,7 @@ public abstract class AbstractDoSFilterTest _dosFilter.setInitParameter("remotePort", "false"); _dosFilter.setInitParameter("insertHeaders", "true"); - _timeoutFilter = _tester.addFilter(filter, "/timeout/*", EnumSet.allOf(DispatcherType.class)); + _timeoutFilter = _tester.getContext().addFilter(filter, "/timeout/*", EnumSet.allOf(DispatcherType.class)); _timeoutFilter.setInitParameter("maxRequestsPerSec", "4"); _timeoutFilter.setInitParameter("delayMs", "200"); _timeoutFilter.setInitParameter("throttledRequests", "1"); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java index ff78a629ff0..e0b0f15ab16 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/CrossOriginFilterTest.java @@ -12,9 +12,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.servlet.FilterMapping; import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.testing.ServletTester; +import org.eclipse.jetty.servlet.ServletTester; import org.junit.After; import org.junit.Assert; import org.junit.Before; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java index 3ad66eab23f..855f5f8ff29 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/IncludableGzipFilterTest.java @@ -22,15 +22,16 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; +import java.nio.ByteBuffer; import java.util.zip.GZIPInputStream; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.io.ByteArrayBuffer; +import org.eclipse.jetty.http.HttpTester; import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.testing.HttpTester; -import org.eclipse.jetty.testing.ServletTester; +import org.eclipse.jetty.servlet.ServletTester; import org.eclipse.jetty.toolchain.test.TestingDir; +import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.IO; import org.junit.After; import org.junit.Before; @@ -69,11 +70,10 @@ public class IncludableGzipFilterTest IO.copy(testIn,testOut); testOut.close(); - tester=new ServletTester(); - tester.setContextPath("/context"); - tester.setResourceBase(testdir.getDir().getCanonicalPath()); - tester.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); - FilterHolder holder = tester.addFilter(IncludableGzipFilter.class,"/*",null); + tester=new ServletTester("/context"); + tester.getContext().setResourceBase(testdir.getDir().getCanonicalPath()); + tester.getContext().addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); + FilterHolder holder = tester.getContext().addFilter(IncludableGzipFilter.class,"/*",null); holder.setInitParameter("mimeTypes","text/plain"); tester.start(); } @@ -89,22 +89,18 @@ public class IncludableGzipFilterTest public void testGzipFilter() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + + ByteBuffer request=BufferUtil.toBuffer( + "GET /context/file.txt HTTP/1.0\r\n"+ + "Host: tester\r\n"+ + "Accept-Encoding: gzip\r\n"+ + "\r\n"); - request.setMethod("GET"); - request.setVersion("HTTP/1.0"); - request.setHeader("Host","tester"); - request.setHeader("accept-encoding","gzip"); - request.setURI("/context/file.txt"); - ByteArrayBuffer reqsBuff = new ByteArrayBuffer(request.generate().getBytes()); - ByteArrayBuffer respBuff = tester.getResponses(reqsBuff); - response.parse(respBuff.asArray()); - - assertTrue(response.getMethod()==null); - assertTrue(response.getHeader("Content-Encoding").equalsIgnoreCase("gzip")); + HttpTester.Response response=HttpTester.parseResponse(tester.getResponses(request)); + assertEquals(HttpServletResponse.SC_OK,response.getStatus()); + assertEquals("gzip",response.get("Content-Encoding")); InputStream testIn = new GZIPInputStream(new ByteArrayInputStream(response.getContentBytes())); ByteArrayOutputStream testOut = new ByteArrayOutputStream(); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java index 9e197341e6e..de87414af7a 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java @@ -34,8 +34,8 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.FilterMapping; -import org.eclipse.jetty.testing.HttpTester; -import org.eclipse.jetty.testing.ServletTester; +import org.eclipse.jetty.http.HttpTester; +import org.eclipse.jetty.servlet.ServletTester; import org.eclipse.jetty.util.IO; import org.junit.After; import org.junit.Before; @@ -56,12 +56,11 @@ public class MultipartFilterTest _dir.deleteOnExit(); assertTrue(_dir.isDirectory()); - tester=new ServletTester(); - tester.setContextPath("/context"); - tester.setResourceBase(_dir.getCanonicalPath()); - tester.addServlet(DumpServlet.class, "/"); - tester.setAttribute("javax.servlet.context.tempdir", _dir); - FilterHolder multipartFilter = tester.addFilter(MultiPartFilter.class,"/*", EnumSet.of(DispatcherType.REQUEST)); + tester=new ServletTester("/context"); + tester.getContext().setResourceBase(_dir.getCanonicalPath()); + tester.getContext().addServlet(DumpServlet.class, "/"); + tester.getContext().setAttribute("javax.servlet.context.tempdir", _dir); + FilterHolder multipartFilter = tester.getContext().addFilter(MultiPartFilter.class,"/*", EnumSet.of(DispatcherType.REQUEST)); multipartFilter.setInitParameter("deleteFiles", "true"); tester.start(); } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java index 9d59bddc48d..03e1a41849c 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java @@ -30,8 +30,9 @@ import java.util.Set; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.testing.HttpTester; -import org.eclipse.jetty.testing.ServletTester; +import org.eclipse.jetty.http.HttpTester; +import org.eclipse.jetty.servlet.ServletTester; +import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.IO; import org.junit.After; import org.junit.Before; @@ -51,8 +52,7 @@ public class PutFilterTest _dir.deleteOnExit(); assertTrue(_dir.isDirectory()); - tester=new ServletTester(); - tester.setContextPath("/context"); + tester=new ServletTester("/context"); tester.setResourceBase(_dir.getCanonicalPath()); tester.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); FilterHolder holder = tester.addFilter(PutFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST)); @@ -75,15 +75,14 @@ public class PutFilterTest { // generated and parsed test HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Response response; // test GET request.setMethod("GET"); request.setVersion("HTTP/1.0"); request.setHeader("Host","tester"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_NOT_FOUND,response.getStatus()); // test PUT0 @@ -92,8 +91,7 @@ public class PutFilterTest request.setHeader("Content-Type","text/plain"); String data0="Now is the time for all good men to come to the aid of the party"; request.setContent(data0); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_CREATED,response.getStatus()); File file=new File(_dir,"file.txt"); @@ -105,8 +103,7 @@ public class PutFilterTest request.setVersion("HTTP/1.0"); request.setHeader("Host","tester"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); assertEquals(data0,response.getContent()); @@ -116,8 +113,7 @@ public class PutFilterTest request.setHeader("Content-Type","text/plain"); String data1="How Now BROWN COW!!!!"; request.setContent(data1); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); file=new File(_dir,"file.txt"); @@ -130,8 +126,8 @@ public class PutFilterTest request.setHeader("Content-Type","text/plain"); String data2="Blah blah blah Blah blah"; request.setContent(data2); - String to_send = request.generate(); - URL url = new URL(tester.createSocketConnector(true)); + String to_send = BufferUtil.toString(request.generate()); + URL url = new URL(tester.createConnector(true)); Socket socket=new Socket(url.getHost(),url.getPort()); OutputStream out = socket.getOutputStream(); int l = to_send.length(); @@ -153,10 +149,9 @@ public class PutFilterTest request.setVersion("HTTP/1.0"); request.setHeader("Host","tester"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); } while(response.getStatus()==200); - assertTrue(response.getMethod()==null); assertEquals(HttpServletResponse.SC_NOT_FOUND,response.getStatus()); out.write(to_send.substring(l-5).getBytes()); @@ -167,8 +162,7 @@ public class PutFilterTest request.setVersion("HTTP/1.0"); request.setHeader("Host","tester"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); assertEquals(data2,response.getContent()); } @@ -178,7 +172,7 @@ public class PutFilterTest { // generated and parsed test HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Response response; // test PUT1 request.setMethod("PUT"); @@ -188,8 +182,7 @@ public class PutFilterTest request.setHeader("Content-Type","text/plain"); String data1="How Now BROWN COW!!!!"; request.setContent(data1); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_CREATED,response.getStatus()); File file=new File(_dir,"file.txt"); @@ -200,16 +193,14 @@ public class PutFilterTest request.setMethod("DELETE"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_NO_CONTENT,response.getStatus()); assertTrue(!file.exists()); request.setMethod("DELETE"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_FORBIDDEN,response.getStatus()); } @@ -218,7 +209,7 @@ public class PutFilterTest { // generated and parsed test HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Response response; // test PUT1 request.setMethod("PUT"); @@ -228,8 +219,9 @@ public class PutFilterTest request.setHeader("Content-Type","text/plain"); String data1="How Now BROWN COW!!!!"; request.setContent(data1); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + System.err.println(request); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); + assertEquals(HttpServletResponse.SC_CREATED,response.getStatus()); File file=new File(_dir,"file.txt"); @@ -241,8 +233,7 @@ public class PutFilterTest request.setMethod("MOVE"); request.setURI("/context/file.txt"); request.setHeader("new-uri","/context/blah.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_NO_CONTENT,response.getStatus()); assertTrue(!file.exists()); @@ -256,19 +247,18 @@ public class PutFilterTest { // generated and parsed test HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Response response; // test PUT1 request.setMethod("OPTIONS"); request.setVersion("HTTP/1.0"); request.setHeader("Host","tester"); request.setURI("/context/file.txt"); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); Set options = new HashSet(); - options.addAll(Arrays.asList(response.getHeader("Allow").split(" *, *"))); + options.addAll(Arrays.asList(response.get("Allow").split(" *, *"))); assertTrue(options.contains("GET")); assertTrue(options.contains("POST")); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java index 5ce86b6be34..d50015c7d9c 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java @@ -28,11 +28,10 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.FilterMapping; -import org.eclipse.jetty.testing.HttpTester; -import org.eclipse.jetty.testing.ServletTester; +import org.eclipse.jetty.http.HttpTester; +import org.eclipse.jetty.servlet.ServletTester; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.junit.After; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java index d3fce4050fb..17f9d49d1a8 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java @@ -340,6 +340,7 @@ public class WebSocketFrame implements Frame data = ByteBuffer.allocate(len); BufferUtil.clearToFill(data); data.put(buf,0,len); + BufferUtil.flipToFlush(data,0); BufferUtil.flipToFill(data); return this; } diff --git a/pom.xml b/pom.xml index 5586dd0a5e5..41f8e23fc46 100644 --- a/pom.xml +++ b/pom.xml @@ -355,6 +355,7 @@ jetty-deploy jetty-websocket + jetty-servlets test-continuation test-jetty-webapp @@ -362,7 +363,6 @@ 0;) - try{_connectors[i].stop();}catch(Throwable e){mex.add(e);} + { + if (_connectors[i]!=null) + try{_connectors[i].stop();}catch(Throwable e){mex.add(e);} + } } try {super.doStop(); } catch(Throwable e) { mex.add(e);} diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java index 43877344434..4cbe5be0ee2 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletTester.java @@ -197,6 +197,13 @@ public class ServletTester extends AggregateLifeCycle InetAddress.getLocalHost().getHostAddress() )+":"+connector.getLocalPort(); } + + public LocalHttpConnector createLocalConnector() + { + LocalHttpConnector connector = new LocalHttpConnector(); + _server.addConnector(connector); + return connector; + } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java index de87414af7a..5fd6264b58d 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java @@ -75,8 +75,8 @@ public class MultipartFilterTest public void testBadPost() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); + HttpTester.Response response; // test GET request.setMethod("POST"); @@ -97,8 +97,7 @@ public class MultipartFilterTest request.setContent(content); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); } @@ -107,8 +106,8 @@ public class MultipartFilterTest public void testPost() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); + HttpTester.Response response; // test GET request.setMethod("POST"); @@ -128,8 +127,7 @@ public class MultipartFilterTest request.setContent(content); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); assertTrue(response.getContent().indexOf("brown cow")>=0); } @@ -139,8 +137,8 @@ public class MultipartFilterTest public void testEncodedPost() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); + HttpTester.Response response; // test GET request.setMethod("POST"); @@ -160,8 +158,7 @@ public class MultipartFilterTest request.setContent(content); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); assertTrue(response.getContent().indexOf("brown cow")>=0); } @@ -172,8 +169,8 @@ public class MultipartFilterTest @Test public void testPostWithContentTransferEncodingBase64() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); + HttpTester.Response response; // test GET request.setMethod("POST"); @@ -194,8 +191,7 @@ public class MultipartFilterTest request.setContent(content); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); assertTrue(response.getContent().indexOf("brown cow")>=0); } @@ -206,8 +202,8 @@ public class MultipartFilterTest @Test public void testPostWithContentTransferEncodingQuotedPrintable() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); - HttpTester response = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); + HttpTester.Response response; // test GET request.setMethod("POST"); @@ -231,8 +227,7 @@ public class MultipartFilterTest request.setContent(content); - response.parse(tester.getResponses(request.generate())); - assertTrue(response.getMethod()==null); + response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); assertTrue(response.getContent().indexOf("brown cow")>=0); } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java index 03e1a41849c..d784aa7aab0 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/PutFilterTest.java @@ -74,7 +74,7 @@ public class PutFilterTest public void testHandlePut() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); HttpTester.Response response; // test GET @@ -171,7 +171,7 @@ public class PutFilterTest public void testHandleDelete() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); HttpTester.Response response; // test PUT1 @@ -208,7 +208,7 @@ public class PutFilterTest public void testHandleMove() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); HttpTester.Response response; // test PUT1 @@ -246,13 +246,13 @@ public class PutFilterTest public void testHandleOptions() throws Exception { // generated and parsed test - HttpTester request = new HttpTester(); + HttpTester.Request request = HttpTester.newRequest(); HttpTester.Response response; // test PUT1 request.setMethod("OPTIONS"); request.setVersion("HTTP/1.0"); - request.setHeader("Host","tester"); + request.put("Host","tester"); request.setURI("/context/file.txt"); response = HttpTester.parseResponse(tester.getResponses(request.generate())); assertEquals(HttpServletResponse.SC_OK,response.getStatus()); diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java index d50015c7d9c..4fd1c3cd35b 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java @@ -28,10 +28,12 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.server.LocalHttpConnector; import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.FilterMapping; import org.eclipse.jetty.http.HttpTester; import org.eclipse.jetty.servlet.ServletTester; +import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.junit.After; @@ -43,7 +45,7 @@ public class QoSFilterTest private static final Logger LOG = Log.getLogger(QoSFilterTest.class); private ServletTester _tester; - private LocalConnector[] _connectors; + private LocalHttpConnector[] _connectors; private CountDownLatch _doneRequests; private final int NUM_CONNECTIONS = 8; private final int NUM_LOOPS = 6; @@ -58,7 +60,7 @@ public class QoSFilterTest TestServlet.__maxSleepers=0; TestServlet.__sleepers=0; - _connectors = new LocalConnector[NUM_CONNECTIONS]; + _connectors = new LocalHttpConnector[NUM_CONNECTIONS]; for(int i = 0; i < _connectors.length; ++i) _connectors[i] = _tester.createLocalConnector(); @@ -133,7 +135,7 @@ public class QoSFilterTest { for (int i=0;i