本文整理汇总了Java中io.undertow.servlet.handlers.ServletRequestContext.current方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequestContext.current方法的具体用法?Java ServletRequestContext.current怎么用?Java ServletRequestContext.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.servlet.handlers.ServletRequestContext
的用法示例。
在下文中一共展示了ServletRequestContext.current方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forSession
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
public static HttpSessionImpl forSession(final Session session, final ServletContext servletContext, final boolean newSession) {
// forSession is called by privileged actions only so no need to do it again
ServletRequestContext current = ServletRequestContext.current();
if (current == null) {
return new HttpSessionImpl(session, servletContext, newSession, null);
} else {
HttpSessionImpl httpSession = current.getSession();
if (httpSession == null) {
httpSession = new HttpSessionImpl(session, servletContext, newSession, current);
current.setSession(httpSession);
} else {
if(httpSession.session != session) {
//in some rare cases it may be that there are two different service contexts involved in the one request
//in this case we just return a new session rather than using the thread local version
httpSession = new HttpSessionImpl(session, servletContext, newSession, current);
}
}
return httpSession;
}
}
示例2: currentServletRequestContext
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
static ServletRequestContext currentServletRequestContext() {
if (System.getSecurityManager() == null) {
return ServletRequestContext.current();
} else {
return AccessController.doPrivileged(new PrivilegedAction<ServletRequestContext>() {
@Override
public ServletRequestContext run() {
return ServletRequestContext.current();
}
});
}
}
示例3: getCurrentSessionId
import io.undertow.servlet.handlers.ServletRequestContext; //导入方法依赖的package包/类
private String getCurrentSessionId(HttpServerExchange exchange) {
if (exchange == null && ServletRequestContext.current() != null) {
exchange = ServletRequestContext.current().getExchange();
}
if (exchange == null) return null;
Cookie sessionCookie = exchange.getRequestCookies().get("JSESSIONID");
if (sessionCookie == null) return null;
return sessionCookie.getValue();
}