Java 类org.eclipse.jetty.server.Handler 实例源码

项目:vk-java-sdk    文件:Application.java   
private static void initServer(Properties properties) throws Exception {
    Integer port = Integer.valueOf(properties.getProperty("server.port"));
    String host = properties.getProperty("server.host");

    Integer clientId = Integer.valueOf(properties.getProperty("client.id"));
    String clientSecret = properties.getProperty("client.secret");

    HandlerCollection handlers = new HandlerCollection();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[]{"index.html"});
    resourceHandler.setResourceBase(Application.class.getResource("/static").getPath());

    VkApiClient vk = new VkApiClient(new HttpTransportClient());
    handlers.setHandlers(new Handler[]{resourceHandler, new RequestHandler(vk, clientId, clientSecret, host)});

    Server server = new Server(port);
    server.setHandler(handlers);

    server.start();
    server.join();
}
项目:JavaEE    文件:Main.java   
public static void main(String[] args) throws Exception {

        // Create a basic Jetty server object that will listen on port 8080
        Server server = new Server(8080);

        // Create the ResourceHandler. It is the object that will actually
        // handle the request for a given file. It is a Jetty Handler object
        // so it is suitable for chaining with other handlers as you will see
        // in other examples
        ResourceHandler resource_handler = new ResourceHandler();

        // Configure the ResourceHandler. Setting the resource base indicates
        // where the files should be served out of
        resource_handler.setDirectoriesListed(true);
        resource_handler.setWelcomeFiles(new String[]{ "index.html" });
        resource_handler.setResourceBase("src/main/webapp/");

        // Add the ResourceHandler to the server
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
        server.setHandler(handlers);

        // Start server
        server.start();
        server.join();
    }
项目:fwm    文件:ScratchPad.java   
public static void startServer(String[] args) throws Exception {
    Server server = new Server(8080);

    WebAppContext ctx = new WebAppContext();
    ctx.setContextPath("/");
    ctx.setWar("src/main/webapp/");
    HandlerCollection hc = new HandlerCollection();
    hc.setHandlers(new Handler[] {ctx});

    server.setHandler(hc);
    server.setStopAtShutdown(true);
    server.start();

    server.join();

    // server.removeBean(o);
    // server.addBean(o);
}
项目:otter-G    文件:JettyEmbedServer.java   
public void start() throws Exception {
    Resource configXml = Resource.newSystemResource(config);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();

    //        Integer port = getPort();
    //        if (port != null && port > 0) {
    //            Connector[] connectors = server.getConnectors();
    //            for (Connector connector : connectors) {
    //                connector.setPort(port);
    //            }
    //        }
    Handler handler = server.getHandler();
    if (handler != null && handler instanceof WebAppContext) {
        WebAppContext webAppContext = (WebAppContext) handler;
        webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
    }
    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is startup!");
    }
}
项目:otter-G    文件:JettyEmbedServer.java   
public void afterPropertiesSet() throws Exception {
    Resource configXml = Resource.newSystemResource(config);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();
    Integer port = getPort();
    if (port != null && port > 0) {
        Connector[] connectors = server.getConnectors();
        for (Connector connector : connectors) {
            connector.setPort(port);
        }
    }

    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
    }

    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is startup!");
    }
}
项目:otter-G    文件:JettyEmbedIntegration.java   
public static void main(String args[]) throws Exception {
    Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
    XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
    Server server = (Server) configuration.configure();
    int port = 8081;
    Connector[] connectors = server.getConnectors();
    for (Connector connector : connectors) {
        connector.setPort(port);
    }

    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
    }

    server.start();
    server.join();
}
项目:Cognizant-Intelligent-Test-Scripter    文件:DashBoardServer.java   
public void prepare() {
    try {
        Tools.verifyLocalPort("DBServer ", port());
        server = new Server();
        DefaultHandler webHandler = new DefaultHandler();
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{getResourceHandler(),
            getUIWSHandler(), webHandler});

        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port());
        server.setConnectors(new Connector[]{connector});
        server.setHandler(handlers);

        LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
                new Object[]{Tools.IP(), port() + ""});

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
项目:paul0-application-server    文件:HomeServerConfig.java   
private HandlerList getAllServices() throws Exception{
    // File server & Context Handler for root, also setting the index.html
    // to be the "welcome file", i.e, autolink on root addresses.
    ContextHandler rootContext = new ContextHandler();
    rootContext.setContextPath("/*");
    rootContext.setHandler(getResourceHandlers());

    // Possible servlet lists, for all servlets or custom services you want to access later.
    // Warning, it might become a little bit nested if you add to many classes.
    ServletHandler questionHandler = new ServletHandler();
    questionHandler.addServletWithMapping(QuestionHandler.class, "/question");

    // Add the ResourceHandler to the server.
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] {
            rootContext ,
            questionHandler,
    });

    return handlers;
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
/**
 * @param sessionHandler The sessionHandler to set.
 */
