use of io.undertow.server.session.PathParameterSessionConfig in project undertow by undertow-io.
the class URLRewritingSessionTestCase method setup.
@BeforeClass
public static void setup() {
final PathParameterSessionConfig sessionConfig = new PathParameterSessionConfig();
final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), sessionConfig);
handler.setNext(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
Session session = manager.getSession(exchange, sessionConfig);
if (session == null) {
session = manager.createSession(exchange, sessionConfig);
session.setAttribute(COUNT, 0);
} else {
Assert.assertEquals("/notamatchingpath;jsessionid=" + session.getId(), exchange.getRequestURI());
}
Integer count = (Integer) session.getAttribute(COUNT);
exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
session.setAttribute(COUNT, ++count);
for (Map.Entry<String, Deque<String>> qp : exchange.getQueryParameters().entrySet()) {
exchange.getResponseHeaders().add(new HttpString(qp.getKey()), qp.getValue().getFirst());
}
if (exchange.getQueryString().isEmpty()) {
exchange.getResponseSender().send(sessionConfig.rewriteUrl(DefaultServer.getDefaultServerURL() + "/notamatchingpath", session.getId()));
} else {
exchange.getResponseSender().send(sessionConfig.rewriteUrl(DefaultServer.getDefaultServerURL() + "/notamatchingpath?" + exchange.getQueryString(), session.getId()));
}
}
});
DefaultServer.setRootHandler(handler);
}
use of io.undertow.server.session.PathParameterSessionConfig in project undertow by undertow-io.
the class ServletContextImpl method initDone.
public void initDone() {
initialized = true;
Set<SessionTrackingMode> trackingMethods = sessionTrackingModes;
SessionConfig sessionConfig = sessionCookieConfig;
if (trackingMethods != null && !trackingMethods.isEmpty()) {
if (sessionTrackingModes.contains(SessionTrackingMode.SSL)) {
sessionConfig = new SslSessionConfig(deployment.getSessionManager());
} else {
if (sessionTrackingModes.contains(SessionTrackingMode.COOKIE) && sessionTrackingModes.contains(SessionTrackingMode.URL)) {
sessionCookieConfig.setFallback(new PathParameterSessionConfig(sessionCookieConfig.getName().toLowerCase(Locale.ENGLISH)));
} else if (sessionTrackingModes.contains(SessionTrackingMode.URL)) {
sessionConfig = new PathParameterSessionConfig(sessionCookieConfig.getName().toLowerCase(Locale.ENGLISH));
}
}
}
SessionConfigWrapper wrapper = deploymentInfo.getSessionConfigWrapper();
if (wrapper != null) {
sessionConfig = wrapper.wrap(sessionConfig, deployment);
}
this.sessionConfig = new ServletContextSessionConfig(sessionConfig);
this.onWritePossibleTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, WriteListener>() {
@Override
public Void call(HttpServerExchange exchange, WriteListener context) throws Exception {
context.onWritePossible();
return null;
}
});
this.runnableTask = new ThreadSetupHandler.Action<Void, Runnable>() {
@Override
public Void call(HttpServerExchange exchange, Runnable context) throws Exception {
context.run();
return null;
}
};
this.onDataAvailableTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ReadListener>() {
@Override
public Void call(HttpServerExchange exchange, ReadListener context) throws Exception {
context.onDataAvailable();
return null;
}
});
this.onAllDataReadTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ReadListener>() {
@Override
public Void call(HttpServerExchange exchange, ReadListener context) throws Exception {
context.onAllDataRead();
return null;
}
});
this.invokeActionTask = deployment.createThreadSetupAction(new ThreadSetupHandler.Action<Void, ThreadSetupHandler.Action<Void, Object>>() {
@Override
public Void call(HttpServerExchange exchange, ThreadSetupHandler.Action<Void, Object> context) throws Exception {
context.call(exchange, null);
return null;
}
});
}
Aggregations