Package org.eclipse.jetty.servlet

Examples of org.eclipse.jetty.servlet.ServletContextHandler$Context


            }
        }
    }
   
    private void setFilters(JettyHttpEndpoint endpoint, Server server, String connectorKey) {
        ServletContextHandler context = (ServletContextHandler) server
            .getChildHandlerByClass(ServletContextHandler.class);
        List<Filter> filters = endpoint.getFilters();
        for (Filter filter : filters) {
            FilterHolder filterHolder = new FilterHolder();
            filterHolder.setFilter(new CamelFilterWrapper(filter));
View Full Code Here


    private void addFilter(ServletContextHandler context, FilterHolder filterHolder, String pathSpec) {
        context.getServletHandler().addFilterWithMapping(filterHolder, pathSpec, 0);
    }

    private void enableMultipartFilter(HttpEndpoint endpoint, Server server, String connectorKey) throws Exception {
        ServletContextHandler context = (ServletContextHandler) server
                .getChildHandlerByClass(ServletContextHandler.class);
        CamelContext camelContext = this.getCamelContext();
        FilterHolder filterHolder = new FilterHolder();
        filterHolder.setInitParameter("deleteFiles", "true");
        if (ObjectHelper.isNotEmpty(camelContext.getProperties().get(TMP_DIR))) {
            File file = new File(camelContext.getProperties().get(TMP_DIR));
            if (!file.isDirectory()) {
                throw new RuntimeCamelException(
                        "The temp file directory of camel-jetty is not exists, please recheck it with directory name :"
                                + camelContext.getProperties().get(TMP_DIR));
            }
            context.setAttribute("javax.servlet.context.tempdir", file);
        }
        // if a filter ref was provided, use it.
        Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
        if (filter == null) {
            // if no filter ref was provided, use the default filter
View Full Code Here

    // Implementation methods
    // -------------------------------------------------------------------------
    protected CamelServlet createServletForConnector(Server server, Connector connector,
                                                     List<Handler> handlers, JettyHttpEndpoint endpoint) throws Exception {
        ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
        context.setConnectorNames(new String[] {connector.getName()});

        if (handlers != null && !handlers.isEmpty()) {
            for (Handler handler : handlers) {
                if (handler instanceof HandlerWrapper) {
                    ((HandlerWrapper) handler).setHandler(server.getHandler());
                    server.setHandler(handler);
                } else {
                    HandlerCollection handlerCollection = new HandlerCollection();
                    handlerCollection.addHandler(server.getHandler());
                    handlerCollection.addHandler(handler);
                    server.setHandler(handlerCollection);
                }
            }
        }

        CamelServlet camelServlet;
        boolean jetty = endpoint.getUseContinuation() != null ? endpoint.getUseContinuation() : isUseContinuation();
        if (jetty) {
            // use Jetty continuations
            CamelContinuationServlet jettyServlet = new CamelContinuationServlet();
            // configure timeout and log it so end user know what we are using
            Long timeout = endpoint.getContinuationTimeout() != null ? endpoint.getContinuationTimeout() : getContinuationTimeout();
            if (timeout != null) {
                LOG.info("Using Jetty continuation timeout: " + timeout + " millis for: " + endpoint);
                jettyServlet.setContinuationTimeout(timeout);
            } else {
                LOG.info("Using default Jetty continuation timeout for: " + endpoint);
            }

            // use the jetty servlet
            camelServlet = jettyServlet;
        } else {
            // do not use jetty so use a plain servlet
            camelServlet = new CamelServlet();
            LOG.info("Jetty continuation is disabled for: " + endpoint);
        }

        ServletHolder holder = new ServletHolder();
        holder.setServlet(camelServlet);
        context.addServlet(holder, "/*");

        return camelServlet;
    }
View Full Code Here

            if (port == -1) {
                // use default
                port = PORT;
            }

            context = new ServletContextHandler();
            context.setContextPath("/");

            if (args.length == 0) {
                System.out.println("Starting an in-memory repository");
                System.out.println(uri + " -> [memory]");
View Full Code Here

            HandlerList handlers = new HandlerList();
           
            Map<Class<?>, Object> classMap = new HashMap<Class<?>, Object>();
            classMap.put(ExchangeFarm.class, new ExchangeFarm());
            classMap.put(GraphEditorMain.class, this);
            ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SECURITY | ServletContextHandler.SESSIONS);
            ServletHolder jerseyHolder = new ServletHolder(new GraphEditorContainer(classMap));
           
            handler.addServlet(new ServletHolder(new Proxy()), "/proxy/*");
           
            String pathPrefix = prop.getProperty("com.trendmicro.tme.grapheditor.pathprefix", "");
            ServletHolder jspHolder = new ServletHolder(new JspServlet());
            jspHolder.setInitParameter("scratchdir", prop.getProperty("jasper.scratchdir", "/var/lib/tme/graph-editor/jsp"));
            jspHolder.setInitParameter("trimSpaces", "true");
            jspHolder.setInitParameter("portalhost", prop.getProperty("com.trendmicro.tme.grapheditor.portalhost", ""));
            jspHolder.setInitParameter("pathprefix", pathPrefix);
            handler.addServlet(jspHolder, "*.jsp");
           
            String webdir = prop.getProperty("com.trendmicro.tme.grapheditor.webdir");
            handler.setResourceBase(webdir);
            logger.info("Web resource base is set to {}", webdir);
           
            jerseyHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
            jerseyHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.trendmicro.tme.grapheditor");
            handler.addServlet(jerseyHolder, "/webapp/graph-editor/*");
           
            FilterHolder loggingFilterHolder = new FilterHolder(new LoggingFilter());
            handler.addFilter(loggingFilterHolder, "/*", 1);
           
            IdentityService identityService = null;
            try {
                identityService = new ZKIdentityService("/global/acl/graph_editor_admins", ZKSessionManager.instance());
                secure = true;
            }
            catch(CODIException.NoNode e) {
                logger.warn("ACL node /global/acl/graph_editor_admins not found! Graph Editor will run in insecure mode.");
            }
           
            SessionHandler sessionHandler = new SessionHandler(new HashSessionManager());
            sessionHandler.getSessionManager().setIdManager(new HashSessionIdManager());
            handler.setSessionHandler(sessionHandler);
           
            if(secure) {
                Constraint constraint = new Constraint();
                constraint.setName(Constraint.__FORM_AUTH);
                constraint.setRoles(new String[] {
                    "super", "admin", "guest"
                });
                constraint.setAuthenticate(true);
               
                ConstraintMapping cm = new ConstraintMapping();
                cm.setConstraint(constraint);
                cm.setPathSpec("/webapp/graph-editor/*");
               
                JAASLoginService jaasLogin = new JAASLoginService("TME Graph Editor");
                jaasLogin.setLoginModuleName("ldaploginmodule");
                jaasLogin.setIdentityService(identityService);
               
                ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
                securityHandler.setConstraintMappings(new ConstraintMapping[] {
                    cm
                });
                securityHandler.setAuthenticator(new BasicAuthenticator());
                securityHandler.setLoginService(jaasLogin);
                securityHandler.setStrict(false);
               
                handler.setSecurityHandler(securityHandler);
            }
           
            RewriteHandler rewrite = new RewriteHandler();
            rewrite.setRewriteRequestURI(true);
           
            RewriteRegexRule redirectRoot = new RewriteRegexRule();
            redirectRoot.setRegex("^/$");
            redirectRoot.setReplacement("/webapp/graph-editor/graph");
            rewrite.addRule(redirectRoot);
           
            if(!pathPrefix.isEmpty()) {
                RedirectPatternRule redirect = new RedirectPatternRule();
                redirect.setPattern(pathPrefix + "/");
                redirect.setLocation(pathPrefix + "/webapp/graph-editor/graph");
                rewrite.addRule(redirect);
               
                RewriteRegexRule reverse = new RewriteRegexRule();
                reverse.setRegex(pathPrefix + "/(.*)");
                reverse.setReplacement("/$1");
                rewrite.addRule(reverse);
            }
            rewrite.setHandler(handlers);
           
            handlers.addHandler(handler);
           
            ResourceHandler resHandler = new ResourceHandler();
            resHandler.setResourceBase(webdir);
            resHandler.setDirectoriesListed(true);
            handlers.addHandler(resHandler);
           
            int port = Integer.valueOf(prop.getProperty("com.trendmicro.tme.grapheditor.port"));
            Server server = new Server(port);
            server.setHandler(rewrite);
            server.setSessionIdManager(handler.getSessionHandler().getSessionManager().getIdManager());
           
            server.start();
            System.err.println("Graph Editor started listening on port " + port);
            logger.info("Graph Editor started listening on port " + port);
           
View Full Code Here

        Server server = new Server();

        server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))});

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/api");
        ServletHolder servletHolder = new ServletHolder(createJerseyServlet());
        servletHolder.setInitOrder(1);
        context.addServlet(servletHolder, "/*");

        WebAppContext webAppContext = new WebAppContext();
        webAppContext.setServer(server);
        webAppContext.setContextPath("/");

