下面列出了怎么用org.eclipse.jetty.server.session.HashSessionIdManager的API类实例代码及写法,或者点击链接到github查看源代码。
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
log.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static void createAndStartServer() {
server = new Server(HTTP_SERVER_PORT);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(JPAApplicationConfiguration.class);
applicationContext.refresh();
appContext = applicationContext;
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
log.error("Error starting server", e);
}
}
public static TestServer createAndStartServer(Class<?> ... configClasses) {
int port= NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
log.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
LOGGER.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
LOGGER.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
LOGGER.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
LOGGER.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
LOGGER.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
public static TestServer createAndStartServer(Class<?>... configClasses) {
int port = NEXT_PORT.incrementAndGet();
Server server = new Server(port);
HashSessionIdManager idmanager = new HashSessionIdManager();
server.setSessionIdManager(idmanager);
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
applicationContext.register(configClasses);
applicationContext.refresh();
try {
server.setHandler(getServletContextHandler(applicationContext));
server.start();
} catch (Exception e) {
LOGGER.error("Error starting server", e);
}
return new TestServer(server, applicationContext, port);
}
/**
* Starts a Jetty server with D2R Server as root webapp.
*
* @return <code>true</code> on success, <code>false</code> if webapp init failed
*/
public boolean start() {
Server jetty = new Server(port);
// use Random (/dev/urandom) instead of SecureRandom to generate session keys - otherwise Jetty may hang during startup waiting for enough entropy
// see http://jira.codehaus.org/browse/JETTY-331 and http://docs.codehaus.org/display/JETTY/Connectors+slow+to+startup
jetty.setSessionIdManager(new HashSessionIdManager(new Random()));
WebAppContext context = new WebAppContext(jetty, "webapp", "");
// Wave a chicken at Jetty to make some annoying System.err.println noise go away
context.getSecurityHandler().setIdentityService(new DefaultIdentityService());
context.getSecurityHandler().setAuthenticator(null);
context.getSecurityHandler().setAuthenticatorFactory(null);
// Place the system loader into the servlet context. The webapp init
// listener will find it there and create the D2RServer instance.
D2RServer.storeSystemLoader(loader, context.getServletContext());
try {
jetty.start();
D2RServer server = D2RServer.fromServletContext(context.getServletContext());
if (server == null || server.errorOnStartup()) {
jetty.stop();
log.warn("[[[ Server startup failed, see messages above ]]]");
return false;
}
log.info("[[[ Server started at " + loader.getSystemBaseURI() + " ]]]");
return true;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}