public void setSessionHandler(SessionHandler sessionHandler)
{
    if (isStarted())
        throw new IllegalStateException("STARTED");

    Handler next=null;
    if (_sessionHandler!=null)
    {
        next=_sessionHandler.getHandler();
        _sessionHandler.setHandler(null);
        replaceHandler(_sessionHandler,sessionHandler);
    }

    _sessionHandler = sessionHandler;
    if (next!=null && _sessionHandler.getHandler()==null)
        _sessionHandler.setHandler(next);
    relinkHandlers();
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
/**
 * @param securityHandler The {@link SecurityHandler} to set on this context.
 */
public void setSecurityHandler(SecurityHandler securityHandler)
{
    if (isStarted())
        throw new IllegalStateException("STARTED");

    Handler next=null;
    if (_securityHandler!=null)
    {
        next=_securityHandler.getHandler();
        _securityHandler.setHandler(null);
        replaceHandler(_securityHandler,securityHandler);
    }

    _securityHandler = securityHandler;
    if (next!=null && _securityHandler.getHandler()==null)
        _securityHandler.setHandler(next);
    relinkHandlers();
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
/**
 * @param gzipHandler The {@link GzipHandler} to set on this context.
 */
public void setGzipHandler(GzipHandler gzipHandler)
{
    if (isStarted())
        throw new IllegalStateException("STARTED");

    Handler next=null;
    if (_gzipHandler!=null)
    {
        next=_gzipHandler.getHandler();
        _gzipHandler.setHandler(null);
        replaceHandler(_gzipHandler,gzipHandler);
    }

    _gzipHandler = gzipHandler;
    if (next!=null && _gzipHandler.getHandler()==null)
        _gzipHandler.setHandler(next);
    relinkHandlers();
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
/**
 * @param servletHandler The servletHandler to set.
 */
public void setServletHandler(ServletHandler servletHandler)
{
    if (isStarted())
        throw new IllegalStateException("STARTED");

    Handler next=null;
    if (_servletHandler!=null)
    {
        next=_servletHandler.getHandler();
        _servletHandler.setHandler(null);
        replaceHandler(_servletHandler,servletHandler);
    }
    _servletHandler = servletHandler;
    if (next!=null && _servletHandler.getHandler()==null)
        _servletHandler.setHandler(next);
    relinkHandlers();
}
项目:nifi-registry    文件:JettyServer.java   
public void start() {
    try {
        // start the server
        server.start();

        // ensure everything started successfully
        for (Handler handler : server.getChildHandlers()) {
            // see if the handler is a web app
            if (handler instanceof WebAppContext) {
                WebAppContext context = (WebAppContext) handler;

                // see if this webapp had any exceptions that would
                // cause it to be unavailable
                if (context.getUnavailableException() != null) {
                    startUpFailure(context.getUnavailableException());
                }
            }
        }

        dumpUrls();
    } catch (final Throwable t) {
        startUpFailure(t);
    }
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:ccow    文件:WebSocketsTestSuite.java   
@BeforeClass
public static void beforeClass() throws Exception {
    ccowServer = new Server(serverPort);

    final CCOWContextListener c = new CCOWContextListener(commonContext, new InlinedContextAgentRepositoryModule());

    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    ccowServer.addBean(mbContainer);

    final ServletContextHandler webSocketServletContextHandler = new ServletContextHandler(ccowServer, "/ws",
            ServletContextHandler.SESSIONS);
    webSocketServletContextHandler.addEventListener(c);
    WebSocketServerContainerInitializer.configureContext(webSocketServletContextHandler);

    final ServletContextHandler restServletContextHandler = new ServletContextHandler(ccowServer, "/");
    restServletContextHandler.addEventListener(c);
    restServletContextHandler.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

     final ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(new Handler[] { webSocketServletContextHandler, restServletContextHandler});

    ccowServer.setHandler(contexts);
    ccowServer.start();

}
项目:jetty-server-request-logger    文件:JettyServerCustomizer.java   
@Bean
public EmbeddedServletContainerFactory jettyConfigBean() {

    DynamicPropertyFactory propertyFactory = DynamicPropertyFactory.getInstance();
    String accessLogFilePath = propertyFactory.getStringProperty("server.accessLog.config.file", ACCESS_LOG_FILE_PATH).getValue();

    JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory
            = new JettyEmbeddedServletContainerFactory();
    jettyEmbeddedServletContainerFactory.addServerCustomizers(new org.springframework.boot.context.embedded.jetty.JettyServerCustomizer() {
        public void customize(Server server) {
            HandlerCollection handlers = new HandlerCollection();
            for (Handler handler : server.getHandlers()) {
                handlers.addHandler(handler);
            }
            RequestLogHandler requestLogHandler = new RequestLogHandler();
            RequestLogImpl requestLogImpl = new RequestLogImpl();
            requestLogImpl.setFileName(accessLogFilePath);
            requestLogHandler.setRequestLog(requestLogImpl);
            handlers.addHandler(requestLogHandler);
            server.setHandler(handlers);
            LOGGER.info("Jetty Server Customized. Access Log Configuration File - {}", accessLogFilePath);
        }
    });
    return jettyEmbeddedServletContainerFactory;
}
项目:leopard    文件:WebappDaoImpl.java   
protected Handler getHandlerList(List<String> hostList) {
    // jettyServer.getWebappService().addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
    // jettyServer.getWebappService().addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
    if (hostList.contains("fshop.leopard.io")) {
        if (false) {
            return new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/");
        }
        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
        handlerList.addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
        try {
            handlerList.start();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return handlerList;
    }
    return null;
}
项目:Camel    文件:JettyHttpComponent.java   
protected void addJettyHandlers(Server server, List<Handler> handlers) {
    if (handlers != null && !handlers.isEmpty()) {
        for (Handler handler : handlers) {
            if (handler instanceof HandlerWrapper) {
                // avoid setting the security handler more than once
                if (!handler.equals(server.getHandler())) {
                    ((HandlerWrapper) handler).setHandler(server.getHandler());
                    server.setHandler(handler);
                }
            } else {
                HandlerCollection handlerCollection = new HandlerCollection();
                handlerCollection.addHandler(server.getHandler());
                handlerCollection.addHandler(handler);
                server.setHandler(handlerCollection);
            }
        }
    }
}
项目:service-base    文件:JServer.java   
/**
 *
 * @param webapp
 * @return
 */
private static ContextHandlerCollection setupHttpsRedirect(WebAppContext webapp) {
    /*HANDLERS BUSINESS*/
    SecuredRedirectHandler securedRedirect = new SecuredRedirectHandler();

    // Establish all handlers that have a context
    ContextHandlerCollection contextHandlers = new ContextHandlerCollection();
    webapp.setVirtualHosts(new String[]{"@secured"});   // handles requests that come through the sslConnector connector ...

    ContextHandler redirectHandler = new ContextHandler();
    redirectHandler.setContextPath("/");
    redirectHandler.setHandler(securedRedirect);
    redirectHandler.setVirtualHosts(new String[]{"@unsecured"});  // handls requests that come through the Connector (unsecured) ...
    contextHandlers.setHandlers(new Handler[]{redirectHandler, webapp});
    return contextHandlers;
}
项目:joinfaces    文件:JsfJettyServerCustomizer.java   
@Override
public void customize(Server server) {
    Handler[] childHandlersByClass = server.getChildHandlersByClass(WebAppContext.class);
    final WebAppContext webAppContext = (WebAppContext) childHandlersByClass[0];

    try {
        ClassPathResource classPathResource = new ClassPathResource(this.jettyProperties.getClassPathResource());
        webAppContext.setBaseResource(new ResourceCollection(classPathResource.getURI().toString()));

        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            @Override
            public Void run() {
                webAppContext.setClassLoader(new URLClassLoader(new URL[0], this.getClass().getClassLoader()));
                return null;
            }
        });

        log.info("Setting Jetty classLoader to {} directory", this.jettyProperties.getClassPathResource());
    }
    catch (IOException exception) {
        log.error("Unable to configure Jetty classLoader to {} directory {}", this.jettyProperties.getClassPathResource(), exception.getMessage());

        throw new RuntimeException(exception);
    }
}
项目:MMServerEngine    文件:PlayerRequestJettyEntrance.java   
@Override
public void start() throws Exception {
    sessionService = BeanHelper.getServiceBean(SessionService.class);
    requestService = BeanHelper.getServiceBean(RequestService.class);
    accountSysService = BeanHelper.getServiceBean(AccountSysService.class);

    Handler entranceHandler = new AbstractHandler(){
        @Override
        public void handle(String target, Request baseRequest,
                           HttpServletRequest request, HttpServletResponse response) throws IOException {
            fire(request,response,"EntranceJetty");
        }
    };

    server = new Server(this.port);
    server.setHandler(entranceHandler);
    server.start();
}
项目:Camel    文件:JettyHttpComponent.java   
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);
    if (Server.getVersion().startsWith("8")) {
        context.getClass().getMethod("setConnectorNames", new Class[] {String[].class})
            .invoke(context, new Object[] {new String[] {connector.getName()}});
    }

    addJettyHandlers(server, handlers);

    CamelServlet camelServlet = new CamelContinuationServlet();
    ServletHolder holder = new ServletHolder();
    holder.setServlet(camelServlet);
    holder.setAsyncSupported(true);
    holder.setInitParameter(CamelServlet.ASYNC_PARAM, Boolean.toString(endpoint.isAsync()));
    context.addServlet(holder, "/*");

    // use rest enabled resolver in case we use rest
    camelServlet.setServletResolveConsumerStrategy(new HttpRestServletResolveConsumerStrategy());

    return camelServlet;
}
项目:app-runner-router    文件:RouterHandlerList.java   
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    Handler[] handlers = getHandlers();
    if (handlers!=null && isStarted())
    {

        if (target.startsWith("/api/") && !AppsCallAggregator.canHandle(target, request)) {
            boolean isLocalRestRequest = target.startsWith("/api/v1/runners") || target.startsWith("/api/v1/system");
            Handler h = isLocalRestRequest ? restService : reverseProxy;
            h.handle(target, baseRequest, request, response);
            if (baseRequest.isHandled()) {
                return;
            }
        }

        for (Handler handler : handlers) {
            handler.handle(target, baseRequest, request, response);
            if (baseRequest.isHandled()) {
                return;
            }
        }

    }
}
项目:incubator-pulsar    文件:ServerManager.java   
public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);

    server.start();

    log.info("Server started at end point {}", getServiceUri());
}
项目:incubator-pulsar    文件:ProxyServer.java   
public void start() throws PulsarServerException {
    log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(TimeZone.getDefault().getID());
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);

        server.start();
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
项目:incubator-pulsar    文件:WebService.java   
public void start() throws PulsarServerException {
    try {
        RequestLogHandler requestLogHandler = new RequestLogHandler();
        Slf4jRequestLog requestLog = new Slf4jRequestLog();
        requestLog.setExtended(true);
        requestLog.setLogTimeZone(TimeZone.getDefault().getID());
        requestLog.setLogLatency(true);
        requestLogHandler.setRequestLog(requestLog);
        handlers.add(0, new ContextHandlerCollection());
        handlers.add(requestLogHandler);

        ContextHandlerCollection contexts = new ContextHandlerCollection();
        contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
        server.setHandler(handlerCollection);

        server.start();

        log.info("Web Service started at {}", pulsar.getWebServiceAddress());
    } catch (Exception e) {
        throw new PulsarServerException(e);
    }
}
项目:incubator-pulsar    文件:WebServer.java   
public void start() throws Exception {
    RequestLogHandler requestLogHandler = new RequestLogHandler();
    Slf4jRequestLog requestLog = new Slf4jRequestLog();
    requestLog.setExtended(true);
    requestLog.setLogTimeZone(TimeZone.getDefault().getID());
    requestLog.setLogLatency(true);
    requestLogHandler.setRequestLog(requestLog);
    handlers.add(0, new ContextHandlerCollection());
    handlers.add(requestLogHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));

    HandlerCollection handlerCollection = new HandlerCollection();
    handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
    server.setHandler(handlerCollection);

    server.start();

    log.info("Server started at end point {}", getServiceUri());
}
项目:stepic-java-web-service    文件:Main.java   
public static void main(String[] args) throws Exception {
    AccountService accountService = new AccountService();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.addServlet(new ServletHolder(new SingUpServlet(accountService)), "/signup");
    context.addServlet(new ServletHolder(new SignInServlet(accountService)), "/signin");

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setResourceBase("public_html");

    HandlerList handlers = new HandlerList();
    final Handler[] handler = {resource_handler, context};
    handlers.setHandlers(handler);

    Server server = new Server(8080);
    server.setHandler(handlers);

    server.start();
    System.out.println("Server started");
    server.join();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JettyEmbeddedServletContainerFactoryTests.java   
@Test
public void wrappedHandlers() throws Exception {
    JettyEmbeddedServletContainerFactory factory = getFactory();
    factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() {
        @Override
        public void customize(Server server) {
            Handler handler = server.getHandler();
            HandlerWrapper wrapper = new HandlerWrapper();
            wrapper.setHandler(handler);
            HandlerCollection collection = new HandlerCollection();
            collection.addHandler(wrapper);
            server.setHandler(collection);
        }
    }));
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();
    assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
}
项目:hazelcast-jetty-sessionmanager    文件:HazelcastSessionIdManager.java   
public void invalidateAll(String sessionId) {
    synchronized (sessionsIds) {
        sessionsIds.remove(sessionId);

        //tell all contexts that may have a session object with this id to
        //get rid of them
        Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
        for (int i = 0; contexts != null && i < contexts.length; i++) {
            SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
            if (sessionHandler != null) {
                SessionManager manager = sessionHandler.getSessionManager();
                if (manager != null && manager instanceof HazelcastSessionManager) {
                    ((HazelcastSessionManager) manager).invalidateSession(sessionId);
                }
            }
        }
    }
}
项目:hazelcast-jetty-sessionmanager    文件:HazelcastSessionIdManager.java   
@Override
public void renewSessionId(String oldClusterId, String oldNodeId, HttpServletRequest request) {
    //generate a new id
    String newClusterId = newSessionId(request.hashCode());

    synchronized (sessionsIds) {
        //remove the old one from the list
        sessionsIds.remove(oldClusterId);
        //add in the new session id to the list
        sessionsIds.add(newClusterId);

        //tell all contexts to update the id
        Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
        for (int i = 0; contexts != null && i < contexts.length; i++) {
            SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
            if (sessionHandler != null) {
                SessionManager manager = sessionHandler.getSessionManager();

                if (manager != null && manager instanceof HazelcastSessionManager) {
                    ((HazelcastSessionManager) manager).
                            renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request));
                }
            }
        }
    }
}
项目:hazelcast-jetty-sessionmanager    文件:HazelcastSessionIdManager.java   
@Override
public void invalidateAll(String sessionId) {
    synchronized (sessionsIds) {
        sessionsIds.remove(sessionId);

        //tell all contexts that may have a session object with this id to
        //get rid of them
        Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
        for (int i = 0; contexts != null && i < contexts.length; i++) {
            SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
            if (sessionHandler != null) {
                SessionManager manager = sessionHandler.getSessionManager();
                if (manager != null && manager instanceof HazelcastSessionManager) {
                    ((HazelcastSessionManager) manager).invalidateSession(sessionId);
                }
            }
        }
    }
}
项目:apt-graph    文件:FileServer.java   
/**
 * Start the file server (blocking).
 *
 * @throws Exception If server cannot start
 */
