Search in sources :

Example 11 with Extension

use of jakarta.websocket.Extension in project spring-framework by spring-projects.

the class AbstractStandardUpgradeStrategy method upgrade.

@Override
public void upgrade(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<WebSocketExtension> selectedExtensions, @Nullable Principal user, WebSocketHandler wsHandler, Map<String, Object> attrs) throws HandshakeFailureException {
    HttpHeaders headers = request.getHeaders();
    InetSocketAddress localAddr = null;
    try {
        localAddr = request.getLocalAddress();
    } catch (Exception ex) {
    // Ignore
    }
    InetSocketAddress remoteAddr = null;
    try {
        remoteAddr = request.getRemoteAddress();
    } catch (Exception ex) {
    // Ignore
    }
    StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr, user);
    StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session);
    List<Extension> extensions = new ArrayList<>();
    for (WebSocketExtension extension : selectedExtensions) {
        extensions.add(new WebSocketToStandardExtensionAdapter(extension));
    }
    upgradeInternal(request, response, selectedProtocol, extensions, endpoint);
}
Also used : Extension(jakarta.websocket.Extension) WebSocketExtension(org.springframework.web.socket.WebSocketExtension) HttpHeaders(org.springframework.http.HttpHeaders) WebSocketExtension(org.springframework.web.socket.WebSocketExtension) StandardWebSocketHandlerAdapter(org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter) StandardWebSocketSession(org.springframework.web.socket.adapter.standard.StandardWebSocketSession) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) HandshakeFailureException(org.springframework.web.socket.server.HandshakeFailureException) WebSocketToStandardExtensionAdapter(org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter)

Example 12 with Extension

use of jakarta.websocket.Extension in project spring-framework by spring-projects.

the class StandardWebSocketSession method initializeNativeSession.

@Override
public void initializeNativeSession(Session session) {
    super.initializeNativeSession(session);
    this.uri = session.getRequestURI();
    this.acceptedProtocol = session.getNegotiatedSubprotocol();
    List<Extension> standardExtensions = getNativeSession().getNegotiatedExtensions();
    if (!CollectionUtils.isEmpty(standardExtensions)) {
        this.extensions = new ArrayList<>(standardExtensions.size());
        for (Extension standardExtension : standardExtensions) {
            this.extensions.add(new StandardToWebSocketExtensionAdapter(standardExtension));
        }
        this.extensions = Collections.unmodifiableList(this.extensions);
    } else {
        this.extensions = Collections.emptyList();
    }
    if (this.user == null) {
        this.user = session.getUserPrincipal();
    }
}
Also used : Extension(jakarta.websocket.Extension) WebSocketExtension(org.springframework.web.socket.WebSocketExtension)

Aggregations

Extension (jakarta.websocket.Extension)12 ArrayList (java.util.ArrayList)10 Endpoint (jakarta.websocket.Endpoint)3 Parameter (jakarta.websocket.Extension.Parameter)3 URI (java.net.URI)3 List (java.util.List)3 ClientEndpoint (jakarta.websocket.ClientEndpoint)2 ClientEndpointConfig (jakarta.websocket.ClientEndpointConfig)2 DeploymentException (jakarta.websocket.DeploymentException)2 InetSocketAddress (java.net.InetSocketAddress)2 Transformation (org.apache.tomcat.websocket.Transformation)2 WebSocketExtension (org.springframework.web.socket.WebSocketExtension)2 ServletException (jakarta.servlet.ServletException)1 EndpointConfig (jakarta.websocket.EndpointConfig)1 HandshakeResponse (jakarta.websocket.HandshakeResponse)1 Session (jakarta.websocket.Session)1 WebSocketContainer (jakarta.websocket.WebSocketContainer)1 ServerEndpoint (jakarta.websocket.server.ServerEndpoint)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1