public class ServletAwareConfig extends ServerEndpointConfig.Configurator { @Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties().put("httpSession", httpSession); } }
.headers(headers) .cookies(cookies) .session((HttpSession) handshakeRequest.getHttpSession()) .servletPath(servletPath) .contextPath(framework.getServletContext().getContextPath())
public class ServletAwareConfigurator extends Configurator { @Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties().put("httpSession", httpSession); } }
public class UserAwareConfigurator extends Configurator { @Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); User user = (User) httpSession.getAttribute("user"); config.getUserProperties().put("user", user); } }
/** * Applies the {@link javax.servlet.http.HttpSession} to the configuration. * * @param userInformation * @param handshakeRequest */ private void applyHttpSessionInformation(Map<String, Object> userInformation, HandshakeRequest handshakeRequest) { userInformation.put(HttpSession.class.getName(), handshakeRequest.getHttpSession()); }
/** * Applies the {@link javax.servlet.http.HttpSession} to the configuration. * * @param userInformation * @param handshakeRequest */ private void applyHttpSessionInformation(Map<String, Object> userInformation, HandshakeRequest handshakeRequest) { userInformation.put(HttpSession.class.getName(), handshakeRequest.getHttpSession()); }
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties().put(HttpSession.class.getName(), httpSession); logger.info(httpSession.getId()); } }
@Override public void modifyHandshake( ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); if (httpSession != null) { Object sessionSubject = httpSession.getAttribute("che_subject"); if (sessionSubject != null) { sec.getUserProperties().put("che_subject", sessionSubject); } } } }
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); config.getUserProperties() .put(HttpSession.class.getName(), httpSession); } }
import javax.servlet.http.HttpSession; import javax.websocket.HandshakeResponse; import javax.websocket.server.HandshakeRequest; import javax.websocket.server.ServerEndpointConfig; import javax.websocket.server.ServerEndpointConfig.Configurator; public class ChatRoomEndpointConfigurator extends Configurator { @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(), httpSession); } }
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { //add HttpSession to WebSocketSession so web socket handlers can share session state with regular HTTP requests HttpSession httpSession = (HttpSession) request.getHttpSession(); if(httpSession!=null) { config.getUserProperties().put(HttpSession.class.getName(), httpSession); } } }
/** * 重写修改握手方法 */ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(), httpSession); } }
public class WebsocketEndpointConfigurator extends Configurator{ @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); sec.getUserProperties().put(HttpSession.class.getName(), httpSession); } }
public class CustomConfigurator extends ServerEndpointConfig.Configurator { private HttpSession httpSession; // modifyHandshake() is called before getEndpointInstance()! @Override public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { httpSession = (HttpSession) request.getHttpSession(); super.modifyHandshake(sec, request, response); } @Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { T endpoint = super.getEndpointInstance(endpointClass); if (endpoint instanceof MyServerEndpoint) { // The injection point: ((MyServerEndpoint) endpoint).setHttpSession(httpSession); } else { throw new InstantiationException( MessageFormat.format("Expected instanceof \"{0}\". Got instanceof \"{1}\".", MyServerEndpoint.class, endpoint.getClass())); } return endpoint; } }
private void applyWebsocketFilters(HandshakeRequest handshakeRequest) { if (!filterLookuped) { HttpSession httpSession = ((HttpSession) handshakeRequest.getHttpSession()); final String filterNames = httpSession.getServletContext().getInitParameter(FILTER_PARAM_NAME); if (!StringUtils.isEmpty(filterNames)) { final StringTokenizer filterTokenizer = new StringTokenizer(filterNames, ","); FilterLookup.getInstance().initFilters(filterTokenizer); } filterLookuped = Boolean.TRUE; } }
private void applyWebsocketFilters(HandshakeRequest handshakeRequest) { if (!filterLookuped) { HttpSession httpSession = ((HttpSession) handshakeRequest.getHttpSession()); final String filterNames = httpSession.getServletContext().getInitParameter(FILTER_PARAM_NAME); if (!StringUtils.isEmpty(filterNames)) { final StringTokenizer filterTokenizer = new StringTokenizer(filterNames, ","); FilterLookup.getInstance().initFilters(filterTokenizer); } filterLookuped = Boolean.TRUE; } }
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { HttpSession httpSession = (HttpSession) request.getHttpSession(); org.zkoss.zk.ui.Session sess = SessionsCtrl.getSession(WebApps.getCurrent(), httpSession); config.getUserProperties().put(getClass().getName(), sess); }
private WebSocketContext(ServletContext context, HandshakeRequest request, Map<String, Object> userProperties) { super(context, request.getRequestURI().toString(), request.getQueryString(), request.getHeaders(), request.getParameterMap(), request.getUserPrincipal(), (HttpSession)request.getHttpSession(), // Hopefully these will become a standard, for now they are Jetty specific. (InetSocketAddress)userProperties.get("javax.websocket.endpoint.localAddress"), (InetSocketAddress)userProperties.get("javax.websocket.endpoint.remoteAddress"), WebSocketTransport.retrieveLocales(userProperties), "HTTP/1.1", WebSocketTransport.isSecure(request)); } }
HandshakeResponse response) HttpSession theSession = (HttpSession) request.getHttpSession(); config.getUserProperties().put(HttpSession.class.getName(), theSession);
@Override public void modifyHandshake(ServerEndpointConfig config, HandshakeRequest request, HandshakeResponse response) { // Tomcat websocket impl returns request headers in lowercase ???? String connectMessageId = getHeaderOrParameter(request, "connectId", true); String clientId = getHeaderOrParameter(request, "GDSClientId", true); String clientType = getHeaderOrParameter(request, "GDSClientType", true); HttpSession session = (HttpSession)request.getHttpSession(); log.debug( "WebSocket configurator handshake ackId %s clientId %s sessionId %s", connectMessageId, clientId, session != null ? session.getId() : "(none)" ); Gravity gravity = (Gravity)config.getUserProperties().get("gravity"); if (gravity.getGraniteConfig().getSecurityService() != null) gravity.getGraniteConfig().getSecurityService().prelogin(session, request, null); String ctype = getHeader(request, "Content-Type", true); String protocol = getHeader(request, "Sec-WebSocket-Protocol", true); ContentType contentType = WebSocketUtil.getContentType(ctype, protocol); // Hack using a thread local to be sure that the endpoint gets the correct values // Jetty and GlassFish GravityWebSocketConfig.set(connectMessageId, clientId, clientType, contentType, session); }