public final void start() throws Exception {
    LOGGER.info("Starting web interface at http://localhost:8000");

    Server server = new Server(8000);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[]{"index.html"});
    resource_handler.setResourceBase("../website");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(
            new Handler[]{
                resource_handler,
                new DefaultHandler()});
    server.setHandler(handlers);

    server.start();
}
项目:little_mitm    文件:PerformanceServer.java   
public void run(int port) throws Exception {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(port);
    server.addConnector(connector);

    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });

    resource_handler.setResourceBase("./performance/site/");

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler,
            new DefaultHandler() });
    server.setHandler(handlers);

    server.start();
    System.out.println("Started performance file server at port: " + port);
    server.join();
}
项目:Learning    文件:EmbeddedServer.java   
public static void main( String[] args )
    throws Exception
{
    Server server = new Server( 8080 );

    WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/jaxrs" );

    ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
    webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
    HandlerCollection handlers = new HandlerCollection();
    handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );

    server.setHandler( handlers );


    server.start();
    server.join();
}
项目:Camel    文件:WebsocketComponent.java   
protected ServletContextHandler createContext(Server server, Connector connector, List<Handler> handlers) throws Exception {
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    server.addConnector(connector);

    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);
            }
        }
    }

    return context;
}
项目:spring-boot-concourse    文件:JettyEmbeddedServletContainerFactoryTests.java   
@Test
public void wrappedHandlers() throws Exception {
    JettyEmbeddedServletContainerFactory factory = getFactory();
    factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() {
        @Override
        public void customize(Server server) {
            Handler handler = server.getHandler();
            HandlerWrapper wrapper = new HandlerWrapper();
            wrapper.setHandler(handler);
            HandlerCollection collection = new HandlerCollection();
            collection.addHandler(wrapper);
            server.setHandler(collection);
        }
    }));
    this.container = factory
            .getEmbeddedServletContainer(exampleServletRegistration());
    this.container.start();
    assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World");
}
项目:jbake-rtl-jalaali    文件:JettyServer.java   
/**
 * Run Jetty web server serving out supplied path on supplied port
 * 
 * @param path
 * @param port
 */
public void run(String path, String port) {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
       connector.setPort(Integer.parseInt(port));
       server.addConnector(connector);

       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[]{ "index.html" });

       resource_handler.setResourceBase(path);

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
       server.setHandler(handlers);

       LOGGER.info("Serving out contents of: [{}] on http://localhost:{}/", path, port);
       LOGGER.info("(To stop server hit CTRL-C)");

       try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:jetty-reactive-httpclient    文件:Usage.java   
public void prepare(Handler handler) throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    connector = new ServerConnector(server);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();

    QueuedThreadPool clientThreads = new QueuedThreadPool();
    clientThreads.setName("client");
    httpClient = new HttpClient();
    httpClient.setExecutor(clientThreads);
    httpClient.start();
}