Search in sources :

Example 6 with ErrorPageErrorHandler

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);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ErrorPageErrorHandler(org.eclipse.jetty.servlet.ErrorPageErrorHandler) SampleHealthCheck(edu.uci.ics.texera.web.healthcheck.SampleHealthCheck)

Example 7 with ErrorPageErrorHandler

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);
    }
}
Also used : ErrorPageErrorHandler(org.eclipse.jetty.servlet.ErrorPageErrorHandler) Bundle(org.osgi.framework.Bundle) ServletContext(javax.servlet.ServletContext) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BundleContext(org.osgi.framework.BundleContext)

Example 8 with ErrorPageErrorHandler

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);
}
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

ErrorPageErrorHandler (org.eclipse.jetty.servlet.ErrorPageErrorHandler)8 HashMap (java.util.HashMap)2 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 Constraint (org.eclipse.jetty.util.security.Constraint)2 FileStorage (com.hortonworks.registries.common.util.FileStorage)1 NOOPTransactionManager (com.hortonworks.registries.storage.NOOPTransactionManager)1 Storable (com.hortonworks.registries.storage.Storable)1 StorageManager (com.hortonworks.registries.storage.StorageManager)1 StorageManagerAware (com.hortonworks.registries.storage.StorageManagerAware)1 TransactionManager (com.hortonworks.registries.storage.TransactionManager)1 TransactionManagerAware (com.hortonworks.registries.storage.TransactionManagerAware)1 TransactionEventListener (com.hortonworks.registries.storage.transaction.TransactionEventListener)1 ModuleRegistration (com.hortonworks.streamline.common.ModuleRegistration)1 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)1 StreamlineKerberosRequestFilter (com.hortonworks.streamline.streams.security.authentication.StreamlineKerberosRequestFilter)1 DefaultStreamlineAuthorizer (com.hortonworks.streamline.streams.security.impl.DefaultStreamlineAuthorizer)1 SecurityCatalogService (com.hortonworks.streamline.streams.security.service.SecurityCatalogService)1 AuthorizerConfiguration (com.hortonworks.streamline.webservice.configurations.AuthorizerConfiguration)1 ModuleConfiguration (com.hortonworks.streamline.webservice.configurations.ModuleConfiguration)1