View Full Code Here

        connector.setPort(config.getLocalPort());
        server.addConnector(connector);

        server.setStopAtShutdown(true);

        final ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.addEventListener(new GuiceServletContextListener()
        {
            @Override
            protected Injector getInjector()
            {
                return injector;
            }
        });

        // Jersey insists on using java.util.logging (JUL)
        final EventListener listener = new SetupJULBridge();
        context.addEventListener(listener);

        // Make sure Guice filter all requests
        final FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
        context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));

        // Backend servlet for Guice - never used
        final ServletHolder sh = new ServletHolder(DefaultServlet.class);
        context.addServlet(sh, "/*");

        server.start();

        final long secondsToStart = (System.currentTimeMillis() - startTime) / 1000;
        log.info(String.format("Jetty server started in %d:%02d", secondsToStart / 60, secondsToStart % 60));
View Full Code Here

        this.server = new Server(new QueuedThreadPool(nThreads, nThreads));
        this.http = new ServerConnector(server);
        http.setPort(port);
        http.setAcceptQueueSize(maxConn);
        server.addConnector(http);
        this.context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    }
View Full Code Here

    final Server server = new Server(8081);
    final Neo4jGraph neo  = new Neo4jGraph("dbpedia4neo");
    final GraphSail gsail = new GraphSail(neo);
    final SailGraph sail  = new SailGraph(gsail);
   
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        server.setHandler(context);
               
        // set the query handler
        context.addServlet(new ServletHolder(new QueryHandler(sail)), "/query");
       
    // we need a clean shutdown
        Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
View Full Code Here

            //server.addBean(mbContainer);
        }
    }

    private void enableSessionSupport(Server server, String connectorKey) throws Exception {
        ServletContextHandler context = (ServletContextHandler)server.getChildHandlerByClass(ServletContextHandler.class);
        if (context.getSessionHandler() == null) {
            SessionHandler sessionHandler = new SessionHandler();
            if (context.isStarted()) {
                throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey);
            } else {
                context.setSessionHandler(sessionHandler);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.servlet.ServletContextHandler$Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.