Merge branch 'jetty-9.2.x' into cdi-testing

This commit is contained in:
Joakim Erdfelt 2014-10-09 12:42:14 -07:00
commit 67db9e67de
15 changed files with 751 additions and 33 deletions

View File

@ -444,7 +444,7 @@ case "$ACTION" in
exit 1
fi
if [ "$JETTY_USER" ]
if [ -n "$JETTY_USER" ]
then
unset SU_SHELL
if [ "$JETTY_SHELL" ]

View File

@ -98,7 +98,7 @@ public class HttpSpiContextHandler extends ContextHandler
ex.printStackTrace(writer);
writer.println("</pre>");
writer.println("<p><i><small><a href=\"http://jetty.mortbay.org\">Powered by jetty://</a></small></i></p>");
writer.println("<p><i><small><a href=\"http://eclipse.org/jetty\">Powered by jetty://</a></small></i></p>");
writer.close();
}

View File

@ -30,10 +30,12 @@ import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
@ -137,6 +139,14 @@ public class JettyRunForkedMojo extends JettyRunMojo
* @parameter default-value="50"
*/
private int maxStartupLines;
/**
* Extra environment variables to be passed to the forked process
*
* @parameter
*/
private Map<String,String> env = new HashMap<String,String>();
/**
* The forked jetty instance
@ -344,7 +354,13 @@ public class JettyRunForkedMojo extends JettyRunMojo
PluginLog.getLog().debug(Arrays.toString(cmd.toArray()));
PluginLog.getLog().info("Forked process starting");
//set up extra environment vars if there are any
if (!env.isEmpty())
{
builder.environment().putAll(env);
}
if (waitForChild)
{
forkedProcess = builder.start();

View File

@ -188,8 +188,10 @@ public class ProxyServlet extends HttpServlet
{
String servletName = getServletConfig().getServletName();
servletName = servletName.replace('-', '.');
if (!servletName.startsWith(getClass().getPackage().getName()))
if ((getClass().getPackage() != null) && !servletName.startsWith(getClass().getPackage().getName()))
{
servletName = getClass().getName() + "." + servletName;
}
return Log.getLogger(servletName);
}

View File

@ -590,8 +590,11 @@ public class RequestTest
@Override
public boolean check(HttpServletRequest request,HttpServletResponse response) throws IOException
{
request.setCharacterEncoding(StringUtil.__ISO_8859_1);
return "test\u00e4".equals(request.getParameter("name2"));
// Should be "testä"
// "test" followed by a LATIN SMALL LETTER A WITH DIAERESIS
request.setCharacterEncoding(StandardCharsets.ISO_8859_1.name());
String actual = request.getParameter("name2");
return "test\u00e4".equals(actual);
}
};
@ -604,7 +607,8 @@ public class RequestTest
"Connection: close\r\n"+
"\r\n"+
content;
_connector.getResponses(request);
String response = _connector.getResponses(request);
assertThat(response,Matchers.containsString(" 200 OK"));
}
@Test
@ -615,11 +619,15 @@ public class RequestTest
@Override
public boolean check(HttpServletRequest request,HttpServletResponse response) throws IOException
{
return "test\u00e4".equals(request.getParameter("name2"));
// http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=00e4&mode=hex
// Should be "testä"
// "test" followed by a LATIN SMALL LETTER A WITH DIAERESIS
String actual = request.getParameter("name2");
return "test\u00e4".equals(actual);
}
};
String content="name1=test&name2=test%C4%A4&name3=&name4=test";
String content="name1=test&name2=test%C3%A4&name3=&name4=test";
String request="POST / HTTP/1.1\r\n"+
"Host: whatever\r\n"+
"Content-Type: "+MimeTypes.Type.FORM_ENCODED.asString()+"\r\n" +
@ -627,7 +635,8 @@ public class RequestTest
"Connection: close\r\n"+
"\r\n"+
content;
_connector.getResponses(request);
String response = _connector.getResponses(request);
assertThat(response,Matchers.containsString(" 200 OK"));
}
@ -748,6 +757,8 @@ public class RequestTest
"Host: myhost\n"+
"Connection: close\n"+
"\n");
assertThat(response,Matchers.containsString(" 302 Found"));
assertThat(response,Matchers.containsString("Location: http://myhost/foo"));
}
@Test
@ -1213,6 +1224,7 @@ public class RequestTest
private class RequestHandler extends AbstractHandler
{
private RequestTester _checker;
@SuppressWarnings("unused")
private String _content;
@Override

View File

@ -0,0 +1,193 @@
//
// ========================================================================
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.handler;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
/**
* Testing oddball request scenarios (like error 400) where the error should
* be logged
*/
@RunWith(Parameterized.class)
@Ignore
public class BadRequestLogHandlerTest
{
private static final Logger LOG = Log.getLogger(BadRequestLogHandlerTest.class);
public static class CaptureLog extends AbstractLifeCycle implements RequestLog
{
public List<String> captured = new ArrayList<>();
@Override
public void log(Request request, Response response)
{
captured.add(String.format("%s %s %s %03d",request.getMethod(),request.getUri().toString(),request.getProtocol(),response.getStatus()));
}
}
private static class HelloHandler extends AbstractHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/plain");
response.getWriter().print("Hello World");
baseRequest.setHandled(true);
}
}
@Parameters
public static List<Object[]> data()
{
List<Object[]> data = new ArrayList<>();
data.add(new String[]{ "GET /bad VER\r\n"
+ "Host: localhost\r\n"
+ "Connection: close\r\n\r\n" ,
"GET <invalidrequest> HTTP/1.1 400" });
data.add(new String[]{ "GET /%%adsasd HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Connection: close\r\n\r\n" ,
"GET <invalidrequest> HTTP/1.1 400" });
return data;
}
@Parameter(0)
public String requestHeader;
@Parameter(1)
public String expectedLog;
@Test(timeout=4000)
public void testLogHandler() throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
CaptureLog captureLog = new CaptureLog();
RequestLogHandler requestLog = new RequestLogHandler();
requestLog.setRequestLog(captureLog);
requestLog.setHandler(new HelloHandler());
server.setHandler(requestLog);
try
{
server.start();
String host = connector.getHost();
if (host == null)
{
host = "localhost";
}
InetAddress destAddr = InetAddress.getByName(host);
int port = connector.getLocalPort();
SocketAddress endpoint = new InetSocketAddress(destAddr,port);
Socket socket = new Socket();
socket.setSoTimeout(1000);
socket.connect(endpoint);
try(OutputStream out = socket.getOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out,StandardCharsets.UTF_8);
InputStream in = socket.getInputStream();
InputStreamReader reader = new InputStreamReader(in,StandardCharsets.UTF_8))
{
StringReader request = new StringReader(requestHeader);
IO.copy(request,writer);
writer.flush();
StringWriter response = new StringWriter();
IO.copy(reader,response);
LOG.info("Response: {}",response);
} finally {
socket.close();
}
assertRequestLog(captureLog);
}
finally
{
server.stop();
}
}
private void assertRequestLog(CaptureLog captureLog)
{
int captureCount = captureLog.captured.size();
if (captureCount != 1)
{
LOG.warn("Capture Log size is {}, expected to be 1",captureCount);
if (captureCount > 1)
{
for (int i = 0; i < captureCount; i++)
{
LOG.warn("[{}] {}",i,captureLog.captured.get(i));
}
}
assertThat("Capture Log Entry Count",captureLog.captured.size(),is(1));
}
String actual = captureLog.captured.get(0);
assertThat("Capture Log",actual,is(expectedLog));
}
}

