Package org.eclipse.jetty.server.handler

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


  private ContextHandler createUpdateContext() {
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    File rootFolder = new RootFolderSelector().getRootFolder();
    resource_handler.setResourceBase(new File(rootFolder, "src/test/resources/httpUpdateServerBase").getAbsolutePath());
    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setHandler(resource_handler);
    contextHandler.setContextPath("/updates");
    return contextHandler;
  }
View Full Code Here


    contextHandler.setContextPath("/updates");
    return contextHandler;
  }

  private ContextHandler createRootContext() {
    ContextHandler rootContext = new ContextHandler("/");
    rootContext.setHandler(new DefaultHandler());
    return rootContext;
  }
View Full Code Here

      return gzipHandler;
   }

   private ContextHandler constructHandler(final String connectorName, final String pathInfo, final Handler handler) {

      final ContextHandler contextHandler = new ContextHandler();
      contextHandler.setContextPath(pathInfo);
      contextHandler.setAllowNullPathInfo(true);
      contextHandler.setConnectorNames(new String[]{connectorName});
      contextHandler.addLocaleEncoding(Locale.US.getDisplayName(), StringUtils.UTF_8);
      contextHandler.setHandler(handler);

      final MimeTypes mimeTypes = new MimeTypes();
      mimeTypes.setMimeMap(new HashMap());
      contextHandler.setMimeTypes(mimeTypes);

      return contextHandler;
   }
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

                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

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.