本文整理汇总了Java中org.eclipse.jetty.servlet.ServletContextHandler.setSessionHandler方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContextHandler.setSessionHandler方法的具体用法?Java ServletContextHandler.setSessionHandler怎么用?Java ServletContextHandler.setSessionHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.servlet.ServletContextHandler
的用法示例。
在下文中一共展示了ServletContextHandler.setSessionHandler方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的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");
}
示例2: enableSessionSupport
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
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);
}
}
}
示例3: setupNotebookServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
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;
}
示例4: setupRestApiContextHandler
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
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;
}
示例5: createStaticResourcesServer
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
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;
}
示例6: start
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void start() {
System.setProperty("java.net.preferIPv4Stack", "true");//TODO optional?
server = new org.eclipse.jetty.server.Server();
// HashSessionIdManager sessionIdManager = new HashSessionIdManager();
// server.setSessionIdManager(sessionIdManager);
connector = new NetworkTrafficServerConnector(server);
connector.setPort(httpPort);
connector.setHost(host);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler();
SessionHandler sessionHandler = new SessionHandler();
// HashSessionManager sessionManager = new HashSessionManager();
// sessionManager.setMaxInactiveInterval(sessionTimeoutS);
// sessionManager.setSessionCookie(sessionManager.getSessionCookie()+httpPort); //avoid session mix up for 2 server running as localhost
// sessionHandler.setSessionManager(sessionManager);
contextHandler.setSessionHandler(sessionHandler);
contextHandler.addServlet(new ServletHolder(new ServletContainer(jerseySetup(restResource))), "/applicationServer/*");
ErrorHandler errorHandler = new ErrorHandler();
errorHandler.setShowStacks(true);
contextHandler.setErrorHandler(errorHandler);
GzipHandler gzipHandler = new GzipHandler();
// HashSet<String> mimeTypes = new HashSet<>();
// mimeTypes.add("text/html");
// mimeTypes.add("text/plain");
// mimeTypes.add("text/css");
// mimeTypes.add("application/x-javascript");
// mimeTypes.add("application/json");
gzipHandler.setMinGzipSize(0);
// gzipHandler.setMimeTypes(mimeTypes);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[]{resourceHandler, contextHandler});
gzipHandler.setHandler(handlers);
server.setHandler(gzipHandler);
try {
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: createServletForConnector
import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
protected CometDServlet createServletForConnector(Server server, Connector connector, CometdEndpoint endpoint) throws Exception {
CometDServlet servlet = new CometDServlet();
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
ServletHolder holder = new ServletHolder();
holder.setServlet(servlet);
holder.setAsyncSupported(true);
// Use baseResource to pass as a parameter the url
// pointing to by example classpath:webapp
if (endpoint.getBaseResource() != null) {
String[] resources = endpoint.getBaseResource().split(":");
if (LOG.isDebugEnabled()) {
LOG.debug(">>> Protocol found: " + resources[0] + ", and resource: " + resources[1]);
}
if (resources[0].equals("file")) {
context.setBaseResource(Resource.newResource(resources[1]));
} else if (resources[0].equals("classpath")) {
// Create a URL handler using classpath protocol
URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);
context.setBaseResource(Resource.newResource(url));
}
}
applyCrossOriginFiltering(endpoint, context);
context.addServlet(holder, "/cometd/*");
context.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/");
context.setSessionHandler(new SessionHandler(new HashSessionManager()));
holder.setInitParameter("timeout", Integer.toString(endpoint.getTimeout()));
holder.setInitParameter("interval", Integer.toString(endpoint.getInterval()));
holder.setInitParameter("maxInterval", Integer.toString(endpoint.getMaxInterval()));
holder.setInitParameter("multiFrameInterval", Integer.toString(endpoint.getMultiFrameInterval()));
holder.setInitParameter("JSONCommented", Boolean.toString(endpoint.isJsonCommented()));
holder.setInitParameter("logLevel", Integer.toString(endpoint.getLogLevel()));
return servlet;
}