Issue #2936 - Allow Dispatcher.error() to work for BadMessageException
+ Applying fixes from review Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
fe66e3d0cb
commit
57ef060325
|
@ -36,9 +36,13 @@ import org.eclipse.jetty.http.HttpURI;
|
|||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.Attributes;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class Dispatcher implements RequestDispatcher
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(Dispatcher.class);
|
||||
|
||||
public final static String __ERROR_DISPATCH="org.eclipse.jetty.server.Dispatcher.ERROR";
|
||||
|
||||
/** Dispatch include attribute names */
|
||||
|
@ -207,11 +211,14 @@ public class Dispatcher implements RequestDispatcher
|
|||
{
|
||||
// Only throw BME if not in Error Dispatch Mode
|
||||
// This allows application ErrorPageErrorHandler to handle BME messages
|
||||
Boolean inErrorDispatch = (Boolean) request.getAttribute(__ERROR_DISPATCH);
|
||||
if(inErrorDispatch == null || !inErrorDispatch)
|
||||
if (dispatch != DispatcherType.ERROR)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.warn("Ignoring Original Bad Request Query String: " + old_uri, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,7 +92,6 @@ public class ErrorPageTest
|
|||
public void testSendErrorClosedResponse() throws Exception
|
||||
{
|
||||
String response = _connector.getResponse("GET /fail-closed/ HTTP/1.0\r\n\r\n");
|
||||
System.out.println(response);
|
||||
assertThat(response,Matchers.containsString("HTTP/1.1 599 599"));
|
||||
assertThat(response,Matchers.containsString("DISPATCH: ERROR"));
|
||||
assertThat(response,Matchers.containsString("ERROR_PAGE: /599"));
|
||||
|
@ -165,6 +164,8 @@ public class ErrorPageTest
|
|||
|
||||
@Test
|
||||
public void testBadMessage() throws Exception
|
||||
{
|
||||
try (StacklessLogging ignore = new StacklessLogging(Dispatcher.class))
|
||||
{
|
||||
String response = _connector.getResponse("GET /app?baa=%88%A4 HTTP/1.0\r\n\r\n");
|
||||
assertThat(response, Matchers.containsString("HTTP/1.1 400 Bad query encoding"));
|
||||
|
@ -177,6 +178,7 @@ public class ErrorPageTest
|
|||
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /app"));
|
||||
assertThat(response, Matchers.containsString("getParameterMap()= {}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class AppServlet extends HttpServlet implements Servlet
|
||||
|
|
Loading…
Reference in New Issue