use of org.eclipse.jetty.server.session.SessionHandler in project camel by apache.
the class WebsocketComponent method createStaticResourcesServer.
protected Server createStaticResourcesServer(Server server, ServletContextHandler context, String home) throws Exception {
context.setContextPath("/");
SessionHandler sh = new SessionHandler();
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")) {
context.setBaseResource(new JettyClassPathResource(getCamelContext().getClassResolver(), resources[1]));
} 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;
}
use of org.eclipse.jetty.server.session.SessionHandler in project dropwizard by dropwizard.
the class ServletEnvironmentTest method setsSessionHandlers.
@Test
public void setsSessionHandlers() throws Exception {
final SessionHandler sessionHandler = mock(SessionHandler.class);
environment.setSessionHandler(sessionHandler);
verify(handler).setSessionHandler(sessionHandler);
verify(handler).setSessionsEnabled(true);
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class OneServletContextWithSession method main.
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
// Create a ServletContext, with a session handler enabled.
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setResourceBase(System.getProperty("java.io.tmpdir"));
server.setHandler(context);
// Access the SessionHandler from the context.
SessionHandler sessions = context.getSessionHandler();
// Explicitly set Session Cache and null Datastore.
// This is normally done by default,
// but is done explicitly here for demonstration.
// If more than one context is to be deployed, it is
// simpler to use SessionCacheFactory and/or
// SessionDataStoreFactory instances set as beans on
// the server.
SessionCache cache = new DefaultSessionCache(sessions);
cache.setSessionDataStore(new NullSessionDataStore());
sessions.setSessionCache(cache);
// Servlet to read/set the greeting stored in the session.
// Can be accessed using http://localhost:8080/hello
context.addServlet(HelloSessionServlet.class, "/");
server.start();
server.join();
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class ResponseTest method testSendRedirect.
@Test
public void testSendRedirect() throws Exception {
String[][] tests = { // No cookie
{ "http://myhost:8888/other/location;jsessionid=12345?name=value", "http://myhost:8888/other/location;jsessionid=12345?name=value" }, { "/other/location;jsessionid=12345?name=value", "http://@HOST@@PORT@/other/location;jsessionid=12345?name=value" }, { "./location;jsessionid=12345?name=value", "http://@HOST@@PORT@/path/location;jsessionid=12345?name=value" }, // From cookie
{ "/other/location", "http://@HOST@@PORT@/other/location" }, { "/other/l%20cation", "http://@HOST@@PORT@/other/l%20cation" }, { "location", "http://@HOST@@PORT@/path/location" }, { "./location", "http://@HOST@@PORT@/path/location" }, { "../location", "http://@HOST@@PORT@/location" }, { "/other/l%20cation", "http://@HOST@@PORT@/other/l%20cation" }, { "l%20cation", "http://@HOST@@PORT@/path/l%20cation" }, { "./l%20cation", "http://@HOST@@PORT@/path/l%20cation" }, { "../l%20cation", "http://@HOST@@PORT@/l%20cation" }, { "../locati%C3%abn", "http://@HOST@@PORT@/locati%C3%abn" }, { "../other%2fplace", "http://@HOST@@PORT@/other%2fplace" }, { "http://somehost.com/other/location", "http://somehost.com/other/location" } };
int[] ports = new int[] { 8080, 80 };
String[] hosts = new String[] { null, "myhost", "192.168.0.1", "0::1" };
for (int port : ports) {
for (String host : hosts) {
for (int i = 0; i < tests.length; i++) {
// System.err.printf("%s %d %s%n",host,port,tests[i][0]);
Response response = getResponse();
Request request = response.getHttpChannel().getRequest();
request.setScheme("http");
if (host != null)
request.setAuthority(host, port);
request.setURIPathQuery("/path/info;param;jsessionid=12345?query=0&more=1#target");
request.setContextPath("/path");
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(i > 2);
SessionHandler handler = new SessionHandler();
NullSessionDataStore ds = new NullSessionDataStore();
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionCache(ss);
ss.setSessionDataStore(ds);
DefaultSessionIdManager idMgr = new DefaultSessionIdManager(_server);
idMgr.setWorkerName(null);
handler.setSessionIdManager(idMgr);
request.setSessionHandler(handler);
request.setSession(new TestSession(handler, "12345"));
handler.setCheckingRemoteSessionIdEncoding(false);
response.sendRedirect(tests[i][0]);
String location = response.getHeader("Location");
String expected = tests[i][1].replace("@HOST@", host == null ? request.getLocalAddr() : (host.contains(":") ? ("[" + host + "]") : host)).replace("@PORT@", host == null ? ":8888" : (port == 80 ? "" : (":" + port)));
assertEquals("test-" + i + " " + host + ":" + port, expected, location);
}
}
}
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class ServerConnectorTimeoutTest method testIdleTimeoutAfterSuspend.
@Test(timeout = 60000)
public void testIdleTimeoutAfterSuspend() throws Exception {
SuspendHandler _handler = new SuspendHandler();
_server.stop();
SessionHandler session = new SessionHandler();
session.setHandler(_handler);
_server.setHandler(session);
_server.start();
_handler.setSuspendFor(100);
_handler.setResumeAfter(25);
assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("RESUMED"));
}
Aggregations