Java 类org.eclipse.jetty.server.handler.ErrorHandler 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedServletContainerFactory.java   
private void addJettyErrorPages(ErrorHandler errorHandler,
        Collection<ErrorPage> errorPages) {
    if (errorHandler instanceof ErrorPageErrorHandler) {
        ErrorPageErrorHandler handler = (ErrorPageErrorHandler) errorHandler;
        for (ErrorPage errorPage : errorPages) {
            if (errorPage.isGlobal()) {
                handler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE,
                        errorPage.getPath());
            }
            else {
                if (errorPage.getExceptionName() != null) {
                    handler.addErrorPage(errorPage.getExceptionName(),
                            errorPage.getPath());
                }
                else {
                    handler.addErrorPage(errorPage.getStatusCode(),
                            errorPage.getPath());
                }
            }
        }
    }
}
项目:rdf-delta    文件:PatchLogServer.java   
/** Build a ServletContextHandler. */
private static ServletContextHandler buildServletContext(String contextPath) {
    if ( contextPath == null || contextPath.isEmpty() )
        contextPath = "/" ;
    else if ( !contextPath.startsWith("/") )
        contextPath = "/" + contextPath ;
    ServletContextHandler context = new ServletContextHandler() ;
    context.setDisplayName("PatchLogServer") ;
    MimeTypes mt = new MimeTypes();
    addMimeType(mt, Lang.TTL);
    addMimeType(mt, Lang.NT);
    addMimeType(mt, Lang.TRIG);
    addMimeType(mt, Lang.NQ);
    addMimeType(mt, Lang.RDFXML);
    context.setMimeTypes(mt);
    ErrorHandler eh = new HttpErrorHandler();
    context.setErrorHandler(eh) ;
    return context ;
}
项目:spring-boot-concourse    文件:JettyEmbeddedServletContainerFactory.java   
private void addJettyErrorPages(ErrorHandler errorHandler,
        Collection<ErrorPage> errorPages) {
    if (errorHandler instanceof ErrorPageErrorHandler) {
        ErrorPageErrorHandler handler = (ErrorPageErrorHandler) errorHandler;
        for (ErrorPage errorPage : errorPages) {
            if (errorPage.isGlobal()) {
                handler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE,
                        errorPage.getPath());
            }
            else {
                if (errorPage.getExceptionName() != null) {
                    handler.addErrorPage(errorPage.getExceptionName(),
                            errorPage.getPath());
                }
                else {
                    handler.addErrorPage(errorPage.getStatusCode(),
                            errorPage.getPath());
                }
            }
        }
    }
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
private void addJettyErrorPages(ErrorHandler errorHandler,
        Collection<ErrorPage> errorPages) {
    if (errorHandler instanceof ErrorPageErrorHandler) {
        ErrorPageErrorHandler handler = (ErrorPageErrorHandler) errorHandler;
        for (ErrorPage errorPage : errorPages) {
            if (errorPage.isGlobal()) {
                handler.addErrorPage(ErrorPageErrorHandler.GLOBAL_ERROR_PAGE,
                        errorPage.getPath());
            }
            else {
                if (errorPage.getExceptionName() != null) {
                    handler.addErrorPage(errorPage.getExceptionName(),
                            errorPage.getPath());
                }
                else {
                    handler.addErrorPage(errorPage.getStatusCode(),
                            errorPage.getPath());
                }
            }
        }
    }
}
项目:traccar-service    文件:WebServer.java   
public WebServer(Config config, DataSource dataSource) {
    this.config = config;
    this.dataSource = dataSource;

    sessionManager = new HashSessionManager();
    int sessionTimeout = config.getInteger("web.sessionTimeout");
    if (sessionTimeout != 0) {
        sessionManager.setMaxInactiveInterval(sessionTimeout);
    }

    initServer();
    initApi();
    if (config.getBoolean("web.console")) {
        initConsole();
    }
    switch (config.getString("web.type", "new")) {
        case "old":
            initOldWebApp();
            break;
        default:
            initWebApp();
            break;
    }
    initClientProxy();
    server.setHandler(handlers);

    server.addBean(new ErrorHandler() {
        @Override
        protected void handleErrorPage(
                HttpServletRequest request, Writer writer, int code, String message) throws IOException {
            writer.write("<!DOCTYPE<html><head><title>Error</title></head><html><body>"
                    + code + " - " + HttpStatus.getMessage(code) + "</body></html>");
        }
    }, false);
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler,int options)
{
    super((ContextHandler.Context)null);
    _options=options;
    _scontext = new Context();
    _sessionHandler = sessionHandler;
    _securityHandler = securityHandler;
    _servletHandler = servletHandler;

    if (contextPath!=null)
        setContextPath(contextPath);

    if (parent instanceof HandlerWrapper)
        ((HandlerWrapper)parent).setHandler(this);
    else if (parent instanceof HandlerCollection)
        ((HandlerCollection)parent).addHandler(this);


    // Link the handlers
    relinkHandlers();

    if (errorHandler!=null)
        setErrorHandler(errorHandler);


    this.addFilter(new FilterHolder(new HTTPAuthFilter()), "/v2/*", EnumSet.allOf(DispatcherType.class));

}
项目:EvoMaster    文件:SutController.java   
/**
 * Start the controller as a RESTful server.
 * Use the setters of this class to change the default
 * port and host.
 * <br>
 * This method is blocking until the server is initialized.
 */