View File

@ -0,0 +1,447 @@
//
// ========================================================================
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.handler;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class RequestLogHandlerTest
{
private static final Logger LOG = Log.getLogger(RequestLogHandlerTest.class);
public static class CaptureLog extends AbstractLifeCycle implements RequestLog
{
public List<String> captured = new ArrayList<>();
@Override
public void log(Request request, Response response)
{
captured.add(String.format("%s %s %s %03d",request.getMethod(),request.getUri().toString(),request.getProtocol(),response.getStatus()));
}
}
private static abstract class AbstractTestHandler extends AbstractHandler
{
@Override
public String toString()
{
return this.getClass().getSimpleName();
}
}
private static class HelloHandler extends AbstractTestHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/plain");
response.getWriter().print("Hello World");
baseRequest.setHandled(true);
}
}
private static class ResponseSendErrorHandler extends AbstractTestHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.sendError(500, "Whoops");
baseRequest.setHandled(true);
}
}
private static class ServletExceptionHandler extends AbstractTestHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
throw new ServletException("Whoops");
}
}
private static class IOExceptionHandler extends AbstractTestHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
throw new IOException("Whoops");
}
}
private static class RuntimeExceptionHandler extends AbstractTestHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
throw new RuntimeException("Whoops");
}
}
private static class AsyncOnTimeoutCompleteHandler extends AbstractTestHandler implements AsyncListener
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
AsyncContext ac = request.startAsync();
ac.setTimeout(1000);
ac.addListener(this);
baseRequest.setHandled(true);
}
@Override
public void onTimeout(AsyncEvent event) throws IOException
{
event.getAsyncContext().complete();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException
{
}
@Override
public void onError(AsyncEvent event) throws IOException
{
}
@Override
public void onComplete(AsyncEvent event) throws IOException
{
}
}
private static class AsyncOnTimeoutCompleteUnhandledHandler extends AbstractTestHandler implements AsyncListener
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
AsyncContext ac = request.startAsync();
ac.setTimeout(1000);
ac.addListener(this);
}
@Override
public void onTimeout(AsyncEvent event) throws IOException
{
event.getAsyncContext().complete();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException
{
}
@Override
public void onError(AsyncEvent event) throws IOException
{
}
@Override
public void onComplete(AsyncEvent event) throws IOException
{
}
}
private static class AsyncOnTimeoutDispatchHandler extends AbstractTestHandler implements AsyncListener
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if(request.getAttribute("deep") == null)
{
AsyncContext ac = request.startAsync();
ac.setTimeout(1000);
ac.addListener(this);
baseRequest.setHandled(true);
request.setAttribute("deep",true);
}
}
@Override
public void onTimeout(AsyncEvent event) throws IOException
{
event.getAsyncContext().dispatch();
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException
{
}
@Override
public void onError(AsyncEvent event) throws IOException
{
}
@Override
public void onComplete(AsyncEvent event) throws IOException
{
}
}
private static class AsyncOnStartIOExceptionHandler extends AbstractTestHandler implements AsyncListener
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
AsyncContext ac = request.startAsync();
ac.setTimeout(1000);
ac.addListener(this);
baseRequest.setHandled(true);
}
@Override
public void onTimeout(AsyncEvent event) throws IOException
{
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException
{
event.getAsyncContext().complete();
throw new IOException("Whoops");
}
@Override
public void onError(AsyncEvent event) throws IOException
{
LOG.warn("onError() -> {}",event);
}
@Override
public void onComplete(AsyncEvent event) throws IOException
{
}
}
@Parameters(name="{0}")
public static List<Object[]> data()
{
List<Object[]> data = new ArrayList<>();
data.add(new Object[] { new HelloHandler(), "/test", "GET /test HTTP/1.1 200" });
data.add(new Object[] { new AsyncOnTimeoutCompleteHandler(), "/test", "GET /test HTTP/1.1 200" });
data.add(new Object[] { new AsyncOnTimeoutCompleteUnhandledHandler(), "/test", "GET /test HTTP/1.1 200" });
data.add(new Object[] { new AsyncOnTimeoutDispatchHandler(), "/test", "GET /test HTTP/1.1 200" });
data.add(new Object[] { new AsyncOnStartIOExceptionHandler(), "/test", "GET /test HTTP/1.1 500" });
data.add(new Object[] { new ResponseSendErrorHandler(), "/test", "GET /test HTTP/1.1 500" });
data.add(new Object[] { new ServletExceptionHandler(), "/test", "GET /test HTTP/1.1 500" });
data.add(new Object[] { new IOExceptionHandler(), "/test", "GET /test HTTP/1.1 500" });
data.add(new Object[] { new RuntimeExceptionHandler(), "/test", "GET /test HTTP/1.1 500" });
return data;
}
@Parameter(0)
public Handler testHandler;
@Parameter(1)
public String requestPath;
@Parameter(2)
public String expectedLogEntry;
@Test(timeout=4000)
@Ignore
public void testLogHandlerCollection() throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
CaptureLog captureLog = new CaptureLog();
RequestLogHandler requestLog = new RequestLogHandler();
requestLog.setRequestLog(captureLog);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { testHandler, requestLog });
server.setHandler(handlers);
try
{
server.start();
String host = connector.getHost();
if (host == null)
{
host = "localhost";
}
int port = connector.getLocalPort();
URI serverUri = new URI("http",null,host,port,requestPath,null,null);
// Make call to test handler
HttpURLConnection connection = (HttpURLConnection)serverUri.toURL().openConnection();
try
{
connection.setAllowUserInteraction(false);
// log response status code
int statusCode = connection.getResponseCode();
LOG.debug("Response Status Code: {}",statusCode);
if (statusCode == 200)
{
// collect response message and log it
String content = getResponseContent(connection);
LOG.debug("Response Content: {}",content);
}
}
finally
{
connection.disconnect();
}
assertRequestLog(captureLog);
}
finally
{
server.stop();
}
}
@Test(timeout=4000)
public void testLogHandlerWrapped() throws Exception
{
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
CaptureLog captureLog = new CaptureLog();
RequestLogHandler requestLog = new RequestLogHandler();
requestLog.setRequestLog(captureLog);
requestLog.setHandler(testHandler);
server.setHandler(requestLog);
try
{
server.start();
String host = connector.getHost();
if (host == null)
{
host = "localhost";
}
int port = connector.getLocalPort();
URI serverUri = new URI("http",null,host,port,"/test",null,null);
// Make call to test handler
HttpURLConnection connection = (HttpURLConnection)serverUri.toURL().openConnection();
try
{
connection.setAllowUserInteraction(false);
// log response status code
int statusCode = connection.getResponseCode();
LOG.info("Response Status Code: {}",statusCode);
if (statusCode == 200)
{
// collect response message and log it
String content = getResponseContent(connection);
LOG.info("Response Content: {}",content);
}
}
finally
{
connection.disconnect();
}
assertRequestLog(captureLog);
}
finally
{
server.stop();
}
}
private void assertRequestLog(CaptureLog captureLog)
{
int captureCount = captureLog.captured.size();
if (captureCount != 1)
{
LOG.warn("Capture Log size is {}, expected to be 1",captureCount);
if (captureCount > 1)
{
for (int i = 0; i < captureCount; i++)
{
LOG.warn("[{}] {}",i,captureLog.captured.get(i));
}
}
assertThat("Capture Log Entry Count",captureLog.captured.size(),is(1));
}
String actual = captureLog.captured.get(0);
assertThat("Capture Log",actual,is(expectedLogEntry));
}
private String getResponseContent(HttpURLConnection connection) throws IOException
{
try (InputStream in = connection.getInputStream(); InputStreamReader reader = new InputStreamReader(in))
{
StringWriter writer = new StringWriter();
IO.copy(reader,writer);
return writer.toString();
}
}
}

