Search in sources :

Example 1 with WsSession

use of org.apache.tomcat.websocket.WsSession in project tomcat by apache.

the class WsHttpUpgradeHandler method init.

@Override
public void init(WebConnection connection) {
    if (ep == null) {
        throw new IllegalStateException(sm.getString("wsHttpUpgradeHandler.noPreInit"));
    }
    String httpSessionId = null;
    Object session = handshakeRequest.getHttpSession();
    if (session != null) {
        httpSessionId = ((HttpSession) session).getId();
    }
    // Need to call onOpen using the web application's class loader
    // Create the frame using the application's class loader so it can pick
    // up application specific config from the ServerContainerImpl
    Thread t = Thread.currentThread();
    ClassLoader cl = t.getContextClassLoader();
    t.setContextClassLoader(applicationClassLoader);
    try {
        wsRemoteEndpointServer = new WsRemoteEndpointImplServer(socketWrapper, webSocketContainer);
        wsSession = new WsSession(ep, wsRemoteEndpointServer, webSocketContainer, handshakeRequest.getRequestURI(), handshakeRequest.getParameterMap(), handshakeRequest.getQueryString(), handshakeRequest.getUserPrincipal(), httpSessionId, negotiatedExtensions, subProtocol, pathParameters, secure, endpointConfig);
        wsFrame = new WsFrameServer(socketWrapper, wsSession, transformation, applicationClassLoader);
        // WsFrame adds the necessary final transformations. Copy the
        // completed transformation chain to the remote end point.
        wsRemoteEndpointServer.setTransformation(wsFrame.getTransformation());
        ep.onOpen(wsSession, endpointConfig);
        webSocketContainer.registerSession(ep, wsSession);
    } catch (DeploymentException e) {
        throw new IllegalArgumentException(e);
    } finally {
        t.setContextClassLoader(cl);
    }
}
Also used : DeploymentException(javax.websocket.DeploymentException) WsSession(org.apache.tomcat.websocket.WsSession)

Aggregations

DeploymentException (javax.websocket.DeploymentException)1 WsSession (org.apache.tomcat.websocket.WsSession)1