本文整理汇总了Java中org.eclipse.jetty.webapp.WebAppContext.setSessionHandler方法的典型用法代码示例。如果您正苦于以下问题:Java WebAppContext.setSessionHandler方法的具体用法?Java WebAppContext.setSessionHandler怎么用?Java WebAppContext.setSessionHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.webapp.WebAppContext
的用法示例。
在下文中一共展示了WebAppContext.setSessionHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@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;
}
示例2: configure
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@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;
}
示例3: run
import org.eclipse.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static Server run(ResourceConfig application, Properties properties, int port, String originFilter,
String aliasName, File keystoreFile, String password, String frontendRoot, String apiPathPattern, boolean copyWebDir) {
try {
QueuedThreadPool threadPool = new QueuedThreadPool(
Integer.valueOf(properties.getProperty("jetty.maxThreads")),
Integer.valueOf(properties.getProperty("jetty.minThreads")),
Integer.valueOf(properties.getProperty("jetty.idleTimeout")),
new ArrayBlockingQueue<>(Integer.valueOf(properties.getProperty("jetty.maxQueueSize"))));
Server server = new Server(threadPool);
HttpConfiguration config = new HttpConfiguration();
if (keystoreFile != null) {
log.info("Jetty runner {}. SSL enabled.", application.getClass());
SslContextFactory sslFactory = new SslContextFactory();
sslFactory.setCertAlias(aliasName);
String path = keystoreFile.getAbsolutePath();
if (!keystoreFile.exists()) {
log.error("Couldn't load keystore file: {}", path);
return null;
}
sslFactory.setKeyStorePath(path);
sslFactory.setKeyStorePassword(password);
sslFactory.setKeyManagerPassword(password);
sslFactory.setTrustStorePath(path);
sslFactory.setTrustStorePassword(password);
config.setSecureScheme("https");
config.setSecurePort(port);
config.addCustomizer(new SecureRequestCustomizer());
ServerConnector https = new ServerConnector(server,
new SslConnectionFactory(sslFactory, "http/1.1"),
new HttpConnectionFactory(config));
https.setPort(port);
server.setConnectors(new Connector[]{https});
} else {
ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(config));
http.setPort(port);
server.setConnectors(new Connector[]{http});
}
Handler handler = ContainerFactory.createContainer(JettyHttpContainer.class, application);
if (originFilter != null)
handler = new CrossDomainFilter(handler, originFilter);
if (frontendRoot != null) {
WebAppContext htmlHandler = new WebAppContext();
htmlHandler.setResourceBase(frontendRoot);
htmlHandler.setCopyWebDir(copyWebDir);
Map<Pattern, Handler> pathToHandler = new HashMap<>();
pathToHandler.put(Pattern.compile(apiPathPattern), handler);
SessionManager sm = new HashSessionManager();
SessionHandler sh = new SessionHandler(sm);
htmlHandler.setSessionHandler(sh);
DefaultServlet defaultServlet = new DefaultServlet();
ServletHolder holder = new ServletHolder(defaultServlet);
holder.setInitParameter("useFileMappedBuffer", Boolean.toString(!copyWebDir));
holder.setInitParameter("cacheControl", "no-store,no-cache,must-revalidate,max-age=-1,public");
htmlHandler.addServlet(holder, "/");
handler = new RequestsRouter(htmlHandler, pathToHandler, frontendRoot);
}
server.setHandler(handler);
server.start();
while (!server.isStarted()) {
Thread.sleep(50);
}
log.info("Jetty server started {} on port {}", application.getClass(), port);
return server;
} catch (Exception e) {
log.error(String.format("Jetty start failed %s.", application.getClass()), e);
return null;
}
}