本文整理匯總了Java中org.eclipse.jetty.server.session.SessionHandler類的典型用法代碼示例。如果您正苦於以下問題:Java SessionHandler類的具體用法?Java SessionHandler怎麽用?Java SessionHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SessionHandler類屬於org.eclipse.jetty.server.session包,在下文中一共展示了SessionHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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();
}
示例2: getSessionDataStore
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
@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;
}
示例3: setSessionHandler
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
/**
* @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();
}
示例4: insertHandler
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
/**
* 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();
}
示例5: run
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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();
}
示例6: emptyPac4jInConfig
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
@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);
}
示例7: main
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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");
}
示例8: invalidateAll
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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);
}
}
}
}
}
示例9: renewSessionId
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
@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));
}
}
}
}
}
示例10: invalidateAll
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
@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);
}
}
}
}
}
示例11: installListeners
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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()));
});
}
示例12: setupRestApiContextHandler
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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());
}
}
示例13: setWebHttpApiHandler
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
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;
}
示例14: start
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
@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);
}
}
}
示例15: listen
import org.eclipse.jetty.server.session.SessionHandler; //導入依賴的package包/類
@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;
}