public final boolean startTheControllerServer() {

    //Jersey
    ResourceConfig config = new ResourceConfig();
    config.register(JacksonFeature.class);
    config.register(new EMController(this));
    config.register(LoggingFeature.class);

    //Jetty
    controllerServer = new Server(InetSocketAddress.createUnresolved(
            getControllerHost(), getControllerPort()));

    ErrorHandler errorHandler = new ErrorHandler();
    errorHandler.setShowStacks(true);
    controllerServer.setErrorHandler(errorHandler);

    ServletHolder servlet = new ServletHolder(new ServletContainer(config));

    ServletContextHandler context = new ServletContextHandler(controllerServer,
            ControllerConstants.BASE_PATH + "/*");
    context.addServlet(servlet, "/*");


    try {
        controllerServer.start();
    } catch (Exception e) {
        SimpleLogger.error("Failed to start Jetty: " + e.getMessage());
        controllerServer.destroy();
    }

    //just make sure we start from a clean state
    newSearch();

    SimpleLogger.info("Started controller server on: " + controllerServer.getURI());

    return true;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedServletContainerFactory.java   
/**
 * Create a configuration object that adds error handlers.
 * @return a configuration object for adding error pages
 */
private Configuration getErrorPageConfiguration() {
    return new AbstractConfiguration() {

        @Override
        public void configure(WebAppContext context) throws Exception {
            ErrorHandler errorHandler = context.getErrorHandler();
            context.setErrorHandler(new JettyEmbeddedErrorHandler(errorHandler));
            addJettyErrorPages(errorHandler, getErrorPages());
        }

    };
}
项目:factoryfx    文件:JettyServer.java   
public JettyServer(List<HttpServerConnectorCreator> connectors, List<Object> resources) {
        server=new org.eclipse.jetty.server.Server();
        currentConnectors.addAll(connectors);
        for (HttpServerConnectorCreator creator : currentConnectors) {
            creator.addToServer(server);
        }

        rootServlet = new UpdateableServlet(new ServletContainer(jerseySetup(resources)));
        ServletHolder holder = new ServletHolder(rootServlet);
        ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        contextHandler.addServlet( holder, "/*");
        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setShowStacks(true);
        contextHandler.setErrorHandler(errorHandler);

        GzipHandler gzipHandler = new GzipHandler();
//            HashSet<String> mimeTypes = new HashSet<>();
//            mimeTypes.add("text/html");
//            mimeTypes.add("text/plain");
//            mimeTypes.add("text/css");
//            mimeTypes.add("application/x-javascript");
//            mimeTypes.add("application/json");
        gzipHandler.setMinGzipSize(0);

        gzipHandler.setHandler(contextHandler);

        HandlerCollection handlers = new HandlerList();
        additionalHandlers().forEach(handler -> handlers.addHandler(handler));
        handlers.addHandler(gzipHandler);
        server.setHandler(handlers);
    }
项目:spring-boot-concourse    文件:JettyEmbeddedServletContainerFactory.java   
/**
 * Create a configuration object that adds error handlers.
 * @return a configuration object for adding error pages
 */
private Configuration getErrorPageConfiguration() {
    return new AbstractConfiguration() {

        @Override
        public void configure(WebAppContext context) throws Exception {
            ErrorHandler errorHandler = context.getErrorHandler();
            context.setErrorHandler(new JettyEmbeddedErrorHandler(errorHandler));
            addJettyErrorPages(errorHandler, getErrorPages());
        }

    };
}
项目:contestparser    文件:JettyEmbeddedServletContainerFactory.java   
/**
 * Create a configuration object that adds error handlers.
 * @return a configuration object for adding error pages
 */
private Configuration getErrorPageConfiguration() {
    return new AbstractConfiguration() {
        @Override
        public void configure(WebAppContext context) throws Exception {
            ErrorHandler errorHandler = context.getErrorHandler();
            addJettyErrorPages(errorHandler, getErrorPages());
        }
    };
}
项目:tapestry-fat-jar    文件:Server.java   
public static void main(String[] args) throws Exception {

    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(8080);

    final ErrorHandler errorHandler = new ErrorHandler();
       errorHandler.setServer(server);
       errorHandler.setShowStacks(false);
       server.addBean(errorHandler);

       server.setStopAtShutdown(true);
       server.setStopTimeout(30*1000l);

       ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);

       handler.setClassLoader(Thread.currentThread().getContextClassLoader());
       handler.setContextPath("/");
       handler.setInitParameter("tapestry.app-package", "com.ckfce.tapfatjar");

       FilterHolder filterHolder = new FilterHolder();
       filterHolder.setHeldClass(TapestryFilter.class);
       filterHolder.setName("app");

       handler.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));

    server.setHandler(handler);

       server.start();        
       server.join();
}
项目:TheHumanity    文件:GameServer.java   
private ServletContextHandler getServletContextHandler(final WebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    contextHandler.setErrorHandler(null);
    contextHandler.setContextPath("/");
    contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), "/*");
    contextHandler.addEventListener(new ContextLoaderListener(context));
    //        contextHandler.setResourceBase(new ClassPathResource("web").getURI().toString());
    //        contextHandler.setResourceBase("src/main/resources/web");
    contextHandler.setResourceBase("src/main/webapp");
    contextHandler.setErrorHandler(new ErrorHandler());
    contextHandler.getErrorHandler().setShowStacks(true);
    return contextHandler;
}
项目:QDrill    文件:WebServer.java   
/**
 * Start the web server including setup.
 * @throws Exception
 */
