Package org.eclipse.jetty.server.handler

Examples of org.eclipse.jetty.server.handler.ContextHandler$Context


                throw new Fault(new Message("START_UP_SERVER_FAILED_MSG", LOG, e.getMessage(), port), e);
            }
        }       
       
        String contextName = HttpUriMapper.getContextName(url.getPath());           
        ContextHandler context = new ContextHandler();
        context.setContextPath(contextName);
        // bind the jetty http handler with the context handler
        if (isSessionSupport) {        
            // If we have sessions, we need two handlers.
            if (sessionManager == null) {
                sessionManager = new HashSessionManager();
                HashSessionIdManager idManager = new HashSessionIdManager();
               
                try {
                    //for JETTY 7.5
                    sessionManager.getClass().getMethod("setSessionIdManager", SessionIdManager.class)
                        .invoke(sessionManager, idManager);
                } catch (Exception e) {
                    //for JETTY <=7.4.x
                    try {
                        sessionManager.getClass().getMethod("setIdManager", SessionIdManager.class)
                            .invoke(sessionManager, idManager);
                    } catch (Exception e1) {
                        throw new Fault(new Message("START_UP_SERVER_FAILED_MSG", LOG,
                                                    e.getMessage(), port), e);                       
                    }
                }
            }
            SessionHandler sessionHandler = new SessionHandler(sessionManager);
            if (securityHandler != null) {
                //use the securityHander which already wrap the jetty http handler
                sessionHandler.setHandler(securityHandler);
            } else {
                sessionHandler.setHandler(handler);
            }
            context.setHandler(sessionHandler);
        } else {
            // otherwise, just the one.
            if (securityHandler != null) {
                //use the securityHander which already wrap the jetty http handler
                context.setHandler(securityHandler);
            } else {
                context.setHandler(handler);
            }
        }
        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


       
        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

    @Test
    public void testGetContextHandler() throws Exception {
        String urlStr = "http://localhost:" + PORT1 + "/hello/test";
        JettyHTTPServerEngine engine =
            factory.createJettyHTTPServerEngine(PORT1, "http");
        ContextHandler contextHandler = engine.getContextHandler(new URL(urlStr));
        // can't find the context handler here
        assertNull(contextHandler);
        JettyHTTPTestHandler handler1 = new JettyHTTPTestHandler("string1", true);
        JettyHTTPTestHandler handler2 = new JettyHTTPTestHandler("string2", true);
        engine.addServant(new URL(urlStr), handler1);

        // Note: There appears to be an internal issue in Jetty that does not
        // unregister the MBean for handler1 during this setHandler operation.
        // This scenario may create a warning message in the logs
        //     (javax.management.InstanceAlreadyExistsException: org.apache.cxf.
        //         transport.http_jetty:type=jettyhttptesthandler,id=0)
        // when running subsequent tests.
        contextHandler = engine.getContextHandler(new URL(urlStr));
        contextHandler.stop();
        contextHandler.setHandler(handler2);
        contextHandler.start();

        String response = null;
        try {
            response = getResponse(urlStr);
        } catch (Exception ex) {
View Full Code Here

    public void testJettyHTTPHandler() throws Exception {
        String urlStr1 = "http://localhost:" + PORT3 + "/hello/test1";
        String urlStr2 = "http://localhost:" + PORT3 + "/hello/test2";
        JettyHTTPServerEngine engine =
            factory.createJettyHTTPServerEngine(PORT3, "http");
        ContextHandler contextHandler = engine.getContextHandler(new URL(urlStr1));
        // can't find the context handler here
        assertNull(contextHandler);
        JettyHTTPHandler handler1 = new JettyHTTPTestHandler("test", false);
        JettyHTTPHandler handler2 = new JettyHTTPTestHandler("test2", false);
        engine.addServant(new URL(urlStr1), handler1);
View Full Code Here

                throw new Fault(new Message("START_UP_SERVER_FAILED_MSG", LOG, e.getMessage(), port), e);
            }
        }       
       
        String contextName = HttpUriMapper.getContextName(url.getPath());           
        ContextHandler context = new ContextHandler();
        context.setContextPath(contextName);
        // bind the jetty http handler with the context handler
        if (isSessionSupport) {        
            // If we have sessions, we need two handlers.
            if (sessionManager == null) {
                sessionManager = new HashSessionManager();
                HashSessionIdManager idManager = new HashSessionIdManager();
               
                try {
                    //for JETTY 7.5
                    sessionManager.getClass().getMethod("setSessionIdManager", SessionIdManager.class)
                        .invoke(sessionManager, idManager);
                } catch (Exception e) {
                    //for JETTY <=7.4.x
                    try {
                        sessionManager.getClass().getMethod("setIdManager", SessionIdManager.class)
                            .invoke(sessionManager, idManager);
                    } catch (Exception e1) {
                        throw new Fault(new Message("START_UP_SERVER_FAILED_MSG", LOG,
                                                    e.getMessage(), port), e);                       
                    }
                }
            }
            SessionHandler sessionHandler = new SessionHandler(sessionManager);
            if (securityHandler != null) {
                //use the securityHander which already wrap the jetty http handler
                sessionHandler.setHandler(securityHandler);
            } else {
                sessionHandler.setHandler(handler);
            }
            context.setHandler(sessionHandler);
        } else {
            // otherwise, just the one.
            if (securityHandler != null) {
                //use the securityHander which already wrap the jetty http handler
                context.setHandler(securityHandler);
            } else {
                context.setHandler(handler);
            }
        }
        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

TOP

Related Classes of org.eclipse.jetty.server.handler.ContextHandler$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.