本文整理汇总了Java中javax.websocket.server.HandshakeRequest.getHttpSession方法的典型用法代码示例。如果您正苦于以下问题:Java HandshakeRequest.getHttpSession方法的具体用法?Java HandshakeRequest.getHttpSession怎么用?Java HandshakeRequest.getHttpSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.websocket.server.HandshakeRequest
的用法示例。
在下文中一共展示了HandshakeRequest.getHttpSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
super.modifyHandshake(config, request, response);
if (httpSession == null) {
LOGGER.info("httpSession == null after modifyHandshake");
httpSession = (HttpSession) request.getHttpSession();
}
if (httpSession == null) {
LOGGER.info("httpSession == null");
return;
}
config.getUserProperties().put("httpSession", httpSession);
httpSession = (HttpSession) request.getHttpSession();
LOGGER.info("modifyHandshake " + httpSession.getId());
}
示例2: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
Map<String, List<String>> headers = request.getHeaders();
if (headers != null && headers.containsKey(WatcherSecurityKey.HTTP_HEADER)) {
List<String> header = headers.get(WatcherSecurityKey.HTTP_HEADER);
if (header.size() > 0) {
config.getUserProperties().put(WatcherSecurityKey.HTTP_HEADER, header.
get(0));
}
}
HttpSession httpSession = (HttpSession) request.getHttpSession();
String user = request.getUserPrincipal().getName();
config.getUserProperties().put("httpSession", httpSession);
config.getUserProperties().put("user", user);
logger.log(Level.INFO, "Hand shake for upgrade to websocket by: {0}", user);
}
示例3: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
/**
* Intercept the handshake operation so that we can take a hold of the
* ServletContext instance to be able to retrieve attributes stored to it
* such as the database object and other similar class instances
* <p/>
* @param config
* @param request
* @param response
*/
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
ServletContext context = (ServletContext) httpSession.getServletContext();
config.getUserProperties().put("httpSession", httpSession);
config.getUserProperties().put("user", request.getUserPrincipal().getName());
/*
* store these attributes to servletContext so that they are available to
* every created user socket session
*/
config.getUserProperties().put("protocol", context.getAttribute("protocol"));
}
示例4: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig sec,
HandshakeRequest request, HandshakeResponse response)
{
HttpSession httpSession = (HttpSession) request.getHttpSession();
sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
}
示例5: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
if (null != httpSession) {
config.getUserProperties().put(HttpSession.class.getName(), httpSession);
}
}
示例6: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
final HttpSession httpSession = (HttpSession) request.getHttpSession();
if (request.getUserPrincipal() == null) {
return;
}
final SecurityContext securityCtx = new WebSocketSecurityContext(request);
sec.getUserProperties().put(key(httpSession.getId()), securityCtx);
}
示例7: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(final ServerEndpointConfig config,
final HandshakeRequest request, final HandshakeResponse response) {
final HttpSession httpSession = (HttpSession) request.getHttpSession();
config.getUserProperties().put(HttpSession.class.getName(), httpSession);
}
示例8: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) {
HttpSession session = (HttpSession) request.getHttpSession();
if (null != session) {
config.getUserProperties().put("demo", 1L);
}
}
示例9: createConfigurator
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
private Configurator createConfigurator() {
return new Configurator() {
@Override
public void modifyHandshake(
ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
super.modifyHandshake(sec, request, response);
final HttpSession httpSession = (HttpSession) request.getHttpSession();
if (httpSession != null) {
sec.getUserProperties().put(HTTP_SESSION_ATTRIBUTE, httpSession);
}
sec.getUserProperties().put(SECURITY_CONTEXT, createSecurityContext(request));
sec.getUserProperties().put(ENVIRONMENT_CONTEXT, EnvironmentContext.getCurrent());
}
};
}
示例10: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
config.getUserProperties()
.put(HttpSession.class.getName(), httpSession);
}
示例11: setContext
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
/**
*
* @param request
*/
void setContext(HandshakeRequest request) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
ThreadLocalContextHolder.put(Constants.HTTPSESSION, httpSession);
if(null == httpSession.getAttribute(Constants.LOCALE)) {
httpSession.setAttribute(Constants.LOCALE, getLocale(request));
}
}
示例12: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request,
HandshakeResponse response)
{
HttpSession httpSession = (HttpSession)request.getHttpSession();
config.getUserProperties().put(HttpSession.class.getName(),httpSession);
}
示例13: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
@Override
public void modifyHandshake(final ServerEndpointConfig config,
final HandshakeRequest request,
final HandshakeResponse response) {
final HttpSession httpSession = (HttpSession) request.getHttpSession();
config.getUserProperties().put(HTTP_SESSION_KEY, httpSession);
}
示例14: fromRequest
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
public static HandshakeRequestData fromRequest(HandshakeRequest request) {
HandshakeRequestData data = new HandshakeRequestData();
data.setParameters(request.getParameterMap());
data.setHeaders(request.getHeaders());
data.setRequestUri(request.getRequestURI());
if (request.getHttpSession() instanceof HttpSession) {
data.setHttpSession((HttpSession) request.getHttpSession());
}
//data.initSession(request.getHttpSession());
return data;
}
示例15: modifyHandshake
import javax.websocket.server.HandshakeRequest; //导入方法依赖的package包/类
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
sec.getUserProperties().put(HttpSession.class.getName(), httpSession);
}