Search in sources :

Example 1 with Hybi13Handshake

use of io.undertow.websockets.core.protocol.version13.Hybi13Handshake in project spring-framework by spring-projects.

the class UndertowRequestUpgradeStrategy method upgrade.

@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, Optional<String> subProtocol) {
    ServerHttpRequest request = exchange.getRequest();
    Assert.isInstanceOf(UndertowServerHttpRequest.class, request, "UndertowServerHttpRequest required");
    HttpServerExchange httpExchange = ((UndertowServerHttpRequest) request).getUndertowExchange();
    Set<String> protocols = subProtocol.map(Collections::singleton).orElse(Collections.emptySet());
    Hybi13Handshake handshake = new Hybi13Handshake(protocols, false);
    List<Handshake> handshakes = Collections.singletonList(handshake);
    URI url = request.getURI();
    HttpHeaders headers = request.getHeaders();
    Mono<Principal> principal = exchange.getPrincipal();
    HandshakeInfo info = new HandshakeInfo(url, headers, principal, subProtocol);
    DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
    try {
        DefaultCallback callback = new DefaultCallback(info, handler, bufferFactory);
        new WebSocketProtocolHandshakeHandler(handshakes, callback).handleRequest(httpExchange);
    } catch (Exception ex) {
        return Mono.error(ex);
    }
    return Mono.empty();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) ServerHttpRequest(org.springframework.http.server.reactive.ServerHttpRequest) UndertowServerHttpRequest(org.springframework.http.server.reactive.UndertowServerHttpRequest) URI(java.net.URI) HttpServerExchange(io.undertow.server.HttpServerExchange) WebSocketProtocolHandshakeHandler(io.undertow.websockets.WebSocketProtocolHandshakeHandler) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) UndertowServerHttpRequest(org.springframework.http.server.reactive.UndertowServerHttpRequest) Principal(java.security.Principal) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo) Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) Handshake(io.undertow.websockets.core.protocol.Handshake)

Example 2 with Hybi13Handshake

use of io.undertow.websockets.core.protocol.version13.Hybi13Handshake in project spring-framework by spring-projects.

the class UndertowRequestUpgradeStrategy method upgrade.

@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory) {
    HttpServerExchange httpExchange = ServerHttpRequestDecorator.getNativeRequest(exchange.getRequest());
    Set<String> protocols = (subProtocol != null ? Collections.singleton(subProtocol) : Collections.emptySet());
    Hybi13Handshake handshake = new Hybi13Handshake(protocols, false);
    List<Handshake> handshakes = Collections.singletonList(handshake);
    HandshakeInfo handshakeInfo = handshakeInfoFactory.get();
    DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
    // Trigger WebFlux preCommit actions and upgrade
    return exchange.getResponse().setComplete().then(Mono.deferContextual(contextView -> {
        DefaultCallback callback = new DefaultCallback(handshakeInfo, ContextWebSocketHandler.decorate(handler, contextView), bufferFactory);
        try {
            new WebSocketProtocolHandshakeHandler(handshakes, callback).handleRequest(httpExchange);
        } catch (Exception ex) {
            return Mono.error(ex);
        }
        return Mono.empty();
    }));
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo) HttpServerExchange(io.undertow.server.HttpServerExchange) Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) RequestUpgradeStrategy(org.springframework.web.reactive.socket.server.RequestUpgradeStrategy) Set(java.util.Set) Mono(reactor.core.publisher.Mono) WebSocketConnectionCallback(io.undertow.websockets.WebSocketConnectionCallback) WebSocketProtocolHandshakeHandler(io.undertow.websockets.WebSocketProtocolHandshakeHandler) Supplier(java.util.function.Supplier) UndertowWebSocketHandlerAdapter(org.springframework.web.reactive.socket.adapter.UndertowWebSocketHandlerAdapter) ServerWebExchange(org.springframework.web.server.ServerWebExchange) List(java.util.List) UndertowWebSocketSession(org.springframework.web.reactive.socket.adapter.UndertowWebSocketSession) WebSocketHttpExchange(io.undertow.websockets.spi.WebSocketHttpExchange) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) Handshake(io.undertow.websockets.core.protocol.Handshake) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) ServerHttpRequestDecorator(org.springframework.http.server.reactive.ServerHttpRequestDecorator) Nullable(org.springframework.lang.Nullable) WebSocketHandler(org.springframework.web.reactive.socket.WebSocketHandler) ContextWebSocketHandler(org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler) Collections(java.util.Collections) Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) WebSocketProtocolHandshakeHandler(io.undertow.websockets.WebSocketProtocolHandshakeHandler) DataBufferFactory(org.springframework.core.io.buffer.DataBufferFactory) HandshakeInfo(org.springframework.web.reactive.socket.HandshakeInfo) Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) Handshake(io.undertow.websockets.core.protocol.Handshake)

Example 3 with Hybi13Handshake

use of io.undertow.websockets.core.protocol.version13.Hybi13Handshake in project undertow by undertow-io.

the class WebSocketServlet method handshakes.

protected List<Handshake> handshakes() {
    List<Handshake> handshakes = new ArrayList<>();
    handshakes.add(new Hybi13Handshake());
    handshakes.add(new Hybi08Handshake());
    handshakes.add(new Hybi07Handshake());
    return handshakes;
}
Also used : Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) ArrayList(java.util.ArrayList) Hybi07Handshake(io.undertow.websockets.core.protocol.version07.Hybi07Handshake) Hybi08Handshake(io.undertow.websockets.core.protocol.version08.Hybi08Handshake) Hybi07Handshake(io.undertow.websockets.core.protocol.version07.Hybi07Handshake) Hybi13Handshake(io.undertow.websockets.core.protocol.version13.Hybi13Handshake) Handshake(io.undertow.websockets.core.protocol.Handshake) Hybi08Handshake(io.undertow.websockets.core.protocol.version08.Hybi08Handshake)

Aggregations

Handshake (io.undertow.websockets.core.protocol.Handshake)3 Hybi13Handshake (io.undertow.websockets.core.protocol.version13.Hybi13Handshake)3 HttpServerExchange (io.undertow.server.HttpServerExchange)2 WebSocketProtocolHandshakeHandler (io.undertow.websockets.WebSocketProtocolHandshakeHandler)2 DataBufferFactory (org.springframework.core.io.buffer.DataBufferFactory)2 HandshakeInfo (org.springframework.web.reactive.socket.HandshakeInfo)2 WebSocketConnectionCallback (io.undertow.websockets.WebSocketConnectionCallback)1 WebSocketChannel (io.undertow.websockets.core.WebSocketChannel)1 Hybi07Handshake (io.undertow.websockets.core.protocol.version07.Hybi07Handshake)1 Hybi08Handshake (io.undertow.websockets.core.protocol.version08.Hybi08Handshake)1 WebSocketHttpExchange (io.undertow.websockets.spi.WebSocketHttpExchange)1 URI (java.net.URI)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)1