Search in sources :

Example 1 with MethodFilter

use of org.apache.qpid.server.management.plugin.filter.MethodFilter in project qpid-broker-j by apache.

the class HttpManagement method createServer.

private Server createServer(Collection<HttpPort<?>> ports) {
    LOGGER.debug("Starting up web server on {}", ports);
    _jettyServerExecutor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("Jetty-Server-Thread"));
    Server server = new Server(new ExecutorThreadPool(_jettyServerExecutor));
    int lastPort = -1;
    for (HttpPort<?> port : ports) {
        ServerConnector connector = createConnector(port, server);
        connector.addBean(new ConnectionTrackingListener());
        server.addConnector(connector);
        _portConnectorMap.put(port, connector);
        lastPort = port.getPort();
    }
    ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    root.setContextPath("/");
    root.setCompactPath(true);
    server.setHandler(root);
    final ErrorHandler errorHandler = new ErrorHandler() {

        @Override
        protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException {
            String uri = request.getRequestURI();
            writeErrorPageMessage(request, writer, code, message, uri);
            for (int i = 0; i < 20; i++) writer.write("<br/>                                                \n");
        }
    };
    root.setErrorHandler(errorHandler);
    // set servlet context attributes for broker and configuration
    root.getServletContext().setAttribute(HttpManagementUtil.ATTR_BROKER, getBroker());
    root.getServletContext().setAttribute(HttpManagementUtil.ATTR_MANAGEMENT_CONFIGURATION, this);
    root.addFilter(new FilterHolder(new ExceptionHandlingFilter()), "/*", EnumSet.allOf(DispatcherType.class));
    FilterHolder corsFilter = new FilterHolder(new CrossOriginFilter());
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, getCorsAllowOrigins());
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, Joiner.on(",").join(getCorsAllowMethods()));
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, getCorsAllowHeaders());
    corsFilter.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(getCorsAllowCredentials()));
    root.addFilter(corsFilter, "/*", EnumSet.of(DispatcherType.REQUEST));
    root.addFilter(new FilterHolder(new MethodFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
    addFiltersAndServletsForRest(root);
    if (!Boolean.TRUE.equals(getContextValue(Boolean.class, DISABLE_UI_CONTEXT_NAME))) {
        addFiltersAndServletsForUserInterfaces(root);
    }
    root.getSessionHandler().getSessionCookieConfig().setName(JSESSIONID_COOKIE_PREFIX + lastPort);
    root.getSessionHandler().getSessionCookieConfig().setHttpOnly(true);
    root.getSessionHandler().setMaxInactiveInterval(getSessionTimeout());
    return server;
}
Also used : ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) MethodFilter(org.apache.qpid.server.management.plugin.filter.MethodFilter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) DaemonThreadFactory(org.apache.qpid.server.util.DaemonThreadFactory) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool) ExceptionHandlingFilter(org.apache.qpid.server.management.plugin.filter.ExceptionHandlingFilter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 DispatcherType (javax.servlet.DispatcherType)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ExceptionHandlingFilter (org.apache.qpid.server.management.plugin.filter.ExceptionHandlingFilter)1 MethodFilter (org.apache.qpid.server.management.plugin.filter.MethodFilter)1 DaemonThreadFactory (org.apache.qpid.server.util.DaemonThreadFactory)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 ErrorHandler (org.eclipse.jetty.server.handler.ErrorHandler)1 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 CrossOriginFilter (org.eclipse.jetty.servlets.CrossOriginFilter)1 ExecutorThreadPool (org.eclipse.jetty.util.thread.ExecutorThreadPool)1