Examples of ContextHandlerCollection


Examples of org.mortbay.jetty.handler.ContextHandlerCollection

            path = path.substring(0, path.length() - 1);
        }
        String pathSlash = path + "/";
        // Check that context does not exist yet
        HandlerCollection handlerCollection = (HandlerCollection) server.getHandler();
        ContextHandlerCollection contexts = (ContextHandlerCollection) handlerCollection.getHandlers()[0];
        Handler[] handlers = contexts.getHandlers();
        if (handlers != null) {
            for (int i = 0; i < handlers.length; i++) {
                if (handlers[i] instanceof ContextHandler) {
                    ContextHandler h = (ContextHandler) handlers[i];
                    String handlerPath = h.getContextPath() + "/";
                    if (handlerPath.startsWith(pathSlash) || pathSlash.startsWith(handlerPath)) {
                        throw new Exception("The requested context for path '" + path
                                        + "' overlaps with an existing context for path: '" + h.getContextPath() + "'");
                    }
                }
            }
        }
        // Create context
        ContextHandler context = new ContextHandler();
        context.setContextPath(path);
        ServletHolder holder = new ServletHolder();
        holder.setName("jbiServlet");
        holder.setClassName(HttpBridgeServlet.class.getName());
        ServletHandler handler = new ServletHandler();
        handler.setServlets(new ServletHolder[] {holder});
        ServletMapping mapping = new ServletMapping();
        mapping.setServletName("jbiServlet");
        mapping.setPathSpec("/*");
        handler.setServletMappings(new ServletMapping[] {mapping});
        if (processor.getAuthMethod() != null) {
            SecurityHandler secHandler = new SecurityHandler();
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setAuthenticate(true);
            constraint.setRoles(new String[] {"*"});
            constraintMapping.setConstraint(constraint);
            constraintMapping.setPathSpec("/");
            secHandler.setConstraintMappings(new ConstraintMapping[] {constraintMapping});
            secHandler.setHandler(handler);
            secHandler.setAuthMethod(processor.getAuthMethod());
            JaasUserRealm realm = new JaasUserRealm();
            if (configuration.getAuthenticationService() != null) {
                realm.setAuthenticationService(configuration.getAuthenticationService());
            }
            secHandler.setUserRealm(realm);
            context.setHandler(secHandler);
        } else {
            context.setHandler(handler);
        }
        context.setAttribute("processor", processor);
        // add context
        contexts.addHandler(context);
        handler.initialize();
        context.start();
        return context;
    }
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

    public synchronized void remove(Object context) throws Exception {
        ((ContextHandler) context).stop();
        for (Iterator<Server> it = servers.values().iterator(); it.hasNext();) {
            Server server = it.next();
            HandlerCollection handlerCollection = (HandlerCollection) server.getHandler();
            ContextHandlerCollection contexts = (ContextHandlerCollection) handlerCollection.getHandlers()[0];
            Handler[] handlers = contexts.getHandlers();
            if (handlers != null && handlers.length > 0) {
                contexts.setHandlers((Handler[]) LazyList.removeFromArray(handlers, context));
            }
        }
    }
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

        connector.setPort(url.getPort());
        connector.setMaxIdleTime(this.configuration.getConnectorMaxIdleTime());
        Server server = new Server();
        server.setThreadPool(new ThreadPoolWrapper());
        server.setConnectors(new Connector[] {connector});
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[] {contexts, new DisplayServiceHandler()});
        server.setHandler(handlers);
        server.start();
        servers.put(getKey(url), server);
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

        mapping.setServletName("jbiServlet");
        mapping.setPathSpec("/*");
        handler.setServletMappings(new ServletMapping[] {mapping});
        context.setHandler(handler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[] {contexts});
        contexts.addHandler(context);

        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setHost("localhost");
        connector.setPort(8190);

View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

    webServer.addConnector(listener);

    webServer.setThreadPool(new QueuedThreadPool());

    final String appDir = getWebAppsPath();
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    webServer.setHandler(contexts);

    webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setWar(appDir + "/" + name);
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

        contexts = (ContextHandlerCollection) server
                .getChildHandlerByClass(ContextHandlerCollection.class);
        if (contexts == null)
        {
            contexts = new ContextHandlerCollection();
            HandlerCollection handlers = (HandlerCollection) server
                    .getChildHandlerByClass(HandlerCollection.class);
            if (handlers == null)
            {
                handlers = new HandlerCollection();
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

        ContextHandler context1 = new ContextHandler();
        context1.setContextPath("/one");
        Handler handler1=new HelloHandler();
        context1.setHandler(handler1);  
       
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[]{context0,context1});
       
        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{contexts,new DefaultHandler()});
       
        server.setHandler(handlers);
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

    public TerracottaJettyServer(int port, int maxInactivePeriod, int scavengePeriod)
    {
        this.server = new Server(port);
        this.maxInactivePeriod = maxInactivePeriod;
        this.scavengePeriod = scavengePeriod;
        this.contexts = new ContextHandlerCollection();
        this.sessionIdManager = new TerracottaSessionIdManager(server);
    }
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

        SelectChannelConnector connector=new SelectChannelConnector();
        // SocketConnector connector=new SocketConnector();
        connector.setPort(port);
        server.addConnector(connector);
       
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        server.setHandler(contexts);
       
        Context context = new Context(contexts,"/",Context.NO_SECURITY|Context.SESSIONS);
       
View Full Code Here

Examples of org.mortbay.jetty.handler.ContextHandlerCollection

    public static void main(String[] args)
        throws Exception
    {
        Server server = new Server(8080);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        server.setHandler(contexts);

        Context root = new Context(contexts,"/",Context.SESSIONS);
        root.addServlet(new ServletHolder(new HelloServlet("Ciao")), "/*");

        Context other = new Context(contexts,"/other",Context.SESSIONS);
        other.addServlet("org.mortbay.jetty.example.ManyServletContexts$HelloServlet", "/*");

        StatisticsHandler stats = new StatisticsHandler();
        contexts.addHandler(stats);
        Context yetanother =new Context(stats,"/yo",Context.SESSIONS);
        yetanother.addServlet(new ServletHolder(new HelloServlet("YO!")), "/*");

        server.start();
        server.join();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.