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.server.handler.ContextHandler;
|
||||||
import org.eclipse.jetty.util.Attributes;
|
import org.eclipse.jetty.util.Attributes;
|
||||||
import org.eclipse.jetty.util.MultiMap;
|
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
|
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";
|
public final static String __ERROR_DISPATCH="org.eclipse.jetty.server.Dispatcher.ERROR";
|
||||||
|
|
||||||
/** Dispatch include attribute names */
|
/** Dispatch include attribute names */
|
||||||
|
@ -207,11 +211,14 @@ public class Dispatcher implements RequestDispatcher
|
||||||
{
|
{
|
||||||
// Only throw BME if not in Error Dispatch Mode
|
// Only throw BME if not in Error Dispatch Mode
|
||||||
// This allows application ErrorPageErrorHandler to handle BME messages
|
// This allows application ErrorPageErrorHandler to handle BME messages
|
||||||
Boolean inErrorDispatch = (Boolean) request.getAttribute(__ERROR_DISPATCH);
|
if (dispatch != DispatcherType.ERROR)
|
||||||
if(inErrorDispatch == null || !inErrorDispatch)
|
|
||||||
{
|
{
|
||||||
throw e;
|
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
|
public void testSendErrorClosedResponse() throws Exception
|
||||||
{
|
{
|
||||||
String response = _connector.getResponse("GET /fail-closed/ HTTP/1.0\r\n\r\n");
|
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("HTTP/1.1 599 599"));
|
||||||
assertThat(response,Matchers.containsString("DISPATCH: ERROR"));
|
assertThat(response,Matchers.containsString("DISPATCH: ERROR"));
|
||||||
assertThat(response,Matchers.containsString("ERROR_PAGE: /599"));
|
assertThat(response,Matchers.containsString("ERROR_PAGE: /599"));
|
||||||
|
@ -166,16 +165,19 @@ public class ErrorPageTest
|
||||||
@Test
|
@Test
|
||||||
public void testBadMessage() throws Exception
|
public void testBadMessage() throws Exception
|
||||||
{
|
{
|
||||||
String response = _connector.getResponse("GET /app?baa=%88%A4 HTTP/1.0\r\n\r\n");
|
try (StacklessLogging ignore = new StacklessLogging(Dispatcher.class))
|
||||||
assertThat(response, Matchers.containsString("HTTP/1.1 400 Bad query encoding"));
|
{
|
||||||
assertThat(response, Matchers.containsString("ERROR_PAGE: /BadMessageException"));
|
String response = _connector.getResponse("GET /app?baa=%88%A4 HTTP/1.0\r\n\r\n");
|
||||||
assertThat(response, Matchers.containsString("ERROR_MESSAGE: Bad query encoding"));
|
assertThat(response, Matchers.containsString("HTTP/1.1 400 Bad query encoding"));
|
||||||
assertThat(response, Matchers.containsString("ERROR_CODE: 400"));
|
assertThat(response, Matchers.containsString("ERROR_PAGE: /BadMessageException"));
|
||||||
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: org.eclipse.jetty.http.BadMessageException: 400: Bad query encoding"));
|
assertThat(response, Matchers.containsString("ERROR_MESSAGE: Bad query encoding"));
|
||||||
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: class org.eclipse.jetty.http.BadMessageException"));
|
assertThat(response, Matchers.containsString("ERROR_CODE: 400"));
|
||||||
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$AppServlet-"));
|
assertThat(response, Matchers.containsString("ERROR_EXCEPTION: org.eclipse.jetty.http.BadMessageException: 400: Bad query encoding"));
|
||||||
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /app"));
|
assertThat(response, Matchers.containsString("ERROR_EXCEPTION_TYPE: class org.eclipse.jetty.http.BadMessageException"));
|
||||||
assertThat(response, Matchers.containsString("getParameterMap()= {}"));
|
assertThat(response, Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$AppServlet-"));
|
||||||
|
assertThat(response, Matchers.containsString("ERROR_REQUEST_URI: /app"));
|
||||||
|
assertThat(response, Matchers.containsString("getParameterMap()= {}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue