Search in sources :

Example 1 with WebSocketToStandardExtensionAdapter

use of org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter in project spring-framework by spring-projects.

the class AbstractStandardUpgradeStrategy method upgrade.

@Override
public void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<WebSocketExtension> selectedExtensions, 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(javax.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)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Extension (javax.websocket.Extension)1 HttpHeaders (org.springframework.http.HttpHeaders)1 WebSocketExtension (org.springframework.web.socket.WebSocketExtension)1 StandardWebSocketHandlerAdapter (org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter)1 StandardWebSocketSession (org.springframework.web.socket.adapter.standard.StandardWebSocketSession)1 WebSocketToStandardExtensionAdapter (org.springframework.web.socket.adapter.standard.WebSocketToStandardExtensionAdapter)1 HandshakeFailureException (org.springframework.web.socket.server.HandshakeFailureException)1