Java 类org.eclipse.jetty.server.session.SessionHandler 实例源码

项目:pinto    文件:Demo.java   
public void run() throws Exception {
    org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
    Server server = new Server(port);
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
       context.setContextPath("/");
       context.setWelcomeFiles(new String[]{ "demo.html" });
       context.setResourceBase(httpPath);
       HashSessionIdManager idmanager = new HashSessionIdManager();
       server.setSessionIdManager(idmanager);
       HashSessionManager manager = new HashSessionManager();
       SessionHandler sessions = new SessionHandler(manager);
       sessions.setHandler(context);
       context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
       ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
       context.addServlet(holderPwd,"/*");
       server.setHandler(sessions);
       server.start();
       server.join();
}
项目:jetty-dynomite    文件:DynomiteSessionDataStoreFactory.java   
@Override
   public SessionDataStore getSessionDataStore(SessionHandler sessionHandler) throws Exception {
CustomHostSupplier hostSupplier = new CustomHostSupplier();

ConnectionPoolConfigurationImpl config = new ConnectionPoolConfigurationImpl("AppivoConfig");

for (String host : hosts) {
    hostSupplier.addHost(host, port, "");
}

DynoJedisClient client = new DynoJedisClient.Builder()
        .withApplicationName(app)
        .withDynomiteClusterName(cluster)
        .withHostSupplier(hostSupplier)
        .withCPConfig(config)
        .build();

DynomiteSessionDataStore store = new DynomiteSessionDataStore(client);

return store;
   }
项目: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   
/**
 * Insert a HandlerWrapper before the first Session,Security or ServletHandler
 * but after any other HandlerWrappers.
 */
public void insertHandler(HandlerWrapper handler)
{
    HandlerWrapper h=this;

    // Skip any injected handlers
    while (h.getHandler() instanceof HandlerWrapper)
    {
        HandlerWrapper wrapper = (HandlerWrapper)h.getHandler();
        if (wrapper instanceof SessionHandler ||
            wrapper instanceof SecurityHandler ||
            wrapper instanceof ServletHandler)
            break;
        h=wrapper;
    }

    h.setHandler(handler);
    relinkHandlers();
}
项目:pinto    文件:Main.java   
public void run() throws Exception {

        org.eclipse.jetty.util.log.Log.setLog(new Slf4jLog());
        Server server = new Server(port);
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setContextPath("/");
        context.setResourceBase(httpPath);
        HashSessionIdManager idmanager = new HashSessionIdManager();
        server.setSessionIdManager(idmanager);
        HashSessionManager manager = new HashSessionManager();
        SessionHandler sessions = new SessionHandler(manager);
        sessions.setHandler(context);
        context.addServlet(new ServletHolder(new Servlet(this::getPinto)),"/pinto/*");
        ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
        context.addServlet(holderPwd,"/*");
        server.setHandler(sessions);
        new Thread(new Console(getPinto(),port,build, () -> {
            try {
                server.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }), "console_thread").start();
        server.start();
        server.join();
    }
项目:dropwizard-pac4j    文件:BundleFactoryTest.java   
@Test
public void emptyPac4jInConfig() {
    setup(App.class, "empty-pac4j.yaml");

    App app = dropwizardTestSupport.getApplication();
    ObjectMapper om = dropwizardTestSupport.getObjectMapper();
    Environment env = dropwizardTestSupport.getEnvironment();

    Config config = app.bundle.getConfig();
    assertThat(config).isNotNull();
    // this is the default url resolver!
    assertThat(config.getClients().getUrlResolver())
            .isInstanceOf(JaxRsUrlResolver.class);
    assertThat(om.findMixInClassFor(Client.class)).isNotNull();
    assertThat(env.jersey().getResourceConfig().getSingletons())
            .haveAtLeastOne(CONDSI);

    assertThat(env.getApplicationContext().getSessionHandler())
            .isInstanceOf(SessionHandler.class);
}
项目:electron-java-app    文件:Launcher.java   
public static void main(String[] args) {
    log.info("Server starting...");

    Server embeddedServer = new Server(8080);

    ServletContextHandler contextHandler = new ServletContextHandler(null, "/", true, false);
    embeddedServer.setHandler(contextHandler);

    SessionHandler sessions = new SessionHandler();
    contextHandler.setSessionHandler(sessions);

    ServletHolder servletHolder = new ServletHolder(AppServlet.class);
    contextHandler.addServlet(servletHolder, "/*");

    try {
        embeddedServer.start();
        embeddedServer.join();
    } catch (Exception e) {
        log.error("Server error:\n", e);
    }

    log.info("Server stopped");
}
项目: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);
                }
            }
        }
    }
}
项目: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);
                }
            }
        }
    }
}
项目:bootique-jetty    文件:ServerFactory.java   
protected void installListeners(ServletContextHandler handler, Set<MappedListener> listeners) {

        if (listeners.isEmpty()) {
            return;
        }

        Optional<SessionHandler> sessionHandler = sessions
                ? Optional.of(handler.getSessionHandler()) : Optional.empty();

        sortedListeners(listeners).forEach(listener -> {

            LOGGER.info("Adding listener {}", listener.getListener().getClass().getName());

            // context handler and session handler would do their own listener filtering
            // passing every listener down to them without trying to second guess
            handler.addEventListener(listener.getListener());
            sessionHandler.ifPresent(sh -> sh.addEventListener(listener.getListener()));
        });
    }
