本文整理汇总了Java中io.undertow.server.session.SessionManager.createSession方法的典型用法代码示例。如果您正苦于以下问题:Java SessionManager.createSession方法的具体用法?Java SessionManager.createSession怎么用?Java SessionManager.createSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.session.SessionManager
的用法示例。
在下文中一共展示了SessionManager.createSession方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSession
import io.undertow.server.session.SessionManager; //导入方法依赖的package包/类
public HttpSessionImpl getSession(final ServletContextImpl originalServletContext, final HttpServerExchange exchange, boolean create) {
SessionConfig c = originalServletContext.getSessionConfig();
HttpSessionImpl httpSession = exchange.getAttachment(sessionAttachmentKey);
if (httpSession != null && httpSession.isInvalid()) {
exchange.removeAttachment(sessionAttachmentKey);
httpSession = null;
}
if (httpSession == null) {
final SessionManager sessionManager = deployment.getSessionManager();
Session session = sessionManager.getSession(exchange, c);
if (session != null) {
httpSession = SecurityActions.forSession(session, this, false);
exchange.putAttachment(sessionAttachmentKey, httpSession);
} else if (create) {
String existing = c.findSessionId(exchange);
if (originalServletContext != this) {
//this is a cross context request
//we need to make sure there is a top level session
originalServletContext.getSession(originalServletContext, exchange, true);
} else if (existing != null) {
c.clearSession(exchange, existing);
}
final Session newSession = sessionManager.createSession(exchange, c);
httpSession = SecurityActions.forSession(newSession, this, true);
exchange.putAttachment(sessionAttachmentKey, httpSession);
}
}
return httpSession;
}
示例2: getOrCreateSession
import io.undertow.server.session.SessionManager; //导入方法依赖的package包/类
/**
* Gets the active session, creating a new one if one does not exist
* @param exchange The exchange
* @return The session
*/
public static Session getOrCreateSession(final HttpServerExchange exchange) {
SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
if(sessionManager == null) {
throw UndertowMessages.MESSAGES.sessionManagerNotFound();
}
Session session = sessionManager.getSession(exchange, sessionConfig);
if(session == null) {
session = sessionManager.createSession(exchange, sessionConfig);
}
return session;
}