Package org.mortbay.jetty.handler

Examples of org.mortbay.jetty.handler.ContextHandler


        properties.put("Server", _contexts.getServer());
        if (_configMgr!=null)
            properties.putAll(_configMgr.getProperties());
          
        xmlConfiguration.setProperties(properties);
        ContextHandler context=(ContextHandler)xmlConfiguration.configure();
        return context;
    }
View Full Code Here


            if (!_allowDuplicates)
            {
                Handler[] installed=_contexts.getChildHandlersByClass(ContextHandler.class);
                for (int i=0; i<installed.length; i++)
                {
                    ContextHandler c=(ContextHandler)installed[i];
       
                    if (context.equals(c.getContextPath()))
                        continue files;

                    try
                    {
                        String path=null;
                        if (c instanceof WebAppContext)
                            path = Resource.newResource(((WebAppContext)c).getWar()).getFile().getAbsolutePath();
                        else if (c.getBaseResource()!=null)
                            path = c.getBaseResource().getFile().getAbsolutePath();

                        if (path!=null && path.equals(app.getFile().getAbsolutePath()))
                            continue files;
                    }
                    catch (Exception e)
View Full Code Here

   
    public void doStop() throws Exception
    {
        for (int i=_deployed.size();i-->0;)
        {
            ContextHandler wac = (ContextHandler)_deployed.get(i);
            wac.stop();// TODO Multi exception
        }
    }
View Full Code Here

                    SelectChannelConnector selectConnector = new SelectChannelConnector();
                    selectConnector.setPort(portNumber);
                    server.setConnectors(new Connector[] {selectConnector});
                }
   
                ContextHandler contextHandler = new ContextHandler();
                //contextHandler.setContextPath(contextPath);
                contextHandler.setContextPath("/");
                server.setHandler(contextHandler);
   
                SessionHandler sessionHandler = new SessionHandler();
                ServletHandler servletHandler = new ServletHandler();
                sessionHandler.addHandler(servletHandler);
   
                contextHandler.setHandler(sessionHandler);
   
                server.setStopAtShutdown(true);
                server.setSendServerVersion(sendServerVersion);
                server.start();
               
View Full Code Here

        server = new Server();
        Connector connector = new SelectChannelConnector();
        connector.setPort(port);
        server.setConnectors(new Connector[]{connector});

        ContextHandler context = new ContextHandler();
        context.setContextPath("/");
        final ServletContext servletContext = context.getServletContext();
        server.setHandler(context);

        Handler handler = new AbstractHandler() {
            public void handle(String target, HttpServletRequest req, HttpServletResponse res, int dispatch) throws IOException, ServletException {
                try {
                    ((Request) req).setHandled(true);
                    HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
                    HttpResponse httpResponse = new ServletResponseAdapter(res);
                    JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
                } catch (IOException e) {
                    throw e;
                } catch (ServletException e) {
                    throw e;
                } catch (Exception e) {
                    throw new ServletException(e);
                }
            }
        };

        SessionHandler sessionHandler = new SessionHandler();
        SessionManager sessionManager = new HashSessionManager();
        sessionManager.setIdManager(new HashSessionIdManager());
        sessionHandler.setSessionManager(sessionManager);
        sessionHandler.setHandler(handler);

        context.setHandler(sessionHandler);
    }
View Full Code Here

                throw new Fault(new Message("START_UP_SERVER_FAILED_MSG", LOG, e.getMessage()), e);
            }
        }       
       
        String contextName = HttpUriMapper.getContextName(url.getPath());           
        ContextHandler context = new ContextHandler();
        context.setContextPath(contextName);
       
        // bind the jetty http handler with the context handler       
        context.setHandler(handler);
        if (isSessionSupport) {           
            HashSessionManager sessionManager = new HashSessionManager();
            SessionHandler sessionHandler = new SessionHandler(sessionManager);
            HashSessionIdManager idManager = new HashSessionIdManager();
            sessionManager.setIdManager(idManager);           
            context.addHandler(sessionHandler);          
        }
        contexts.addHandler(context);
       
        ServletContext sc = context.getServletContext();
        handler.setServletContext(sc);
      
        final String smap = HttpUriMapper.getResourceBase(url.getPath());
        handler.setName(smap);
       
        if (contexts.isStarted()) {          
            try {               
                context.start();
            } catch (Exception ex) {
                LOG.log(Level.WARNING, "ADD_HANDLER_FAILED_MSG", new Object[] {ex.getMessage()});
            }
        }
       
View Full Code Here

        final String smap = HttpUriMapper.getResourceBase(url.getPath());
        boolean found = false;
       
        if (server != null && server.isRunning()) {
            for (Handler handler : contexts.getChildHandlersByClass(ContextHandler.class)) {
                ContextHandler contextHandler = null;               
                if (handler instanceof ContextHandler) {
                    contextHandler = (ContextHandler) handler;
                    Handler jh = contextHandler.getHandler();
                    if (jh instanceof JettyHTTPHandler
                        && contextName.equals(contextHandler.getContextPath())
                        && ((JettyHTTPHandler)jh).getName().equals(smap)) {
                        try {
                            contexts.removeHandler(handler);                           
                            handler.stop();
                            handler.destroy();
View Full Code Here

        Handler ret = null;
        // After a stop(), the server is null, and therefore this
        // operation should return null.
        if (server != null) {          
            for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) {
                ContextHandler contextHandler = null;
                if (handler instanceof ContextHandler) {
                    contextHandler = (ContextHandler) handler;
                    if (contextName.equals(contextHandler.getContextPath())) {          
                        ret = contextHandler.getHandler();
                        break;
                    }
                }
            }   
        }
View Full Code Here

     * @param url the associated URL
     * @return the HttpHandler if registered
     */
    public synchronized ContextHandler getContextHandler(URL url) {
        String contextName = HttpUriMapper.getContextName(url.getPath());
        ContextHandler ret = null;
        // After a stop(), the server is null, and therefore this
        // operation should return null.
        if (server != null) {          
            for (Handler handler : server.getChildHandlersByClass(ContextHandler.class)) {
                ContextHandler contextHandler = null;
                if (handler instanceof ContextHandler) {
                    contextHandler = (ContextHandler) handler;
                    if (contextName.equals(contextHandler.getContextPath())) {          
                        ret = contextHandler;
                        break;
                    }
                }
            }   
View Full Code Here

            }
            server.setConnectors(new Connector[]{connector});
           
            if (args.length<3)
            {
                ContextHandler context = new ContextHandler();
                context.setContextPath(URIUtil.SLASH);
                context.setResourceBase(args.length==1?".":args[1]);
                ServletHandler servlet = new ServletHandler();
                servlet.addServletWithMapping("org.mortbay.jetty.servlet.DefaultServlet", URIUtil.SLASH);
                context.setHandler(servlet);
                contexts.addHandler(context);
            }
            else if ("-webapps".equals(args[1]))
            {
                WebAppContext.addWebApplications(server, args[2], WebAppContext.WEB_DEFAULTS_XML, true, true);
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.handler.ContextHandler

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.