Search in sources :

Example 1 with ErrorServlet

use of org.codice.ddf.platform.error.servlet.ErrorServlet in project ddf by codice.

the class ErrorPageInjector method createAndAddErrorPageHandler.

private void createAndAddErrorPageHandler(ServletContextHandler httpServiceContext, Bundle refBundle) {
    // now that we have the handler, we can add in our own ErrorServlet
    ServletHandler handler = httpServiceContext.getServletHandler();
    ServletHolder errorServletHolder = new ServletHolder(new ErrorServlet());
    errorServletHolder.setServletHandler(handler);
    try {
        errorServletHolder.start();
        errorServletHolder.initialize();
    } catch (Exception e) {
        LOGGER.warn("Unable to initialize an errorServletHolder for {}. Jetty's default error page will be used for this context", refBundle.getSymbolicName(), e);
        return;
    }
    LOGGER.info("Injecting an error page into {} ID: {}", refBundle.getSymbolicName(), refBundle.getBundleId());
    handler.addServletWithMapping(errorServletHolder, ERROR_PAGE_PATH);
    ErrorPageErrorHandler errorPageErrorHandler = new ErrorPageErrorHandler();
    errorPageErrorHandler.setErrorPages(errorCodesMap);
    errorPageErrorHandler.setShowStacks(false);
    httpServiceContext.setErrorHandler(errorPageErrorHandler);
}
Also used : ErrorServlet(org.codice.ddf.platform.error.servlet.ErrorServlet) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ErrorPageErrorHandler(org.eclipse.jetty.servlet.ErrorPageErrorHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Aggregations

ErrorServlet (org.codice.ddf.platform.error.servlet.ErrorServlet)1 ErrorPageErrorHandler (org.eclipse.jetty.servlet.ErrorPageErrorHandler)1 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1