Search in sources :

Example 46 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project camel by apache.

the class WebsocketComponent method createStaticResourcesServer.

protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {
    context.setContextPath("/");
    SessionHandler sh = new SessionHandler();
    context.setSessionHandler(sh);
    if (home != null) {
        String[] resources = home.split(":");
        if (LOG.isDebugEnabled()) {
            LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
        }
        if (resources[0].equals("classpath")) {
            context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
        } else if (resources[0].equals("file")) {
            context.setBaseResource(Resource.newResource(resources[1]));
        }
        DefaultServlet defaultServlet = new DefaultServlet();
        ServletHolder holder = new ServletHolder(defaultServlet);
        // avoid file locking on windows
        // http://stackoverflow.com/questions/184312/how-to-make-jetty-dynamically-load-static-pages
        holder.setInitParameter("useFileMappedBuffer", "false");
        context.addServlet(holder, "/");
    }
    server.setHandler(context);
    return server;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 47 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project Activiti by Activiti.

the class TestServerUtil method getServletContextHandler.

private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    WebConfigurer configurer = new WebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);
    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);
    return contextHandler;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) WebConfigurer(org.activiti.rest.WebConfigurer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 48 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project Activiti by Activiti.

the class BaseJPARestTestCase method getServletContextHandler.

private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
    ServletContextHandler contextHandler = new ServletContextHandler();
    JPAWebConfigurer configurer = new JPAWebConfigurer();
    configurer.setContext(context);
    contextHandler.addEventListener(configurer);
    // Create the SessionHandler (wrapper) to handle the sessions
    HashSessionManager manager = new HashSessionManager();
    SessionHandler sessions = new SessionHandler(manager);
    contextHandler.setHandler(sessions);
    return contextHandler;
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) JPAWebConfigurer(org.activiti.rest.JPAWebConfigurer) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 49 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project camel by apache.

the class HttpProducerSessionTest method initServer.

@BeforeClass
public static void initServer() throws Exception {
    port = AvailablePortFinder.getNextAvailable(24000);
    localServer = new Server(new InetSocketAddress("127.0.0.1", port));
    ContextHandler contextHandler = new ContextHandler();
    contextHandler.setContextPath("/session");
    SessionHandler sessionHandler = new SessionHandler();
    sessionHandler.setHandler(new SessionReflectionHandler());
    contextHandler.setHandler(sessionHandler);
    localServer.setHandler(contextHandler);
    localServer.start();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) SessionReflectionHandler(org.apache.camel.component.http4.handler.SessionReflectionHandler) BeforeClass(org.junit.BeforeClass)

Example 50 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project felix by apache.

the class JettyService method configureSessionManager.

private void configureSessionManager(final ServletContextHandler context) throws Exception {
    final SessionHandler sessionHandler = context.getSessionHandler();
    sessionHandler.setMaxInactiveInterval(this.config.getSessionTimeout() * 60);
    sessionHandler.setSessionIdPathParameterName(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_ID_PATH_PARAMETER_NAME, SessionHandler.__DefaultSessionIdPathParameterName));
    sessionHandler.setCheckingRemoteSessionIdEncoding(this.config.getBooleanProperty(JettyConfig.FELIX_JETTY_SERVLET_CHECK_REMOTE_SESSION_ENCODING, true));
    sessionHandler.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
    final SessionCookieConfig cookieConfig = sessionHandler.getSessionCookieConfig();
    cookieConfig.setName(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_COOKIE_NAME, SessionHandler.__DefaultSessionCookie));
    cookieConfig.setDomain(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_DOMAIN, SessionHandler.__DefaultSessionDomain));
    cookieConfig.setPath(this.config.getProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_PATH, context.getContextPath()));
    cookieConfig.setMaxAge(this.config.getIntProperty(JettyConfig.FELIX_JETTY_SERVLET_SESSION_MAX_AGE, -1));
    cookieConfig.setHttpOnly(this.config.getBooleanProperty(JettyConfig.FELIX_JETTY_SESSION_COOKIE_HTTP_ONLY, true));
    cookieConfig.setSecure(this.config.getBooleanProperty(JettyConfig.FELIX_JETTY_SESSION_COOKIE_SECURE, false));
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) SessionCookieConfig(javax.servlet.SessionCookieConfig)

Aggregations

SessionHandler (org.eclipse.jetty.server.session.SessionHandler)70 Server (org.eclipse.jetty.server.Server)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)17 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)13 IOException (java.io.IOException)10 Test (org.junit.Test)9 ServletException (javax.servlet.ServletException)8 HttpSession (javax.servlet.http.HttpSession)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)8 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Handler (org.eclipse.jetty.server.Handler)5 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)5 ArrayList (java.util.ArrayList)4 SessionCookieConfig (javax.servlet.SessionCookieConfig)4 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)4 HttpSessionListener (javax.servlet.http.HttpSessionListener)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)4