public void start() throws Exception {
  if (embeddedJetty == null) {
    return;
  }

  final ServerConnector serverConnector;
  if (config.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) {
    serverConnector = createHttpsConnector();
  } else {
    serverConnector = createHttpConnector();
  }
  embeddedJetty.addConnector(serverConnector);

  // Add resources
  final ErrorHandler errorHandler = new ErrorHandler();
  errorHandler.setShowStacks(true);
  errorHandler.setShowMessageInTitle(true);

  final ServletContextHandler servletContextHandler =
      new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  servletContextHandler.setErrorHandler(errorHandler);
  servletContextHandler.setContextPath("/");
  embeddedJetty.setHandler(servletContextHandler);

  final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new DrillRestServer(workManager)));
  servletHolder.setInitOrder(1);
  servletContextHandler.addServlet(servletHolder, "/*");

  servletContextHandler.addServlet(
      new ServletHolder(new MetricsServlet(metrics)), "/status/metrics");
  servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/status/threads");

  final ServletHolder staticHolder = new ServletHolder("static", DefaultServlet.class);
  staticHolder.setInitParameter("resourceBase", Resource.newClassPathResource("/rest/static").toString());
  staticHolder.setInitParameter("dirAllowed","false");
  staticHolder.setInitParameter("pathInfoOnly","true");
  servletContextHandler.addServlet(staticHolder,"/static/*");

  embeddedJetty.start();
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
public ServletContextHandler(HandlerContainer parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
    this(parent,null,sessionHandler,securityHandler,servletHandler,errorHandler);
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
    this(parent,contextPath,sessionHandler,securityHandler,servletHandler,errorHandler,0);
}
项目:beyondj    文件:JettyHttpComponent.java   
public ErrorHandler getErrorHandler() {
    return errorHandler;
}
项目:beyondj    文件:JettyHttpComponent.java   
public void setErrorHandler(ErrorHandler errorHandler) {
    this.errorHandler = errorHandler;
}
项目:backstopper    文件:Main.java   
private static ErrorHandler generateErrorHandler() {
    ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
    errorHandler.addErrorPage(Throwable.class, "/error");
    return errorHandler;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedErrorHandler.java   
JettyEmbeddedErrorHandler(ErrorHandler delegate) {
    this.delegate = delegate;
}
项目:factoryfx    文件:HttpServer.java   
public void start() {
        System.setProperty("java.net.preferIPv4Stack", "true");//TODO optional?

        server = new org.eclipse.jetty.server.Server();
//        HashSessionIdManager sessionIdManager = new HashSessionIdManager();
//        server.setSessionIdManager(sessionIdManager);

        connector = new NetworkTrafficServerConnector(server);
        connector.setPort(httpPort);
        connector.setHost(host);
        server.addConnector(connector);


        ServletContextHandler contextHandler = new ServletContextHandler();
        SessionHandler sessionHandler = new SessionHandler();
//        HashSessionManager sessionManager = new HashSessionManager();
//        sessionManager.setMaxInactiveInterval(sessionTimeoutS);
//        sessionManager.setSessionCookie(sessionManager.getSessionCookie()+httpPort); //avoid session mix up for 2 server running as localhost
//        sessionHandler.setSessionManager(sessionManager);


        contextHandler.setSessionHandler(sessionHandler);
        contextHandler.addServlet(new ServletHolder(new ServletContainer(jerseySetup(restResource))), "/applicationServer/*");

        ErrorHandler errorHandler = new ErrorHandler();
        errorHandler.setShowStacks(true);
        contextHandler.setErrorHandler(errorHandler);

        GzipHandler gzipHandler = new GzipHandler();
//            HashSet<String> mimeTypes = new HashSet<>();
//            mimeTypes.add("text/html");
//            mimeTypes.add("text/plain");
//            mimeTypes.add("text/css");
//            mimeTypes.add("application/x-javascript");
//            mimeTypes.add("application/json");
        gzipHandler.setMinGzipSize(0);
//            gzipHandler.setMimeTypes(mimeTypes);

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{resourceHandler, contextHandler});
        gzipHandler.setHandler(handlers);
        server.setHandler(gzipHandler);

        try {
            server.start();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
项目:spring-boot-concourse    文件:JettyEmbeddedErrorHandler.java   
JettyEmbeddedErrorHandler(ErrorHandler delegate) {
    this.delegate = delegate;
}
项目:Camel    文件:JettyHttpComponent.java   
public ErrorHandler getErrorHandler() {
    return errorHandler;
}
项目:Camel    文件:JettyHttpComponent.java   
/**
 * This option is used to set the ErrorHandler that Jetty server uses.
 */
@Metadata(description = "This option is used to set the ErrorHandler that Jetty server uses.")
public void setErrorHandler(ErrorHandler errorHandler) {
    this.errorHandler = errorHandler;
}
项目:Camel    文件:JettyHttpComponentConfiguration9.java   
public ErrorHandler getErrorHandler() {
    return errorHandler;
}
项目:Camel    文件:JettyHttpComponentConfiguration9.java   
public void setErrorHandler(ErrorHandler errorHandler) {
    this.errorHandler = errorHandler;
}
项目:polygene-java    文件:AbstractJettyMixin.java   
@Override
public final void startJetty()
    throws Exception
{
    // Configure Server
    configureServer( server, configuration() );

    // Set up HTTP
    HttpConfiguration httpConfig = new HttpConfiguration();
    configureHttp( httpConfig, configuration() );
    httpConfig = specializeHttp( httpConfig );

    // Set up connector
    ServerConnector connector = buildConnector( server, httpConfig );
    configureConnector( connector, configuration() );

    // Bind Connector to Server
    server.addConnector( connector );
    if( mBeanServer != null )
    {
        server.addEventListener( new MBeanContainer( mBeanServer ) );
    }

    // Prepare ServletContext
    ServletContextHandler root = new ServletContextHandler( server,
                                                            "/",
                                                            new SessionHandler(),
                                                            buildSecurityHandler(),
                                                            new ServletHandler(),
                                                            new ErrorHandler() );
    root.setDisplayName( identity.toString() );
    configureContext( root, configuration() );

    // Register ContextListeners, Servlets and Filters
    addContextListeners( root, contextListeners );
    addServlets( root, servlets );
    addFilters( root, filters );

    // Start
    server.start();
}
项目:logsniffer    文件:WebContextWithExtraConfigurations.java   
public WebContextWithExtraConfigurations(final SessionHandler sessionHandler, final SecurityHandler securityHandler,
        final ServletHandler servletHandler, final ErrorHandler errorHandler) {
    super(sessionHandler, securityHandler, servletHandler, errorHandler);
}
项目:cougar    文件:JettyHttpTransport.java   
public void initialiseStaticJettyConfig() throws Exception {
        server.initialiseConnectors();

        ErrorHandler errorHandler = new CougarErrorHandler();
        wsdlStaticHandler = new StaticContentServiceHandler(
                wsdlContextPath,
                wsdlRegex,
                wsdlMediaType,
                uuidHeader,
                uuidParentsHeader,
                deserializer,
                geoIPLocator,
                requestLogger,
                true);
        wsdlStaticHandler.setUnknownCipherKeyLength(unknownCipherKeyLength);

        htmlStaticHandler = new StaticContentServiceHandler(
                htmlContextPath,
                htmlRegex,
                htmlMediaType,
                uuidHeader,
                uuidParentsHeader,
                deserializer,
                geoIPLocator,
                requestLogger,
                suppressCommasInAccessLogForStaticHtml);
        htmlStaticHandler.setUnknownCipherKeyLength(unknownCipherKeyLength);

        StatisticsHandler statisticsHandler = new StatisticsHandler();
        statisticsHandler.setServer(server.getJettyServer());

        handlerCollection.setServer(server.getJettyServer());

        JettyHandler defaultJettyServiceHandler = new AliasHandler(defaultCommandProcessor, suppressCommasInAccessLogForCalls, pathAliases);
        ContextHandler context = new ContextHandler();
        context.setContextPath("");
        context.setResourceBase(".");
        context.setHandler(defaultJettyServiceHandler);
        handlerCollection.addHandler(context);

        handlerCollection.addHandler(wsdlStaticHandler);
        handlerCollection.addHandler(htmlStaticHandler);
//        handlerCollection.addHandler(aliasHandler);
        statisticsHandler.setHandler(handlerCollection);

        // Register the errorhandler with the server itself
        server.addBean(errorHandler);
        server.setHandler(statisticsHandler);
    }