Merge branch 'master' of ssh://git.eclipse.org:29418/jetty/org.eclipse.jetty.project

This commit is contained in:
Thomas Becker 2012-07-26 13:10:32 +02:00
commit 2de6fa5c35
3 changed files with 69 additions and 12 deletions

View File

@ -14,6 +14,9 @@
package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -464,11 +467,12 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
// Handle configuring servlets that implement org.apache.jasper.servlet.JspServlet
if (isJspServlet())
{
initJspServlet();
}
_servlet.init(_config);
if (isJspServlet())
postInitJspServlet();
}
catch (UnavailableException e)
{
@ -524,6 +528,51 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
}
}
protected void postInitJspServlet() throws Exception
{
try
{
//Check that jasper's SystemLogHandler class is on the classpath
Class systemLogHandlerClass = Loader.loadClass(this.getClass(), "org.apache.jasper.util.SystemLogHandler");
PrintStream rootSystemLogHandler = null;
while (systemLogHandlerClass.isAssignableFrom(System.err.getClass()))
{
rootSystemLogHandler = System.err;
Method getWrapped = systemLogHandlerClass.getMethod("getWrapped", new Class[]{});
PrintStream ps = (PrintStream)getWrapped.invoke(System.err, new Object[]{});
System.setErr(ps);
}
if (rootSystemLogHandler != null)
System.setErr(rootSystemLogHandler);
}
catch (ClassNotFoundException e)
{
//jasper not on classpath, ignore
}
catch (NoSuchMethodException e)
{
LOG.info("Problem unwrapping SystemLogHandler from System.err", e);
}
catch (SecurityException e)
{
LOG.warn("Problem unwrapping SystemLogHandler from System.err", e);
}
catch (IllegalAccessException e)
{
LOG.warn("Problem unwrapping SystemLogHandler from System.err", e);
}
catch (IllegalArgumentException e)
{
LOG.warn("Problem unwrapping SystemLogHandler from System.err", e);
}
catch (InvocationTargetException e)
{
LOG.warn("Problem unwrapping SystemLogHandler from System.err", e);
}
}
/* ------------------------------------------------------------ */
/**

View File

@ -66,6 +66,9 @@ import org.eclipse.jetty.util.log.Logger;
* <li><b>exposeHeaders</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
* target resource for normal handling (as an OPTION request). Otherwise the
* filter will response to the preflight. Default is true.</li>
* </ul></p>
* <p>A typical configuration could be:
* <pre>
@ -105,7 +108,8 @@ public class CrossOriginFilter implements Filter
public static final String PREFLIGHT_MAX_AGE_PARAM = "preflightMaxAge";
public static final String ALLOW_CREDENTIALS_PARAM = "allowCredentials";
public static final String EXPOSED_HEADERS_PARAM = "exposedHeaders";
public static final String FORWARD_PREFLIGHT_PARAM = "forwardPreflight";
public static final String OLD_CHAIN_PREFLIGHT_PARAM = "forwardPreflight";
public static final String CHAIN_PREFLIGHT_PARAM = "chainPreflight";
private static final String ANY_ORIGIN = "*";
private static final List<String> SIMPLE_HTTP_METHODS = Arrays.asList("GET", "POST", "HEAD");
@ -116,7 +120,7 @@ public class CrossOriginFilter implements Filter
private List<String> exposedHeaders = new ArrayList<String>();
private int preflightMaxAge;
private boolean allowCredentials;
private boolean forwardPreflight;
private boolean chainPreflight;
public void init(FilterConfig config) throws ServletException
{
@ -174,10 +178,14 @@ public class CrossOriginFilter implements Filter
exposedHeadersConfig = "";
exposedHeaders.addAll(Arrays.asList(exposedHeadersConfig.split(",")));
String forwardPreflightConfig = config.getInitParameter(FORWARD_PREFLIGHT_PARAM);
if (forwardPreflightConfig == null)
forwardPreflightConfig = "true";
forwardPreflight = Boolean.parseBoolean(forwardPreflightConfig);
String chainPreflightConfig = config.getInitParameter(OLD_CHAIN_PREFLIGHT_PARAM);
if (chainPreflightConfig!=null) // TODO remove this
LOG.warn("DEPRECATED CONFIGURATION: Use "+CHAIN_PREFLIGHT_PARAM+ " instead of "+OLD_CHAIN_PREFLIGHT_PARAM);
else
chainPreflightConfig = config.getInitParameter(CHAIN_PREFLIGHT_PARAM);
if (chainPreflightConfig == null)
chainPreflightConfig = "true";
chainPreflight = Boolean.parseBoolean(chainPreflightConfig);
if (LOG.isDebugEnabled())
{
@ -188,7 +196,7 @@ public class CrossOriginFilter implements Filter
PREFLIGHT_MAX_AGE_PARAM + " = " + preflightMaxAgeConfig + ", " +
ALLOW_CREDENTIALS_PARAM + " = " + allowedCredentialsConfig + "," +
EXPOSED_HEADERS_PARAM + " = " + exposedHeadersConfig + "," +
FORWARD_PREFLIGHT_PARAM + " = " + forwardPreflightConfig
CHAIN_PREFLIGHT_PARAM + " = " + chainPreflightConfig
);
}
}
@ -215,7 +223,7 @@ public class CrossOriginFilter implements Filter
{
LOG.debug("Cross-origin request to {} is a preflight cross-origin request", request.getRequestURI());
handlePreflightResponse(request, response, origin);
if (forwardPreflight)
if (chainPreflight)
LOG.debug("Preflight cross-origin request to {} forwarded to application", request.getRequestURI());
else
return;

View File

@ -406,11 +406,11 @@ public class CrossOriginFilterTest
}
@Test
public void testForwardPreflightRequest() throws Exception
public void testChainPreflightRequest() throws Exception
{
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "PUT");
filterHolder.setInitParameter(CrossOriginFilter.FORWARD_PREFLIGHT_PARAM, "false");
filterHolder.setInitParameter(CrossOriginFilter.CHAIN_PREFLIGHT_PARAM, "false");
tester.getContext().addFilter(filterHolder, "/*", FilterMapping.DEFAULT);
CountDownLatch latch = new CountDownLatch(1);