View File

@ -76,8 +76,8 @@ public class SecuredRedirectHandlerTest
server = new Server();
int port = 12080;
int securePort = 12443;
int port = 32080;
int securePort = 32443;
// Setup HTTP Configuration
HttpConfiguration httpConf = new HttpConfiguration();

View File

@ -35,6 +35,8 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -68,7 +70,7 @@ import org.eclipse.jetty.util.log.Logger;
* minutes</li>
* <li><b>allowCredentials</b>, a boolean indicating if the resource allows
* requests with credentials. Default value is <b>false</b></li>
* <li><b>exposeHeaders</b>, a comma separated list of HTTP headers that
* <li><b>exposedHeaders</b>, a comma separated list of HTTP headers that
* are allowed to be exposed on the client. Default value is the
* <b>empty list</b></li>
* <li><b>chainPreflight</b>, if true preflight requests are chained to their
@ -339,6 +341,9 @@ public class CrossOriginFilter implements Filter
private void handleSimpleResponse(HttpServletRequest request, HttpServletResponse response, String origin)
{
response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, origin);
//W3C CORS spec http://www.w3.org/TR/cors/#resource-implementation
if (!anyOriginAllowed)
response.addHeader("Vary", ORIGIN_HEADER);
if (allowCredentials)
response.setHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER, "true");
if (!exposedHeaders.isEmpty())
@ -354,6 +359,9 @@ public class CrossOriginFilter implements Filter
if (!headersAllowed)
return;
response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, origin);
//W3C CORS spec http://www.w3.org/TR/cors/#resource-implementation
if (!anyOriginAllowed)
response.addHeader("Vary", ORIGIN_HEADER);
if (allowCredentials)
response.setHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER, "true");
if (preflightMaxAge > 0)

View File

@ -60,25 +60,35 @@ import org.eclipse.jetty.util.log.Logger;
/**
* Multipart Form Data Filter.
* <p>
* This class decodes the multipart/form-data stream sent by a HTML form that uses a file input
* This class decodes the <code>multipart/form-data</code> stream sent by a HTML form that uses a file input
* item. Any files sent are stored to a temporary file and a File object added to the request
* as an attribute. All other values are made available via the normal getParameter API and
* the setCharacterEncoding mechanism is respected when converting bytes to Strings.
* <p>
* If the init parameter "delete" is set to "true", any files created will be deleted when the
* current request returns.
* <p>
* The init parameter maxFormKeys sets the maximum number of keys that may be present in a
* form (default set by system property org.eclipse.jetty.server.Request.maxFormKeys or 1000) to protect
* Init Parameters:
* <dl>
* <dt>delete</dt>
* <dd>(boolean)
* If set to "true", any files created will be deleted when the current request returns.</dd>
* <dt>maxFormKeys</dt>
* <dd>(number)
* Sets the maximum number of keys that may be present in a
* form (default set by system property <code>org.eclipse.jetty.server.Request.maxFormKeys</code> or 1000) to protect
* against DOS attacks by bad hash keys.
* <p>
* The init parameter deleteFiles controls if uploaded files are automatically deleted after the request
* completes.
*
* Use init parameter "maxFileSize" to set the max size file that can be uploaded.
*
* Use init parameter "maxRequestSize" to limit the size of the multipart request.
*
* </dd>
* <dt>deleteFiles</dt>
* <dd>(boolean)
* Controls if uploaded files are automatically deleted after the request completes.
* </dd>
* <dt>maxFileSize</dt>
* <dd>(size in bytes)
* Set the max size file that can be uploaded.
* </dd>
* <dt>maxRequestSize</dt>
* <dd>(size in bytes)
* To limit the size of the multipart request.
* </dd>
* </dl>
*/
public class MultiPartFilter implements Filter
{

View File

@ -97,6 +97,30 @@ public class CrossOriginFilterTest
Assert.assertFalse(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}
@Test
public void testSimpleRequestWithWildcardOrigin() throws Exception
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
tester.getContext().addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
CountDownLatch latch = new CountDownLatch(1);
tester.getContext().addServlet(new ServletHolder(new ResourceServlet(latch)), "/*");
String origin = "http://foo.example.com";
String request = "" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Connection: close\r\n" +
"Origin: "+origin+"\r\n" +
"\r\n";
String response = tester.getResponses(request);
Assert.assertTrue(response.contains("HTTP/1.1 200"));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(!response.contains("Vary"));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}
@Test
public void testSimpleRequestWithMatchingWildcardOrigin() throws Exception
@ -119,6 +143,7 @@ public class CrossOriginFilterTest
Assert.assertTrue(response.contains("HTTP/1.1 200"));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(response.contains("Vary"));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}
@ -143,6 +168,7 @@ public class CrossOriginFilterTest
Assert.assertTrue(response.contains("HTTP/1.1 200"));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(response.contains("Vary"));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}
@ -167,6 +193,7 @@ public class CrossOriginFilterTest
Assert.assertTrue(response.contains("HTTP/1.1 200"));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(response.contains("Vary"));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}
@ -193,6 +220,7 @@ public class CrossOriginFilterTest
Assert.assertTrue(response.contains("HTTP/1.1 200"));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER));
Assert.assertTrue(response.contains(CrossOriginFilter.ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER));
Assert.assertTrue(response.contains("Vary"));
Assert.assertTrue(latch.await(1, TimeUnit.SECONDS));
}

