Browse Source
The WebSocketHander adapters are now neutral for client vs server-side use with the adapters for RxNetty and Reactor Netty (server-side only) completely removed. A new HandshakeInfo carries information about the handshake including URI, headers, and principal from the upgrade strategy, to the adapter, and then to the session. WebSocketSession exposes the HandshakeInfo as well reducing its overall number of methods.pull/1274/head
21 changed files with 224 additions and 196 deletions
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
/* |
||||
* Copyright 2002-2016 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.web.reactive.socket.adapter; |
||||
|
||||
import java.net.URI; |
||||
import java.security.Principal; |
||||
|
||||
import reactor.core.publisher.Mono; |
||||
|
||||
import org.springframework.http.HttpHeaders; |
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* Simple container of information from a WebSocket handshake request. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 5.0 |
||||
*/ |
||||
public class HandshakeInfo { |
||||
|
||||
private final URI uri; |
||||
|
||||
private final HttpHeaders headers; |
||||
|
||||
private final Mono<Principal> principal; |
||||
|
||||
|
||||
public HandshakeInfo(URI uri, HttpHeaders headers, Mono<Principal> principal) { |
||||
Assert.notNull(uri, "URI is required."); |
||||
Assert.notNull(headers, "HttpHeaders are required."); |
||||
Assert.notNull(principal, "Prinicpal is required."); |
||||
this.uri = uri; |
||||
this.headers = headers; |
||||
this.principal = principal; |
||||
} |
||||
|
||||
|
||||
public URI getUri() { |
||||
return this.uri; |
||||
} |
||||
|
||||
public HttpHeaders getHeaders() { |
||||
return this.headers; |
||||
} |
||||
|
||||
public Mono<Principal> getPrincipal() { |
||||
return this.principal; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "HandshakeInfo[uri=" + this.uri + ", headers=" + this.headers + "]"; |
||||
} |
||||
|
||||
} |
||||
@ -1,53 +0,0 @@
@@ -1,53 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2016 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.web.reactive.socket.adapter; |
||||
|
||||
import java.util.function.BiFunction; |
||||
|
||||
import org.reactivestreams.Publisher; |
||||
import reactor.ipc.netty.http.websocket.WebsocketInbound; |
||||
import reactor.ipc.netty.http.websocket.WebsocketOutbound; |
||||
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest; |
||||
import org.springframework.http.server.reactive.ServerHttpResponse; |
||||
import org.springframework.web.reactive.socket.WebSocketHandler; |
||||
|
||||
/** |
||||
* Reactor Netty {@code WebSocketHandler} implementation adapting and |
||||
* delegating to a Spring {@link WebSocketHandler}. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 5.0 |
||||
*/ |
||||
public class ReactorNettyWebSocketHandlerAdapter extends WebSocketHandlerAdapterSupport |
||||
implements BiFunction<WebsocketInbound, WebsocketOutbound, Publisher<Void>> { |
||||
|
||||
|
||||
public ReactorNettyWebSocketHandlerAdapter(ServerHttpRequest request, ServerHttpResponse response, |
||||
WebSocketHandler handler) { |
||||
|
||||
super(request, response, handler); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Publisher<Void> apply(WebsocketInbound inbound, WebsocketOutbound outbound) { |
||||
ReactorNettyWebSocketSession session = |
||||
new ReactorNettyWebSocketSession(inbound, outbound, getUri(), getBufferFactory()); |
||||
return getDelegate().handle(session); |
||||
} |
||||
|
||||
} |
||||
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2016 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.web.reactive.socket.adapter; |
||||
|
||||
import io.reactivex.netty.protocol.http.ws.WebSocketConnection; |
||||
import reactor.core.publisher.Mono; |
||||
import rx.Observable; |
||||
import rx.RxReactiveStreams; |
||||
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest; |
||||
import org.springframework.http.server.reactive.ServerHttpResponse; |
||||
import org.springframework.web.reactive.socket.WebSocketHandler; |
||||
|
||||
/** |
||||
* RxNetty {@code WebSocketHandler} implementation adapting and delegating to a |
||||
* Spring {@link WebSocketHandler}. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 5.0 |
||||
*/ |
||||
public class RxNettyWebSocketHandlerAdapter extends WebSocketHandlerAdapterSupport |
||||
implements io.reactivex.netty.protocol.http.ws.server.WebSocketHandler { |
||||
|
||||
|
||||
public RxNettyWebSocketHandlerAdapter(ServerHttpRequest request, ServerHttpResponse response, |
||||
WebSocketHandler handler) { |
||||
|
||||
super(request, response, handler); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public Observable<Void> handle(WebSocketConnection conn) { |
||||
RxNettyWebSocketSession session = new RxNettyWebSocketSession(conn, getUri(), getBufferFactory()); |
||||
Mono<Void> result = getDelegate().handle(session); |
||||
return RxReactiveStreams.toObservable(result); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue