392239 Allow no error-code or exception for error-pages

This commit is contained in:
Jan Bartel 2012-10-18 16:34:15 +11:00
parent f6c1ade82f
commit 4769ada666
2 changed files with 21 additions and 8 deletions

View File

@ -50,6 +50,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
private static final Logger LOG = Log.getLogger(ErrorPageErrorHandler.class);
public final static String ERROR_PAGE="org.eclipse.jetty.server.error_page";
public final static String GLOBAL_ERROR_PAGE = "org.eclipse.jetty.server.error_page.global";
protected ServletContext _servletContext;
private final Map<String,String> _errorPages= new HashMap<String,String>(); // code or exception to URL
@ -120,6 +121,12 @@ public class ErrorPageErrorHandler extends ErrorHandler
}
}
}
//try new servlet 3.0 global error page
if (error_page == null)
{
error_page = _errorPages.get(GLOBAL_ERROR_PAGE);
}
if (error_page!=null)
{

View File

@ -679,13 +679,14 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String error = node.getString("error-code", false, true);
int code=0;
if (error == null || error.length() == 0)
{
error = node.getString("exception-type", false, true);
if (error == null || error.length() == 0)
error = ErrorPageErrorHandler.GLOBAL_ERROR_PAGE;
}
else
code=Integer.valueOf(error);
if (code == 0 && (error == null || error.length()==0))
throw new IllegalStateException("Missing error-code or exception-type for error-page");
String location = node.getString("location", false, true);
ErrorPageErrorHandler handler = (ErrorPageErrorHandler)context.getErrorHandler();
Origin o = context.getMetaData().getOrigin("error."+error);
@ -699,7 +700,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
handler.addErrorPage(code,location);
else
handler.addErrorPage(error,location);
context.getMetaData().setOrigin("error."+(code>0?code:error), descriptor);
context.getMetaData().setOrigin("error."+error, descriptor);
break;
}
case WebXml:
@ -709,11 +710,16 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//an error page setup was set in web.xml, only allow other web xml descriptors to override it
if (!(descriptor instanceof FragmentDescriptor))
{
if (code>0)
handler.addErrorPage(code,location);
if (descriptor instanceof OverrideDescriptor || descriptor instanceof DefaultsDescriptor)
{
if (code>0)
handler.addErrorPage(code,location);
else
handler.addErrorPage(error,location);
context.getMetaData().setOrigin("error."+error, descriptor);
}
else
handler.addErrorPage(error,location);
context.getMetaData().setOrigin("error."+(code>0?code:error), descriptor);
throw new IllegalStateException("Duplicate global error-page "+location);
}
break;
}