Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse McConnell2012-08-23 17:44:30 -0400
committerJesse McConnell2012-08-23 17:44:30 -0400
commitfd1ab0ed55fb0596077c6d34e9afa60487e07beb (patch)
tree44e90ecff091cea66d33911b15f33fae09362096
parent8e9bcf48f2b81a13734e96fad7c7cf5571289f00 (diff)
parent18cd5b455f44c3dee3fd9a0f72c78f475d4ed909 (diff)
downloadorg.eclipse.jetty.project-fd1ab0ed55fb0596077c6d34e9afa60487e07beb.tar.gz
org.eclipse.jetty.project-fd1ab0ed55fb0596077c6d34e9afa60487e07beb.tar.xz
org.eclipse.jetty.project-fd1ab0ed55fb0596077c6d34e9afa60487e07beb.zip
merge from master
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/AsyncHttpConnection.java4
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/MimeTypes.java4
-rw-r--r--jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java21
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java35
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java17
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Response.java36
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java57
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java39
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java14
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java6
-rw-r--r--jetty-server/src/test/resources/jetty-logging.properties3
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java20
-rw-r--r--jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java12
-rw-r--r--jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java27
-rw-r--r--jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java36
15 files changed, 264 insertions, 67 deletions
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/AsyncHttpConnection.java b/jetty-client/src/main/java/org/eclipse/jetty/client/AsyncHttpConnection.java
index b214d0ef0b..1ea6b06721 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/AsyncHttpConnection.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/AsyncHttpConnection.java
@@ -208,12 +208,12 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
{
Connection switched=exchange.onSwitchProtocol(_endp);
if (switched!=null)
- connection=switched;
{
// switched protocol!
- _pipeline = null;
if (_pipeline!=null)
+ {
_destination.send(_pipeline);
+ }
_pipeline = null;
connection=switched;
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 e20dde3cdb..7ec00e2409 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
@@ -364,12 +364,12 @@ public class MimeTypes
case 10:
if (!quote && (';'==b || ' '==b )||
(quote && '"'==b ))
- return CACHE.lookup(value.peek(start,i-start)).toString();
+ return CACHE.lookup(value.peek(start,i-start)).toString(StringUtil.__UTF8);
}
}
if (state==10)
- return CACHE.lookup(value.peek(start,i-start)).toString();
+ return CACHE.lookup(value.peek(start,i-start)).toString(StringUtil.__UTF8);
return (String)__encodings.get(value);
}
diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java
index 6bfae412fb..ccb00a200d 100644
--- a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java
+++ b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/FormAuthenticator.java
@@ -216,19 +216,20 @@ public class FormAuthenticator extends LoginAuthenticator
synchronized(session)
{
nuri = (String) session.getAttribute(__J_URI);
- }
-
- if (nuri == null || nuri.length() == 0)
- {
- nuri = request.getContextPath();
- if (nuri.length() == 0)
- nuri = URIUtil.SLASH;
+
+ if (nuri == null || nuri.length() == 0)
+ {
+ nuri = request.getContextPath();
+ if (nuri.length() == 0)
+ nuri = URIUtil.SLASH;
+ }
+
+ Authentication cached=new SessionAuthentication(getAuthMethod(),user,password);
+ session.setAttribute(SessionAuthentication.__J_AUTHENTICATED, cached);
}
response.setContentLength(0);
response.sendRedirect(response.encodeRedirectURL(nuri));
-
- Authentication cached=new SessionAuthentication(getAuthMethod(),user,password);
- session.setAttribute(SessionAuthentication.__J_AUTHENTICATED, cached);
+
return new FormAuthentication(getAuthMethod(),user);
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java
index 3d305358f5..416ff250e9 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java
@@ -130,6 +130,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
private boolean _head = false;
private boolean _host = false;
private boolean _delayedHandling=false;
+ private boolean _earlyEOF = false;
/* ------------------------------------------------------------ */
public static AbstractHttpConnection getCurrentConnection()
@@ -396,6 +397,12 @@ public abstract class AbstractHttpConnection extends AbstractConnection
}
/* ------------------------------------------------------------ */
+ public boolean isEarlyEOF()
+ {
+ return _earlyEOF;
+ }
+
+ /* ------------------------------------------------------------ */
public void reset()
{
_parser.reset();
@@ -408,6 +415,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
_response.recycle();
_uri.clear();
_writer=null;
+ _earlyEOF = false;
}
/* ------------------------------------------------------------ */
@@ -445,7 +453,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
{
_uri.getPort();
String path = null;
-
+
try
{
path = _uri.getDecodedPath();
@@ -456,7 +464,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
LOG.ignore(e);
path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
}
-
+
info=URIUtil.canonicalPath(path);
if (info==null && !_request.getMethod().equals(HttpMethods.CONNECT))
{
@@ -725,6 +733,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
_requests);
}
+ /* ------------------------------------------------------------ */
protected void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException
{
uri=uri.asImmutableBuffer();
@@ -784,6 +793,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
}
}
+ /* ------------------------------------------------------------ */
protected void parsedHeader(Buffer name, Buffer value) throws IOException
{
int ho = HttpHeaders.CACHE.getOrdinal(name);
@@ -845,6 +855,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
_requestFields.add(name, value);
}
+ /* ------------------------------------------------------------ */
protected void headerComplete() throws IOException
{
_requests++;
@@ -915,6 +926,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
_delayedHandling=true;
}
+ /* ------------------------------------------------------------ */
protected void content(Buffer buffer) throws IOException
{
if (_delayedHandling)
@@ -924,6 +936,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
}
}
+ /* ------------------------------------------------------------ */
public void messageComplete(long contentLength) throws IOException
{
if (_delayedHandling)
@@ -934,6 +947,12 @@ public abstract class AbstractHttpConnection extends AbstractConnection
}
/* ------------------------------------------------------------ */
+ public void earlyEOF()
+ {
+ _earlyEOF = true;
+ }
+
+ /* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
private class RequestHandler extends HttpParser.EventHandler
@@ -1002,6 +1021,18 @@ public abstract class AbstractHttpConnection extends AbstractConnection
if (LOG.isDebugEnabled())
LOG.debug("Bad request!: "+version+" "+status+" "+reason);
}
+
+ /* ------------------------------------------------------------ */
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jetty.server.server.HttpParser.EventHandler#earlyEOF()
+ */
+ @Override
+ public void earlyEOF()
+ {
+ AbstractHttpConnection.this.earlyEOF();
+ }
}
/* ------------------------------------------------------------ */
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java
index af5d510d86..025cf68c8a 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java
@@ -24,12 +24,13 @@ import javax.servlet.ServletInputStream;
import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.io.Buffer;
+import org.eclipse.jetty.io.EofException;
public class HttpInput extends ServletInputStream
{
protected final AbstractHttpConnection _connection;
protected final HttpParser _parser;
-
+
/* ------------------------------------------------------------ */
public HttpInput(AbstractHttpConnection connection)
{
@@ -44,11 +45,9 @@ public class HttpInput extends ServletInputStream
@Override
public int read() throws IOException
{
- int c=-1;
- Buffer content=_parser.blockForContent(_connection.getMaxIdleTime());
- if (content!=null)
- c= 0xff & content.get();
- return c;
+ byte[] bytes = new byte[1];
+ int read = read(bytes, 0, 1);
+ return read < 0 ? -1 : 0xff & bytes[0];
}
/* ------------------------------------------------------------ */
@@ -62,6 +61,8 @@ public class HttpInput extends ServletInputStream
Buffer content=_parser.blockForContent(_connection.getMaxIdleTime());
if (content!=null)
l= content.get(b, off, len);
+ else if (_connection.isEarlyEOF())
+ throw new EofException("early EOF");
return l;
}
@@ -71,8 +72,4 @@ public class HttpInput extends ServletInputStream
{
return _parser.available();
}
-
-
-
-
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
index 063e86e5f9..b8f9ccb9a7 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Response.java
@@ -21,8 +21,9 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
+import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
+import java.util.Enumeration;
import java.util.Locale;
import javax.servlet.ServletOutputStream;
@@ -78,6 +79,16 @@ public class Response implements HttpServletResponse
*/
public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__";
+
+ /* ------------------------------------------------------------ */
+ public static Response getResponse(HttpServletResponse response)
+ {
+ if (response instanceof Response)
+ return (Response)response;
+
+ return AbstractHttpConnection.getCurrentConnection().getResponse();
+ }
+
private final AbstractHttpConnection _connection;
private int _status=SC_OK;
private String _reason;
@@ -1080,6 +1091,29 @@ public class Response implements HttpServletResponse
}
}
+
+ public void reset(boolean preserveCookies)
+ {
+ if (!preserveCookies)
+ reset();
+ else
+ {
+ HttpFields response_fields=_connection.getResponseFields();
+
+ ArrayList<String> cookieValues = new ArrayList<String>(5);
+ Enumeration<String> vals = response_fields.getValues(HttpHeaders.SET_COOKIE);
+ while (vals.hasMoreElements())
+ cookieValues.add((String)vals.nextElement());
+
+ reset();
+
+ for (String v:cookieValues)
+ response_fields.add(HttpHeaders.SET_COOKIE, v);
+ }
+ }
+
+
+
/* ------------------------------------------------------------ */
/*
* @see javax.servlet.ServletResponse#reset()
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
index 9d51233ffa..e902ec014c 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
@@ -30,15 +30,16 @@ import java.net.SocketException;
import java.net.URL;
import java.util.Arrays;
import java.util.Random;
-import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.Exchanger;
+import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.eclipse.jetty.io.EndPoint;
+import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
@@ -50,10 +51,11 @@ import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/**
*
@@ -148,8 +150,55 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
client.close();
}
}
-
+ @Test
+ public void testInterruptedRequest() throws Exception
+ {
+ final AtomicBoolean fourBytesRead = new AtomicBoolean(false);
+ final AtomicBoolean earlyEOFException = new AtomicBoolean(false);
+ configureServer(new AbstractHandler()
+ {
+ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ baseRequest.setHandled(true);
+ int contentLength = request.getContentLength();
+ ServletInputStream inputStream = request.getInputStream();
+ for (int i = 0; i < contentLength; i++)
+ {
+ try
+ {
+ inputStream.read();
+ }
+ catch (EofException e)
+ {
+ earlyEOFException.set(true);
+ throw e;
+ }
+ if (i == 3)
+ fourBytesRead.set(true);
+ }
+ }
+ });
+
+ StringBuffer request = new StringBuffer("GET / HTTP/1.0\n");
+ request.append("Host: localhost\n");
+ request.append("Content-length: 6\n\n");
+ request.append("foo");
+
+ Socket client = newSocket(HOST, _connector.getLocalPort());
+ OutputStream os = client.getOutputStream();
+
+ os.write(request.toString().getBytes());
+ os.flush();
+ client.shutdownOutput();
+ String response = readResponse(client);
+ client.close();
+
+// assertThat("response contains 200 OK", response.contains(" 500 "), is(true)); //TODO: check with gregw,
+// currently returns 200
+ assertThat("The 4th byte (-1) has not been passed to the handler", fourBytesRead.get(), is(false));
+ assertThat("EofException has been caught", earlyEOFException.get(), is(true));
+ }
/*
* Feed the server the entire request at once.
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
index c445597e85..ece7e2e964 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ResponseTest.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -28,6 +29,8 @@ import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Locale;
@@ -558,6 +561,42 @@ public class ResponseTest
assertEquals("name=value;Comment=comment;Path=/path;Domain=domain;Secure;HttpOnly",set);
}
+
+
+ @Test
+ public void testCookiesWithReset() throws Exception
+ {
+ Response response = new Response(new TestHttpConnection(connector,new ByteArrayEndPoint(), connector.getServer()));
+
+ Cookie cookie=new Cookie("name","value");
+ cookie.setDomain("domain");
+ cookie.setPath("/path");
+ cookie.setSecure(true);
+ cookie.setComment("comment__HTTP_ONLY__");
+ response.addCookie(cookie);
+
+ Cookie cookie2=new Cookie("name2", "value2");
+ cookie2.setDomain("domain");
+ cookie2.setPath("/path");
+ response.addCookie(cookie2);
+
+ //keep the cookies
+ response.reset(true);
+
+ Enumeration<String> set = response.getHttpFields().getValues("Set-Cookie");
+
+ assertNotNull(set);
+ ArrayList<String> list = Collections.list(set);
+ assertEquals(2, list.size());
+ assertTrue(list.contains("name=value;Comment=comment;Path=/path;Domain=domain;Secure;HttpOnly"));
+ assertTrue(list.contains("name2=value2;Path=/path;Domain=domain"));
+
+ //get rid of the cookies
+ response.reset();
+
+ set = response.getHttpFields().getValues("Set-Cookie");
+ assertFalse(set.hasMoreElements());
+ }
private Response newResponse()
{
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java
index 840219f66e..096ecca071 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SelectChannelServerSslTest.java
@@ -17,8 +17,6 @@
//
package org.eclipse.jetty.server.ssl;
-import static org.junit.Assert.assertEquals;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -26,13 +24,11 @@ import java.net.Socket;
import java.security.KeyStore;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
-
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManagerFactory;
-
import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.nio.SslConnection;
@@ -41,8 +37,10 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
-import static org.junit.Assert.assertThat;
+
import static org.hamcrest.Matchers.lessThan;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
/**
* HttpServer Tester.
@@ -167,6 +165,12 @@ public class SelectChannelServerSslTest extends HttpServerTestBase
}
@Override
+ @Test
+ @Ignore("Override and ignore this test as SSLSocket.shutdownOutput() is not supported, " +
+ "but shutdownOutput() is needed by the test.")
+ public void testInterruptedRequest(){}
+
+ @Override
@Ignore
public void testAvailable() throws Exception
{
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java
index 4da4106b24..0c53417929 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SslSocketServerTest.java
@@ -77,6 +77,12 @@ public class SslSocketServerTest extends HttpServerTestBase
@Override
@Test
+ @Ignore("Override and ignore this test as SSLSocket.shutdownOutput() is not supported, " +
+ "but shutdownOutput() is needed by the test.")
+ public void testInterruptedRequest(){}
+
+ @Override
+ @Test
public void testFlush() throws Exception
{
// TODO this test uses URL, so noop for now
diff --git a/jetty-server/src/test/resources/jetty-logging.properties b/jetty-server/src/test/resources/jetty-logging.properties
new file mode 100644
index 0000000000..d8439d19ea
--- /dev/null
+++ b/jetty-server/src/test/resources/jetty-logging.properties
@@ -0,0 +1,3 @@
+# Setup default logging implementation for during testing
+org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
+org.eclipse.jetty.server.LEVEL=INFO
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java
index 1f443972b0..c5b91cacc9 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/DefaultServlet.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@@ -674,6 +675,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
String ifms=request.getHeader(HttpHeaders.IF_MODIFIED_SINCE);
if (ifms!=null)
{
+ //Get jetty's Response impl
+ Response r = Response.getResponse(response);
+
if (content!=null)
{
Buffer mdlm=content.getLastModified();
@@ -681,9 +685,9 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
{
if (ifms.equals(mdlm.toString()))
{
- response.reset();
- response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- response.flushBuffer();
+ r.reset(true);
+ r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ r.flushBuffer();
return false;
}
}
@@ -693,10 +697,10 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
if (ifmsl!=-1)
{
if (resource.lastModified()/1000 <= ifmsl/1000)
- {
- response.reset();
- response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- response.flushBuffer();
+ {
+ r.reset(true);
+ r.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ r.flushBuffer();
return false;
}
}
@@ -1025,6 +1029,8 @@ public class DefaultServlet extends HttpServlet implements ResourceFactory
if (_cacheControl!=null)
response.setHeader(HttpHeaders.CACHE_CONTROL,_cacheControl.toString());
}
+
+
/* ------------------------------------------------------------ */
/*
diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
index b92fa35553..7a7c91c728 100644
--- a/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
+++ b/jetty-start/src/main/java/org/eclipse/jetty/start/CommandLineBuilder.java
@@ -41,7 +41,8 @@ public class CommandLineBuilder
*/
public void addArg(String arg)
{
- args.add(quote(arg));
+ if (arg != null)
+ args.add(quote(arg));
}
/**
@@ -84,7 +85,8 @@ public class CommandLineBuilder
*/
public void addRawArg(String arg)
{
- args.add(arg);
+ if (arg != null)
+ args.add(arg);
}
public List<String> getArgs()
@@ -106,7 +108,7 @@ public class CommandLineBuilder
return arg;
}
StringBuilder buf = new StringBuilder();
-// buf.append('"');
+ // buf.append('"');
boolean escaped = false;
for (char c : arg.toCharArray())
{
@@ -117,7 +119,7 @@ public class CommandLineBuilder
escaped = (c == '\\');
buf.append(c);
}
-// buf.append('"');
+ // buf.append('"');
return buf.toString();
}
@@ -133,7 +135,7 @@ public class CommandLineBuilder
{
buf.append(' ');
}
- buf.append(arg);
+ buf.append(quote(arg));
delim = true;
}
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
index ae33b07536..fd4b280014 100644
--- a/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/CommandLineBuilderTest.java
@@ -18,22 +18,29 @@
package org.eclipse.jetty.start;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.is;
+
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
public class CommandLineBuilderTest
{
- @Test
- public void testSimpleCommandline()
+ private CommandLineBuilder cmd = new CommandLineBuilder("java");
+
+ @Before
+ public void setUp()
{
- CommandLineBuilder cmd = new CommandLineBuilder("java");
cmd.addEqualsArg("-Djava.io.tmpdir","/home/java/temp dir/");
cmd.addArg("--version");
-
- Assert.assertThat(cmd.toString(), is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
}
-
+
+ @Test
+ public void testSimpleCommandline()
+ {
+ Assert.assertThat(cmd.toString(),is("java -Djava.io.tmpdir=/home/java/temp\\ dir/ --version"));
+ }
+
@Test
public void testQuotingSimple()
{
@@ -52,6 +59,12 @@ public class CommandLineBuilderTest
assertQuoting("/opt/jetty 7 \"special\"/home","/opt/jetty\\ 7\\ \\\"special\\\"/home");
}
+ @Test
+ public void testToStringIsQuotedEvenIfArgsAreNotQuotedForProcessBuilder()
+ {
+ System.out.println(cmd.toString());
+ }
+
private void assertQuoting(String raw, String expected)
{
String actual = CommandLineBuilder.quote(raw);
diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java
index 68989ffeed..a713f7f60a 100644
--- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java
+++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java
@@ -18,10 +18,6 @@
package org.eclipse.jetty.start;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertEquals;
-
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -30,10 +26,16 @@ import java.util.List;
import java.util.Vector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
/* ------------------------------------------------------------ */
/**
*/
@@ -101,14 +103,24 @@ public class MainTest
Classpath classpath = nastyWayToCreateAClasspathObject("/jetty/home with spaces/");
CommandLineBuilder cmd = main.buildCommandLine(classpath,xmls);
- Assert.assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue());
- String commandLine = cmd.toString();
- Assert.assertThat("CommandLine shouldn't be null",commandLine,notNullValue());
- Assert.assertThat("Classpath should be correctly quoted and match expected value",commandLine,
- containsString("-cp /jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar"));
- Assert.assertThat("CommandLine should contain jvmArgs",commandLine,containsString("--exec -Xms1024m -Xmx1024m"));
- Assert.assertThat("CommandLine should contain xmls",commandLine,containsString("jetty.xml jetty-jmx.xml jetty-logging.xml"));
+ assertThat("CommandLineBuilder shouldn't be null",cmd,notNullValue());
+
+ List<String> commandArgs = cmd.getArgs();
+ assertThat("commandArgs should contain 11 elements",commandArgs.size(),equalTo(11));
+ assertThat("args does not contain -cp",commandArgs,hasItems("-cp"));
+ assertThat("Classpath should be correctly quoted and match expected value",commandArgs,
+ hasItems("/jetty/home with spaces/somejar.jar:/jetty/home with spaces/someotherjar.jar"));
+ assertThat("args does not contain --exec",commandArgs,hasItems("--exec"));
+ assertThat("CommandLine should contain jvmArgs",commandArgs,hasItems("-Xms1024m"));
+ assertThat("CommandLine should contain jvmArgs", commandArgs, hasItems("-Xmx1024m"));
+ assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty.xml"));
+ assertThat("CommandLine should contain xmls",commandArgs,hasItems("jetty-jmx.xml"));
+ assertThat("CommandLine should contain xmls", commandArgs, hasItems("jetty-logging.xml"));
+ String commandLine = cmd.toString();
+ assertThat("cmd.toString() should be properly escaped",commandLine,containsString("-cp /jetty/home\\ with\\ " +
+ "spaces/somejar.jar:/jetty/home\\ with\\ spaces/someotherjar.jar"));
+ assertThat("cmd.toString() doesn't contain xml config files",commandLine,containsString(" jetty.xml jetty-jmx.xml jetty-logging.xml"));
}
private Classpath nastyWayToCreateAClasspathObject(String jettyHome) throws NoSuchFieldException, IllegalAccessException

Back to the top