项目:zeppelin    文件:ZeppelinServer.java   
private static void setupRestApiContextHandler(WebAppContext webapp,
                                               ZeppelinConfiguration conf) {

  final ServletHolder servletHolder = new ServletHolder(
          new org.glassfish.jersey.servlet.ServletContainer());

  servletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName());
  servletHolder.setName("rest");
  servletHolder.setForcedPath("rest");

  webapp.setSessionHandler(new SessionHandler());
  webapp.addServlet(servletHolder, "/api/*");

  String shiroIniPath = conf.getShiroPath();
  if (!StringUtils.isBlank(shiroIniPath)) {
    webapp.setInitParameter("shiroConfigLocations", new File(shiroIniPath).toURI().toString());
    SecurityUtils.setIsEnabled(true);
    webapp.addFilter(ShiroFilter.class, "/api/*", EnumSet.allOf(DispatcherType.class))
            .setInitParameter("staticSecurityManagerEnabled", "true");
    webapp.addEventListener(new EnvironmentLoaderListener());
  }
}
项目:scouter    文件:WebAppMain.java   
private static ServletContextHandler setWebHttpApiHandler () {
    ConfigureAdaptor conf = ConfigureManager.getConfigure();

    String providerPackages = "scouterx.webapp";
    if (conf.isNetHttpApiSwaggerEnabled()) {
        providerPackages += ",io.swagger.jaxrs.listing";
    }

    final ServletHolder jerseyHolder = new ServletHolder(ServletContainer.class);
    jerseyHolder.setInitParameter("javax.ws.rs.Application", "scouterx.webapp.main.WebAppMain");
    jerseyHolder.setInitParameter("jersey.config.server.provider.packages", providerPackages);
    jerseyHolder.setInitOrder(1);

    final ServletContextHandler servletContextHandler = new ServletContextHandler();
    servletContextHandler.setSessionHandler(new SessionHandler());
    servletContextHandler.getSessionHandler().setMaxInactiveInterval(conf.getNetHttpApiSessionTimeout());
    servletContextHandler.setContextPath("/");

    servletContextHandler.addServlet(jerseyHolder, "/scouter/*");
    servletContextHandler.addServlet(setStaticContentHandler(), "/*");
    servletContextHandler.addServlet(setSwaggerBootstrapHandler(), "/swagger");

    addFilter(servletContextHandler);

    return servletContextHandler;
}
项目:dropwizard-guicey    文件:SessionListenersSupport.java   
@Override
public void start() throws Exception {
    for (MutableServletContextHandler environment : listeners.keySet()) {
        final SessionHandler sessionHandler = environment.getSessionHandler();
        if (sessionHandler == null) {
            final String msg = String.format(
                    "Can't register session listeners for %s because sessions support is not enabled: %s",
                    environment.getDisplayName().toLowerCase(),
                    Joiner.on(',').join(listeners.get(environment).stream()
                            .map(it -> FeatureUtils.getInstanceClass(it).getSimpleName())
                            .collect(Collectors.toList())));
            if (failWithoutSession) {
                throw new IllegalStateException(msg);
            } else {
                logger.warn(msg);
            }
        } else {
            listeners.get(environment).forEach(sessionHandler::addEventListener);
        }
    }
}
项目:pipes    文件:JettyHttpServer.java   
@Override
public HttpServer listen(int port) throws Exception {

    SessionHandler sessionHandler = new SessionHandler(app.configuration(SessionManager.class));
    sessionHandler.setHandler(new MiddlewareHandler(app));

    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setResourceBase(".");
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setHandler(sessionHandler);

    Server server = new Server(port);

    server.setSessionIdManager(new HashSessionIdManager());
    server.setHandler(context);

    server.start();
    server.join();

    return this;
}
项目:Explorer    文件:ExplorerServer.java   
/**
 * Swagger core handler - Needed for the RestFul api documentation
 *
 * @return ServletContextHandler of Swagger
 */
