ReactorNettyWebSocketSession implements close properly
Issue: SPR-16774
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.springframework.web.reactive.socket.adapter;
|
||||
|
||||
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
import reactor.ipc.netty.NettyInbound;
|
||||
import reactor.ipc.netty.NettyOutbound;
|
||||
import reactor.ipc.netty.NettyPipeline;
|
||||
@@ -42,6 +44,8 @@ import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
public class ReactorNettyWebSocketSession
|
||||
extends NettyWebSocketSessionSupport<ReactorNettyWebSocketSession.WebSocketConnection> {
|
||||
|
||||
private final MonoProcessor<WebSocketFrame> closeMono = MonoProcessor.create();
|
||||
|
||||
|
||||
public ReactorNettyWebSocketSession(WebsocketInbound inbound, WebsocketOutbound outbound,
|
||||
HandshakeInfo info, NettyDataBufferFactory bufferFactory) {
|
||||
@@ -69,11 +73,8 @@ public class ReactorNettyWebSocketSession
|
||||
|
||||
@Override
|
||||
public Mono<Void> close(CloseStatus status) {
|
||||
return Mono.error(new UnsupportedOperationException(
|
||||
"Reactor Netty does not support closing the session from anywhere. " +
|
||||
"You will need to work with the Flux returned from receive() method, " +
|
||||
"either subscribing to it and using the returned Disposable, " +
|
||||
"or using an operator that cancels (e.g. take)."));
|
||||
WebSocketFrame closeFrame = new CloseWebSocketFrame(status.getCode(), status.getReason());
|
||||
return getDelegate().getOutbound().sendObject(closeFrame).then();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user