Polishing and documentation fixes

This commit is contained in:
Juergen Hoeller
2017-01-17 12:47:04 +01:00
parent 5471d6a465
commit c42d44a42c
8 changed files with 48 additions and 57 deletions

View File

@@ -39,107 +39,110 @@ import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.server.WebSession;
/**
* Implementation of the {@link ServerRequest} interface that can be subclassed to adapt the request to a
* {@link HandlerFunction handler function}. All methods default to calling through to the wrapped request.
* Implementation of the {@link ServerRequest} interface that can be subclassed
* to adapt the request to a {@link HandlerFunction handler function}.
* All methods default to calling through to the wrapped request.
*
* @author Arjen Poutsma
* @since 5.0
*/
public class ServerRequestWrapper implements ServerRequest {
private final ServerRequest request;
private final ServerRequest delegate;
/**
* Create a new {@code RequestWrapper} that wraps the given request.
*
* @param request the request to wrap
* @param delegate the request to wrap
*/
public ServerRequestWrapper(ServerRequest request) {
Assert.notNull(request, "'request' must not be null");
this.request = request;
public ServerRequestWrapper(ServerRequest delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate;
}
/**
* Return the wrapped request.
*/
public ServerRequest request() {
return this.request;
return this.delegate;
}
@Override
public HttpMethod method() {
return this.request.method();
return this.delegate.method();
}
@Override
public URI uri() {
return this.request.uri();
return this.delegate.uri();
}
@Override
public String path() {
return this.request.path();
return this.delegate.path();
}
@Override
public Headers headers() {
return this.request.headers();
return this.delegate.headers();
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor) {
return this.request.body(extractor);
return this.delegate.body(extractor);
}
@Override
public <T> T body(BodyExtractor<T, ? super ServerHttpRequest> extractor, Map<String, Object> hints) {
return this.request.body(extractor, hints);
return this.delegate.body(extractor, hints);
}
@Override
public <T> Mono<T> bodyToMono(Class<? extends T> elementClass) {
return this.request.bodyToMono(elementClass);
return this.delegate.bodyToMono(elementClass);
}
@Override
public <T> Flux<T> bodyToFlux(Class<? extends T> elementClass) {
return this.request.bodyToFlux(elementClass);
return this.delegate.bodyToFlux(elementClass);
}
@Override
public <T> Optional<T> attribute(String name) {
return this.request.attribute(name);
return this.delegate.attribute(name);
}
@Override
public Optional<String> queryParam(String name) {
return this.request.queryParam(name);
return this.delegate.queryParam(name);
}
@Override
public List<String> queryParams(String name) {
return this.request.queryParams(name);
return this.delegate.queryParams(name);
}
@Override
public String pathVariable(String name) {
return this.request.pathVariable(name);
return this.delegate.pathVariable(name);
}
@Override
public Map<String, String> pathVariables() {
return this.request.pathVariables();
return this.delegate.pathVariables();
}
@Override
public Mono<WebSession> session() {
return this.request.session();
return this.delegate.session();
}
/**
* Implementation of the {@link Headers} interface that can be subclassed to adapt the headers to a
* {@link HandlerFunction handler function}. All methods default to calling through to the wrapped headers.
* Implementation of the {@code Headers} interface that can be subclassed
* to adapt the headers to a {@link HandlerFunction handler function}.
* All methods default to calling through to the wrapped headers.
*/
public static class HeadersWrapper implements ServerRequest.Headers {
@@ -147,7 +150,6 @@ public class ServerRequestWrapper implements ServerRequest {
/**
* Create a new {@code HeadersWrapper} that wraps the given request.
*
* @param headers the headers to wrap
*/
public HeadersWrapper(Headers headers) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -40,7 +40,7 @@ import org.springframework.web.reactive.socket.WebSocketSession;
* event-listener WebSocket APIs (e.g. Java WebSocket API JSR-356, Jetty,
* Undertow) and Reactive Streams.
*
* <p>Also an implementation of {@link Subscriber<Void>} so it can be used as
* <p>Also an implementation of {@code Subscriber&lt;Void&gt;} so it can be used as
* the completion subscriber for session handling
*
* @author Violeta Georgieva
@@ -80,7 +80,7 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
}
/**
* Alternative constructor with completion {@link Mono<Void>} to propagate
* Alternative constructor with completion {@code Mono&lt;Void&gt;} to propagate
* the session completion (success or error) (for client-side use).
*/
public AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo handshakeInfo,
@@ -232,6 +232,7 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
}
}
protected final class WebSocketSendProcessor extends AbstractListenerWriteProcessor<WebSocketMessage> {
private volatile boolean isReady = true;
@@ -243,20 +244,17 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
@Override
protected void releaseData() {
if (logger.isTraceEnabled()) {
logger.trace("releaseData: " + this.currentData);
}
this.currentData = null;
}
@Override
protected boolean isDataEmpty(WebSocketMessage message) {
return message.getPayload().readableByteCount() == 0;
return (message.getPayload().readableByteCount() == 0);
}
@Override
protected boolean isWritePossible() {
return this.isReady && this.currentData != null;
return (this.isReady && this.currentData != null);
}
/**
@@ -269,4 +267,4 @@ public abstract class AbstractListenerWebSocketSession<T> extends AbstractWebSoc
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -19,8 +19,6 @@ package org.springframework.web.reactive.socket.adapter;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -42,9 +40,6 @@ import org.springframework.web.reactive.socket.WebSocketSession;
*/
public abstract class AbstractWebSocketSession<T> implements WebSocketSession {
protected final Log logger = LogFactory.getLog(getClass());
private final T delegate;
private final String id;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -31,7 +31,6 @@ import rx.Observable;
import rx.RxReactiveStreams;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.util.Assert;
import org.springframework.web.reactive.socket.CloseStatus;
import org.springframework.web.reactive.socket.HandshakeInfo;
import org.springframework.web.reactive.socket.WebSocketMessage;
@@ -53,15 +52,13 @@ public class RxNettyWebSocketSession extends NettyWebSocketSessionSupport<WebSoc
public static final String FRAME_AGGREGATOR_NAME = "websocket-frame-aggregator";
public RxNettyWebSocketSession(WebSocketConnection conn, HandshakeInfo info,
NettyDataBufferFactory factory) {
public RxNettyWebSocketSession(WebSocketConnection conn, HandshakeInfo info, NettyDataBufferFactory factory) {
super(conn, info, factory);
}
/**
* Inserts an {@link WebSocketFrameAggregator} after the
* Insert an {@link WebSocketFrameAggregator} after the
* {@code WebSocketFrameDecoder} for receiving full messages.
* @param channel the channel for the session
* @param frameDecoderName the name of the WebSocketFrame decoder
@@ -69,11 +66,12 @@ public class RxNettyWebSocketSession extends NettyWebSocketSessionSupport<WebSoc
public RxNettyWebSocketSession aggregateFrames(Channel channel, String frameDecoderName) {
ChannelPipeline pipeline = channel.pipeline();
if (pipeline.context(FRAME_AGGREGATOR_NAME) != null) {
logger.trace("WebSocketFrameAggregator already registered.");
return this;
}
ChannelHandlerContext frameDecoder = pipeline.context(frameDecoderName);
Assert.notNull(frameDecoder, "WebSocketFrameDecoder not found: " + frameDecoderName);
if (frameDecoder == null) {
throw new IllegalArgumentException("WebSocketFrameDecoder not found: " + frameDecoderName);
}
ChannelHandler frameAggregator = new WebSocketFrameAggregator(DEFAULT_FRAME_MAX_SIZE);
pipeline.addAfter(frameDecoder.name(), FRAME_AGGREGATOR_NAME, frameAggregator);
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.socket.server;
import reactor.core.publisher.Mono;
@@ -29,7 +30,7 @@ import org.springframework.web.server.ServerWebExchange;
*
* @author Rossen Stoyanchev
* @since 5.0
* @see org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService;
* @see org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService
*/
public interface WebSocketService {