private static ServletContextHandler setupSwaggerContextHandler(int port) {
    // Configure Swagger-core
    final ServletHolder SwaggerServlet = new ServletHolder(
            new com.wordnik.swagger.jersey.config.JerseyJaxrsConfig());
    SwaggerServlet.setName("JerseyJaxrsConfig");
    SwaggerServlet.setInitParameter("api.version", "1.0.0");
    SwaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:" + port + "/api");
    SwaggerServlet.setInitOrder(2);

    // Setup the handler
    final ServletContextHandler handler = new ServletContextHandler();
    handler.setSessionHandler(new SessionHandler());
    handler.addServlet(SwaggerServlet, "/api-docs/*");
    return handler;
}
项目:dw-shiro-bundle    文件:ShiroBundle.java   
private void initializeShiro(final ShiroConfiguration config, Environment environment) {
    if (config.isEnabled()) {
        LOG.debug("Shiro is enabled");

        if (config.isDropwizardSessionHandler() && environment.getApplicationContext().getSessionHandler() == null) {
            LOG.debug("Adding DropWizard SessionHandler to environment.");
            environment.getApplicationContext().setSessionHandler(new SessionHandler());
        }

        // This line ensure Shiro is configured and its .ini file found in the designated location.
        // e.g., via the shiroConfigLocations ContextParameter with fall-backs to default locations if that parameter isn't specified.
        environment.servlets().addServletListeners( new EnvironmentLoaderListener() );

        final String filterUrlPattern = config.getSecuredUrlPattern();
        LOG.debug("ShiroFilter will check URLs matching '{}'.", filterUrlPattern);
        environment.servlets().addFilter("shiro-filter", new ShiroFilter()).addMappingForUrlPatterns( EnumSet.allOf(DispatcherType.class), true, filterUrlPattern );
    } else {
        LOG.debug("Shiro is not enabled");
    }
}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler,int options)
{
    super((ContextHandler.Context)null);
    _options=options;
    _scontext = new Context();
    _sessionHandler = sessionHandler;
    _securityHandler = securityHandler;
    _servletHandler = servletHandler;

    if (contextPath!=null)
        setContextPath(contextPath);

    if (parent instanceof HandlerWrapper)
        ((HandlerWrapper)parent).setHandler(this);
    else if (parent instanceof HandlerCollection)
        ((HandlerCollection)parent).addHandler(this);


    // Link the handlers
    relinkHandlers();

    if (errorHandler!=null)
        setErrorHandler(errorHandler);


    this.addFilter(new FilterHolder(new HTTPAuthFilter()), "/v2/*", EnumSet.allOf(DispatcherType.class));

}
项目:marathon-auth-plugin    文件:ServletContextHandler.java   
/**
 * @return Returns the sessionHandler.
 */
