use of org.eclipse.jetty.servlet.ErrorPageErrorHandler in project textdb by TextDB.
the class TexeraWebApplication method run.
@Override
public void run(TexeraWebConfiguration texeraWebConfiguration, Environment environment) throws Exception {
// serve backend at /api
environment.jersey().setUrlPattern("/api/*");
// redirect all 404 to index page, according to Angular routing requirements
ErrorPageErrorHandler eph = new ErrorPageErrorHandler();
eph.addErrorPage(404, "/");
environment.getApplicationContext().setErrorHandler(eph);
final QueryPlanResource newQueryPlanResource = new QueryPlanResource();
environment.jersey().register(newQueryPlanResource);
// Creates an instance of the PlanStoreResource class to register with Jersey
final PlanStoreResource planStoreResource = new PlanStoreResource();
// Registers the PlanStoreResource with Jersey
environment.jersey().register(planStoreResource);
final DownloadFileResource downloadFileResource = new DownloadFileResource();
environment.jersey().register(downloadFileResource);
// Creates an instance of the HealthCheck and registers it with the environment
final SampleHealthCheck sampleHealthCheck = new SampleHealthCheck();
// Registering the SampleHealthCheck with the environment
environment.healthChecks().register("sample", sampleHealthCheck);
// Creates an instance of the InitSystemResource class to register with Jersey
final SystemResource systemResource = new SystemResource();
// Registers the systemResource with Jersey
environment.jersey().register(systemResource);
environment.jersey().register(SessionHandler.class);
environment.servlets().setSessionHandler(new SessionHandler());
final UserResource userResource = new UserResource();
environment.jersey().register(userResource);
final UserFileResource userFileResource = new UserFileResource();
environment.jersey().register(userFileResource);
final KeywordDictionaryResource keywordDictionaryResource = new KeywordDictionaryResource();
environment.jersey().register(keywordDictionaryResource);
final WorkflowResource workflowResource = new WorkflowResource();
environment.jersey().register(workflowResource);
// Registers MultiPartFeature to support file upload
environment.jersey().register(MultiPartFeature.class);
// Configuring the object mapper used by Dropwizard
environment.getObjectMapper().configure(MapperFeature.USE_GETTERS_AS_SETTERS, false);
environment.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
use of org.eclipse.jetty.servlet.ErrorPageErrorHandler in project ddf by codice.
the class ErrorPageInjector method addMissedErrorPage.
private void addMissedErrorPage(ServiceReference<ServletContext> reference) {
final Bundle refBundle = reference.getBundle();
final BundleContext bundlectx = refBundle.getBundleContext();
ServletContext service = bundlectx.getService(reference);
// Need to use the service to get the errorPageErrorHandler through the
// ServletContextHandler
Optional<ServletContextHandler> optionalHttpContext = getHTTPContext(service, refBundle);
if (!optionalHttpContext.isPresent())
return;
ServletContextHandler httpContext = optionalHttpContext.get();
ErrorPageErrorHandler errorPageErrorHandler = null;
try {
errorPageErrorHandler = (ErrorPageErrorHandler) httpContext.getErrorHandler();
} catch (ClassCastException e) {
LOGGER.warn("Problem getting the ErrorHandler from the ServletContextHandler for the bundle {}.", refBundle.getSymbolicName());
}
if (errorPageErrorHandler != null && errorPageErrorHandler.getErrorPages().isEmpty()) {
createAndAddErrorPageHandler(httpContext, refBundle);
}
}
use of org.eclipse.jetty.servlet.ErrorPageErrorHandler 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);
}
Aggregations