View File

@ -811,7 +811,7 @@ public class Main
if (args.getProperties().getString("STOP.WAIT") != null)
{
int stopWait = Integer.parseInt(args.getProperties().getString("STOP.PORT"));
int stopWait = Integer.parseInt(args.getProperties().getString("STOP.WAIT"));
stop(stopPort,stopKey,stopWait);
}

View File

@ -43,8 +43,10 @@ public class StringUtil
public static final String ALL_INTERFACES="0.0.0.0";
public static final String CRLF="\015\012";
public static final String __LINE_SEPARATOR=
System.getProperty("line.separator","\n");
/** @deprecated use {@link System#lineSeparator()} instead */
@Deprecated
public static final String __LINE_SEPARATOR = System.lineSeparator();
public static final String __ISO_8859_1="ISO-8859-1";
public final static String __UTF8="UTF-8";

View File

@ -43,8 +43,8 @@
</goals>
<configuration>
<instructions>
<Export-Package>${bundle-symbolic-name}.*;version="9.1"</Export-Package>
<Import-Package>javax.servlet.*;version="[3.0,4.0)",org.eclipse.jetty.*;version="[9.0,10.0)",*</Import-Package>
<Export-Package>${bundle-symbolic-name}.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}"</Export-Package>
<Import-Package>javax.servlet.*;version="[3.1,4.0)",org.eclipse.jetty.*;version="[9.0,10.0)",*</Import-Package>
<_nouses>true</_nouses>
</instructions>
</configuration>

View File

@ -41,7 +41,7 @@
<Bundle-Description>Websocket Servlet Interface</Bundle-Description>
<Bundle-Classpath />
<_nouses>true</_nouses>
<DynamicImport-Package>org.eclipse.jetty.websocket.server.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}"</DynamicImport-Package>
<DynamicImport-Package>org.eclipse.jetty.websocket.server.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}",org.eclipse.jetty.websocket.server.pathmap.*;version="${parsedVersion.majorVersion}.${parsedVersion.minorVersion}"</DynamicImport-Package>
</instructions>
</configuration>
</plugin>