@ManagedAttribute(value="context session handler", readonly=true)
public SessionHandler getSessionHandler()
{
    if (_sessionHandler==null && (_options&SESSIONS)!=0 && !isStarted())
        _sessionHandler=newSessionHandler();
    return _sessionHandler;
}
项目:beyondj    文件:JettyHttpComponent.java   
private void enableSessionSupport(Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    if (context.getSessionHandler() == null) {
        SessionHandler sessionHandler = new SessionHandler();
        if (context.isStarted()) {
            throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey);
        } else {
            context.setSessionHandler(sessionHandler);
        }
    }
}
项目:hazelcast-jetty-sessionmanager    文件:JettyConfigurator.java   
@Override
public Server configure() throws Exception {
    Server server = new Server(port);

    WebAppContext context = new WebAppContext();
    context.setResourceBase("../jetty-core/src/test/resources/" + appName);
    context.setLogUrlOnStart(true);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);

    HazelcastSessionIdManager idManager = new HazelcastSessionIdManager(server, clientOnly);
    idManager.setWorkerName("worker-" + port);
    server.setSessionIdManager(idManager);

    HazelcastSessionManager sessionManager = new HazelcastSessionManager();
    sessionManager.setSessionIdManager(idManager);

    SessionHandler handler = new SessionHandler(sessionManager);
    context.setSessionHandler(handler);

    server.setHandler(context);
    server.setStopTimeout(0);

    HashLoginService loginService = new HashLoginService();
    loginService.putUser("someuser", Credential.getCredential("somepass"), new String[]{"role1", "role2"});
    context.getSecurityHandler().setLoginService(loginService);

    return server;
}
项目:hazelcast-jetty-sessionmanager    文件:JettyConfigurator.java   
@Override
public Server configure() throws Exception {
    Server server = new Server(port);

    WebAppContext context = new WebAppContext();
    context.setResourceBase("../jetty-core/src/test/resources/" + appName);
    context.setLogUrlOnStart(true);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);

    HazelcastSessionIdManager idManager = new HazelcastSessionIdManager(server, clientOnly);

    idManager.setWorkerName("worker-" + port);
    server.setSessionIdManager(idManager);

    HazelcastSessionManager sessionManager = new HazelcastSessionManager();
    sessionManager.setSessionIdManager(idManager);

    SessionHandler handler = new SessionHandler(sessionManager);
    context.setSessionHandler(handler);

    server.setHandler(context);
    server.setGracefulShutdown(0);

    HashLoginService loginService = new HashLoginService();
    loginService.putUser("someuser", Credential.getCredential("somepass"), new String[]{"role1", "role2"});
    context.getSecurityHandler().setLoginService(loginService);

    return server;
}
项目:hazelcast-jetty-sessionmanager    文件:JettyConfigurator.java   
@Override
public Server configure() throws Exception {
    Server server = new Server(port);

    WebAppContext context = new WebAppContext();
    context.setResourceBase("../jetty-core/src/test/resources/" + appName);
    context.setLogUrlOnStart(true);
    context.setContextPath("/");
    context.setParentLoaderPriority(true);

    HazelcastSessionIdManager idManager = new HazelcastSessionIdManager(server, clientOnly);

    idManager.setWorkerName("worker-" + port);
    server.setSessionIdManager(idManager);

    HazelcastSessionManager sessionManager = new HazelcastSessionManager();
    sessionManager.setSessionIdManager(idManager);

    SessionHandler handler = new SessionHandler(sessionManager);
    context.setSessionHandler(handler);

    server.setHandler(context);
    server.setGracefulShutdown(0);

    HashLoginService loginService = new HashLoginService();
    loginService.putUser("someuser", Credential.getCredential("somepass"), new String[]{"role1", "role2"});
    context.getSecurityHandler().setLoginService(loginService);

    return server;
}
项目:flowable-engine    文件:TestServerUtil.java   
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;
}
项目:flowable-engine    文件:BaseJPARestTestCase.java   
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;
}
项目:flowable-engine    文件:TestServerUtil.java   
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;
}
项目:flowable-engine    文件:TestServerUtil.java   
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;
}
项目:incubator-zeppelin-druid    文件:ZeppelinServer.java   
private static ServletContextHandler setupNotebookServer(ZeppelinConfiguration conf) {
  notebookWsServer = new NotebookServer();
  final ServletHolder servletHolder = new ServletHolder(notebookWsServer);
  servletHolder.setInitParameter("maxTextMessageSize", "1024000");

  final ServletContextHandler cxfContext = new ServletContextHandler(
      ServletContextHandler.SESSIONS);

  cxfContext.setSessionHandler(new SessionHandler());
  cxfContext.setContextPath(conf.getServerContextPath());
  cxfContext.addServlet(servletHolder, "/ws/*");
  cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*",
      EnumSet.allOf(DispatcherType.class));
  return cxfContext;
}
项目:incubator-zeppelin-druid    文件:ZeppelinServer.java   
private static ServletContextHandler setupRestApiContextHandler(ZeppelinConfiguration conf) {
  final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
  cxfServletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName());
  cxfServletHolder.setName("rest");
  cxfServletHolder.setForcedPath("rest");

  final ServletContextHandler cxfContext = new ServletContextHandler();
  cxfContext.setSessionHandler(new SessionHandler());
  cxfContext.setContextPath(conf.getServerContextPath());
  cxfContext.addServlet(cxfServletHolder, "/api/*");

  cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*",
      EnumSet.allOf(DispatcherType.class));
  return cxfContext;
}
项目:Camel    文件:JettyHttpComponent.java   
private void enableSessionSupport(Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    if (context.getSessionHandler() == null) {
        SessionHandler sessionHandler = new SessionHandler();
        if (context.isStarted()) {
            throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey);
        } else {
            context.setSessionHandler(sessionHandler);
        }
    }
}
项目:Camel    文件:WebsocketComponent.java   
protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {

        context.setContextPath("/");

        SessionManager sm = new HashSessionManager();
        SessionHandler sh = new SessionHandler(sm);
        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")) {
                // Does not work when deployed as a bundle
                // context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
                URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
                context.setBaseResource(Resource.newResource(url));
            } 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;
    }
