Search in sources :

Example 11 with SessionHandler

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

the class ServletContextHandler method setSessionHandler.

/* ------------------------------------------------------------ */
/**
     * @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();
}
Also used : Handler(org.eclipse.jetty.server.Handler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) GzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler)

Example 12 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project qi4j-sdk by Qi4j.

the class AbstractJettyMixin method startJetty.

@Override
public final void startJetty() throws Exception {
    // Configure Server
    configureServer(server, configuration());
    // Set up HTTP
    HttpConfiguration httpConfig = new HttpConfiguration();
    configureHttp(httpConfig, configuration());
    httpConfig = specializeHttp(httpConfig);
    // Set up connector
    ServerConnector connector = buildConnector(server, httpConfig);
    configureConnector(connector, configuration());
    // Bind Connector to Server
    server.addConnector(connector);
    if (mBeanServer != null) {
        server.addEventListener(new MBeanContainer(mBeanServer));
    }
    // Prepare ServletContext
    ServletContextHandler root = new ServletContextHandler(server, "/", new SessionHandler(), buildSecurityHandler(), new ServletHandler(), new ErrorHandler());
    root.setDisplayName(identity);
    configureContext(root, configuration());
    // Register ContextListeners, Servlets and Filters
    addContextListeners(root, contextListeners);
    addServlets(root, servlets);
    addFilters(root, filters);
    // Start
    server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 13 with SessionHandler

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

the class JettyServer method persistSession.

private void persistSession(WebAppContext webApp) {
    String storeDir = getStoreDir();
    SessionManager sm = webApp.getSessionHandler().getSessionManager();
    if (sm instanceof HashSessionManager) {
        ((HashSessionManager) sm).setStoreDirectory(new File(storeDir));
        return;
    }
    HashSessionManager hsm = new HashSessionManager();
    hsm.setStoreDirectory(new File(storeDir));
    SessionHandler sh = new SessionHandler();
    sh.setSessionManager(hsm);
    webApp.setSessionHandler(sh);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) SessionManager(org.eclipse.jetty.server.SessionManager) File(java.io.File)

Example 14 with SessionHandler

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

the class JettyServerForIDEA method persistSession.

private void persistSession(WebAppContext webApp) {
    String storeDir = getStoreDir();
    SessionManager sm = webApp.getSessionHandler().getSessionManager();
    if (sm instanceof HashSessionManager) {
        ((HashSessionManager) sm).setStoreDirectory(new File(storeDir));
        return;
    }
    HashSessionManager hsm = new HashSessionManager();
    hsm.setStoreDirectory(new File(storeDir));
    SessionHandler sh = new SessionHandler();
    sh.setSessionManager(hsm);
    webApp.setSessionHandler(sh);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager) SessionManager(org.eclipse.jetty.server.SessionManager) File(java.io.File)

Example 15 with SessionHandler

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

the class Jetty9WebServer method loadStaticContent.

private void loadStaticContent(SessionManager sm, String mountPoint) {
    String contentLocation = staticContent.get(mountPoint);
    try {
        SessionHandler sessionHandler = new SessionHandler(sm);
        sessionHandler.setServer(getJetty());
        final WebAppContext staticContext = new WebAppContext();
        staticContext.setServer(getJetty());
        staticContext.setContextPath(mountPoint);
        staticContext.setSessionHandler(sessionHandler);
        staticContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        URL resourceLoc = getClass().getClassLoader().getResource(contentLocation);
        if (resourceLoc != null) {
            URL url = resourceLoc.toURI().toURL();
            final Resource resource = Resource.newResource(url);
            staticContext.setBaseResource(resource);
            addFiltersTo(staticContext);
            staticContext.addFilter(new FilterHolder(new NoCacheHtmlFilter()), "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD));
            handlers.addHandler(staticContext);
        } else {
            log.warn("No static content available for Neo Server at %s, management console may not be available.", jettyAddress);
        }
    } catch (Exception e) {
        log.error("Unknown error loading static content", e);
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Resource(org.eclipse.jetty.util.resource.Resource) URL(java.net.URL) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) PortBindException(org.neo4j.helpers.PortBindException) BindException(java.net.BindException) IOException(java.io.IOException)

Aggregations

SessionHandler (org.eclipse.jetty.server.session.SessionHandler)43 Server (org.eclipse.jetty.server.Server)13 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 IOException (java.io.IOException)8 ServletException (javax.servlet.ServletException)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)5 File (java.io.File)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpSession (javax.servlet.http.HttpSession)4 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)4 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 BeforeClass (org.junit.BeforeClass)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)3 LocalConnector (org.eclipse.jetty.server.LocalConnector)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 SessionManager (org.eclipse.jetty.server.SessionManager)3