项目:Camel    文件:WebsocketComponent.java   
private void enableSessionSupport(Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    if (context.getSessionHandler() == null) {
        SessionHandler sessionHandler = new SessionHandler();
        if (context.isStarted()) {
            throw new IllegalStateException("Server has already been started. Cannot enabled sessionSupport on " + connectorKey);
        } else {
            context.setSessionHandler(sessionHandler);
        }
    }
}
项目:soabase    文件:AdminConsoleApp.java   
@Override
public final void run(T configuration, Environment environment) throws Exception
{
    environment.jersey().register(DiscoveryResource.class);
    environment.jersey().register(AttributesResource.class);
    environment.jersey().register(PreferencesResource.class);

    environment.jersey().register(AuthResource.class);
    AbstractBinder binder = new AbstractBinder()
    {
        @Override
        protected void configure()
        {
            AuthSpecHolder holder = new AuthSpecHolder(builder.getAuthSpec());
            bind(holder).to(AuthSpecHolder.class);
        }
    };
    environment.jersey().register(binder);
    if ( builder.getAuthSpec() != null )
    {
        environment.servlets().setSessionHandler(new SessionHandler());
    }

    ComponentManager componentManager = SoaBundle.getFeatures(environment).getNamed(ComponentManager.class, SoaFeatures.DEFAULT_NAME);
    for ( TabComponent component : componentManager.getTabs() )
    {
        int index = 0;
        for ( AssetsPath assetsPath : component.getAssetsPaths() )
        {
            AssetServlet servlet = new AssetServlet(assetsPath.getResourcePath(), assetsPath.getUriPath(), null, Charsets.UTF_8);
            environment.servlets().addServlet(component.getName() + index++, servlet).addMapping(assetsPath.getUriPath() + '*');
        }
    }

}
项目:keycloak-dropwizard-integration    文件:KeycloakBundle.java   
@Override
public void run(T configuration, Environment environment) throws Exception {

    /* setup the authenticator in front of the requests to allow for pre-auth integration */
    // tag::authenticator[]
    KeycloakJettyAuthenticator keycloak = new KeycloakDropwizardAuthenticator();
    keycloak.setAdapterConfig(getKeycloakConfiguration(configuration));
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    environment.getApplicationContext().setSecurityHandler(securityHandler);
    environment.getApplicationContext().getSecurityHandler().setAuthenticator(keycloak);
    // end::authenticator[]

    // tag::authfactory[]
    environment.jersey().register(new AuthDynamicFeature(
            createAuthFactory(configuration)));
    // To use @RolesAllowed annotations
    environment.jersey().register(RolesAllowedDynamicFeature.class);
    // To use @Auth to inject a custom Principal type into your resource
    environment.jersey().register(new AuthValueFactoryProvider.Binder<>(getUserClass()));
    // end::authfactory[]

    if (getKeycloakConfiguration(configuration).isBearerOnly()) {
        // no session needed
    } else if (getKeycloakConfiguration(configuration).getTokenStore() != null &&
            getKeycloakConfiguration(configuration).getTokenStore().toLowerCase(Locale.ENGLISH)
                    .equals(TokenStore.COOKIE.toString().toLowerCase(Locale.ENGLISH))) {
        // no session needed
    } else {
        // allow (stateful) sessions in Dropwizard
        environment.jersey().register(HttpSessionFactory.class);
        environment.servlets().setSessionHandler(new SessionHandler());
    }
}
项目:datacollector    文件:WebServerTask.java   
private ServletContextHandler configureRootContext(SessionHandler sessionHandler) {
  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);

  context.setSessionHandler(sessionHandler);

  context.setContextPath("/");
  for (ContextConfigurator cc : contextConfigurators) {
    cc.init(context);
  }
  return context;
}
项目:varOne    文件:VarOneServer.java   
private static ServletContextHandler setupResourcesContextHandler(
        VarOneConfiguration conf) {
    final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    cxfServletHolder.setInitParameter("javax.ws.rs.Application", VarOneServer.class.getName());
    cxfServletHolder.setName("rest");
    cxfServletHolder.setForcedPath("rest");

    final ServletContextHandler cxfContext = new ServletContextHandler();
    cxfContext.setSessionHandler(new SessionHandler());
    cxfContext.setContextPath(conf.getServerContextPath());
    cxfContext.addServlet(cxfServletHolder, "/rest/*");

    return cxfContext;
}
项目:nano-framework    文件:AbstractSessionIdManager.java   
private void forEachSessionManager(final SessionManagerCallback callback) {
    Handler[] contexts = server.getChildHandlersByClass(ContextHandler.class);
    for (int i = 0; contexts != null && i < contexts.length; i++) {
        final SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class);
        if (sessionHandler != null) {
            final SessionManager manager = sessionHandler.getSessionManager();
            if (manager != null && manager instanceof AbstractSessionManager) {
                callback.execute((AbstractSessionManager) manager);
            }
        }
    }
}
项目:nano-framework    文件:JettyCustomServer.java   
protected void applySessionHandler(final WebAppContext webapp) {
    final String jettyCluster = context.getProperty(JettyRedisSession.JETTY_CLUSTER);
    if (StringUtils.isNotBlank(jettyCluster)) {
        setSessionIdManager(createRedisSessionIdManager(jettyCluster));
        webapp.setSessionHandler(new SessionHandler(createRedisSessionManager(jettyCluster)));
    }
}
项目:orchidae    文件:Starter.java   
private ServletContextHandler getServletContextHandler( AnnotationConfigWebApplicationContext context )
    throws IOException
{
    ServletContextHandler servletContext = new ServletContextHandler();
    servletContext.addEventListener( new ContextLoaderListener( context ) );
    ServletHolder holder = new ServletHolder( "default", new DispatcherServlet( context ) );
    holder.getRegistration()
        .setMultipartConfig( new MultipartConfigElement( "./tmp", 20000000, 20000000, 200000 ) );
    servletContext.addServlet( holder, "/*" );
    servletContext.addEventListener( new ServletListener( context ) );
    servletContext.setResourceBase( new FileSystemResource( new File( "./" ) ).toString() );
    servletContext.setSessionHandler( new SessionHandler() );
    return servletContext;
}