diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java index e40be220f2..ddeb138b43 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java @@ -28,6 +28,8 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.util.MimeType; /** + * Abstract base class for {@link Decoder} implementations. + * * @author Sebastien Deleuze * @author Arjen Poutsma * @since 5.0 @@ -36,6 +38,7 @@ public abstract class AbstractDecoder implements Decoder { private List decodableMimeTypes = Collections.emptyList(); + protected AbstractDecoder(MimeType... supportedMimeTypes) { this.decodableMimeTypes = Arrays.asList(supportedMimeTypes); } @@ -51,12 +54,14 @@ public abstract class AbstractDecoder implements Decoder { if (mimeType == null) { return true; } - return this.decodableMimeTypes.stream(). - anyMatch(mt -> mt.isCompatibleWith(mimeType)); + return this.decodableMimeTypes.stream().anyMatch(m -> m.isCompatibleWith(mimeType)); } @Override - public Mono decodeToMono(Publisher inputStream, ResolvableType elementType, MimeType mimeType, Object... hints) { + public Mono decodeToMono(Publisher inputStream, ResolvableType elementType, + MimeType mimeType, Object... hints) { + throw new UnsupportedOperationException(); } + } diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java index 64f5b0b60f..c65e1e033d 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java @@ -24,6 +24,8 @@ import org.springframework.core.ResolvableType; import org.springframework.util.MimeType; /** + * Abstract base class for {@link Decoder} implementations. + * * @author Sebastien Deleuze * @author Arjen Poutsma * @since 5.0 @@ -32,6 +34,7 @@ public abstract class AbstractEncoder implements Encoder { private List encodableMimeTypes = Collections.emptyList(); + protected AbstractEncoder(MimeType... supportedMimeTypes) { this.encodableMimeTypes = Arrays.asList(supportedMimeTypes); } @@ -47,8 +50,7 @@ public abstract class AbstractEncoder implements Encoder { if (mimeType == null) { return true; } - return this.encodableMimeTypes.stream(). - anyMatch(mt -> mt.isCompatibleWith(mimeType)); + return this.encodableMimeTypes.stream().anyMatch(m -> m.isCompatibleWith(mimeType)); } } diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java index 91e4004499..0a2e984d18 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java @@ -25,21 +25,25 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.MimeType; /** - * Abstract base class for {@link org.springframework.core.codec.Encoder} classes that - * can only deal with a single value. + * Abstract base class for {@link org.springframework.core.codec.Encoder} + * classes that can only deal with a single value. + * * @author Arjen Poutsma * @since 5.0 */ public abstract class AbstractSingleValueEncoder extends AbstractEncoder { + public AbstractSingleValueEncoder(MimeType... supportedMimeTypes) { super(supportedMimeTypes); } + @Override public final Flux encode(Publisher inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Object... hints) { + return Flux.from(inputStream). take(1). concatMap(t -> { @@ -53,7 +57,7 @@ public abstract class AbstractSingleValueEncoder extends AbstractEncoder { } /** - * Encodes {@code T} to an output {@link DataBuffer} stream. + * Encode {@code T} to an output {@link DataBuffer} stream. * @param t the value to process * @param dataBufferFactory a buffer factory used to create the output * @param type the stream element type to process @@ -65,5 +69,4 @@ public abstract class AbstractSingleValueEncoder extends AbstractEncoder { protected abstract Flux encode(T t, DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) throws Exception; - } diff --git a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java index 1c137febe1..0725307e1f 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java @@ -28,6 +28,8 @@ import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; /** + * Decoder for {@link ByteBuffer}s. + * * @author Sebastien Deleuze * @author Arjen Poutsma * @since 5.0 @@ -49,6 +51,7 @@ public class ByteBufferDecoder extends AbstractDecoder { @Override public Flux decode(Publisher inputStream, ResolvableType elementType, MimeType mimeType, Object... hints) { + return Flux.from(inputStream).map((dataBuffer) -> { ByteBuffer copy = ByteBuffer.allocate(dataBuffer.readableByteCount()); copy.put(dataBuffer.asByteBuffer()); diff --git a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java index bc457ed4f1..9af702fbc9 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java @@ -28,11 +28,14 @@ import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; /** + * Encoder for {@link ByteBuffer}s. + * * @author Sebastien Deleuze * @since 5.0 */ public class ByteBufferEncoder extends AbstractEncoder { + public ByteBufferEncoder() { super(MimeTypeUtils.ALL); } diff --git a/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java index b04d43e51c..680b29292a 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java @@ -32,17 +32,19 @@ import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; /** - * A decoder for {@link Resource}s. + * Decoder for {@link Resource}s. * * @author Arjen Poutsma * @since 5.0 */ public class ResourceDecoder extends AbstractDecoder { + public ResourceDecoder() { super(MimeTypeUtils.ALL); } + @Override public boolean canDecode(ResolvableType elementType, MimeType mimeType, Object... hints) { Class clazz = elementType.getRawClass(); @@ -54,6 +56,7 @@ public class ResourceDecoder extends AbstractDecoder { @Override public Flux decode(Publisher inputStream, ResolvableType elementType, MimeType mimeType, Object... hints) { + Class clazz = elementType.getRawClass(); Mono byteArray = Flux.from(inputStream). @@ -67,17 +70,13 @@ public class ResourceDecoder extends AbstractDecoder { if (InputStreamResource.class.equals(clazz)) { - return Flux.from(byteArray. - map(ByteArrayInputStream::new). - map(InputStreamResource::new)); + return Flux.from(byteArray.map(ByteArrayInputStream::new).map(InputStreamResource::new)); } else if (clazz.isAssignableFrom(ByteArrayResource.class)) { - return Flux.from(byteArray. - map(ByteArrayResource::new)); + return Flux.from(byteArray.map(ByteArrayResource::new)); } else { - return Flux.error(new IllegalStateException( - "Unsupported resource class: " + clazz)); + return Flux.error(new IllegalStateException("Unsupported resource class: " + clazz)); } } } diff --git a/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java index c33c2578ce..7658f2dac6 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java @@ -32,7 +32,8 @@ import org.springframework.util.MimeTypeUtils; import org.springframework.util.StreamUtils; /** - * An encoder for {@link Resource}s. + * Encoder for {@link Resource}s. + * * @author Arjen Poutsma * @since 5.0 */ @@ -40,8 +41,10 @@ public class ResourceEncoder extends AbstractSingleValueEncoder { public static final int DEFAULT_BUFFER_SIZE = StreamUtils.BUFFER_SIZE; + private final int bufferSize; + public ResourceEncoder() { this(DEFAULT_BUFFER_SIZE); } @@ -52,17 +55,17 @@ public class ResourceEncoder extends AbstractSingleValueEncoder { this.bufferSize = bufferSize; } + @Override public boolean canEncode(ResolvableType elementType, MimeType mimeType, Object... hints) { Class clazz = elementType.getRawClass(); - return (super.canEncode(elementType, mimeType, hints) && - Resource.class.isAssignableFrom(clazz)); + return (super.canEncode(elementType, mimeType, hints) && Resource.class.isAssignableFrom(clazz)); } @Override - protected Flux encode(Resource resource, - DataBufferFactory dataBufferFactory, + protected Flux encode(Resource resource, DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Object... hints) throws IOException { + InputStream is = resource.getInputStream(); return DataBufferUtils.read(is, dataBufferFactory, bufferSize); } diff --git a/spring-core/src/main/java/org/springframework/core/codec/StringEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/StringEncoder.java index 4387f28ca6..8e8b28c23e 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/StringEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/StringEncoder.java @@ -38,6 +38,7 @@ public class StringEncoder extends AbstractEncoder { public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + public StringEncoder() { super(new MimeType("text", "plain", DEFAULT_CHARSET)); } @@ -51,8 +52,9 @@ public class StringEncoder extends AbstractEncoder { @Override public Flux encode(Publisher inputStream, - DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, - Object... hints) { + DataBufferFactory bufferFactory, ResolvableType elementType, + MimeType mimeType, Object... hints) { + Charset charset; if (mimeType != null && mimeType.getCharset() != null) { charset = mimeType.getCharset(); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java index 07dc1d0eaf..7917fa2617 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/MonoToCompletableFutureConverter.java @@ -27,11 +27,15 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; /** + * Converter to adapt {@link CompletableFuture} to Reactive Streams and + * Reactor {@link Mono}. + * * @author Sebastien Deleuze * @since 5.0 */ public class MonoToCompletableFutureConverter implements GenericConverter { + @Override public Set getConvertibleTypes() { Set pairs = new LinkedHashSet<>(2); @@ -40,6 +44,7 @@ public class MonoToCompletableFutureConverter implements GenericConverter { return pairs; } + @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java index f4aeed4059..d25b4f9c86 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ReactorToRxJava1Converter.java @@ -31,6 +31,9 @@ import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; /** + * Converter to adapt RxJava1 {@link Observable}, {@link Single}, and + * {@link Completable} to Reactive Streams and Reactor types. + * * @author Stephane Maldini * @author Sebastien Deleuze * @since 5.0 diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java index c9fe379291..f3f66f8db9 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java @@ -19,8 +19,8 @@ package org.springframework.core.io.buffer; import java.nio.ByteBuffer; /** - * A factory for {@link DataBuffer}s, allowing for allocation and wrapping of data - * buffers. + * A factory for {@link DataBuffer}s,allowing for allocation and wrapping of + * data buffers. * * @author Arjen Poutsma * @see DataBuffer @@ -29,22 +29,24 @@ import java.nio.ByteBuffer; public interface DataBufferFactory { /** - * Allocates a data buffer of a default initial capacity. Depending on the underlying - * implementation and its configuration, this will be heap-based or direct buffer. + * Allocate a data buffer of a default initial capacity. Depending on the + * underlying implementation and its configuration, this will be heap-based + * or direct buffer. * @return the allocated buffer */ DataBuffer allocateBuffer(); /** - * Allocates a data buffer of the given initial capacity. Depending on the underlying - * implementation and its configuration, this will be heap-based or direct buffer. - * @param initialCapacity the initial capacity of the buffer to allocateBuffer + * Allocate a data buffer of the given initial capacity. Depending on the + * underlying implementation and its configuration, this will be heap-based + * or direct buffer. + * @param initialCapacity the initial capacity of the buffer to allocate * @return the allocated buffer */ DataBuffer allocateBuffer(int initialCapacity); /** - * Wraps the given {@link ByteBuffer} in a {@code DataBuffer}. + * Wrap the given {@link ByteBuffer} in a {@code DataBuffer}. * @param byteBuffer the NIO byte buffer to wrap * @return the wrapped buffer */ diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index 5415220742..aa365f74dd 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -47,8 +47,9 @@ public class DefaultDataBuffer implements DataBuffer { private int writePosition; /** - * Creates a new {@code DefaultDataBuffer} based on the given {@code ByteBuffer}. Both - * reading and writing position of this buffer are based on the current {@linkplain + * Create a new {@code DefaultDataBuffer} based on the given + * {@code ByteBuffer}. Both reading and writing position of this buffer are + * based on the current {@linkplain * ByteBuffer#position() position} of the given buffer. * @param byteBuffer the buffer to base this buffer on */ diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java index 53fe131d8a..befe3b3b14 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java @@ -22,8 +22,8 @@ import org.springframework.util.Assert; /** * Default implementation of the {@code DataBufferFactory} interface. Allows for - * specification of the default initial capacity at construction time, as well as whether - * heap-based or direct buffers are to be preferred. + * specification of the default initial capacity at construction time, as well + * as whether heap-based or direct buffers are to be preferred. * * @author Arjen Poutsma * @since 5.0 @@ -42,6 +42,7 @@ public class DefaultDataBufferFactory implements DataBufferFactory { private final int defaultInitialCapacity; + /** * Creates a new {@code DefaultDataBufferFactory} with default settings. */ @@ -50,21 +51,23 @@ public class DefaultDataBufferFactory implements DataBufferFactory { } /** - * Creates a new {@code DefaultDataBufferFactory}, indicating whether direct buffers - * should be created by {@link #allocateBuffer()} and {@link #allocateBuffer(int)}. - * @param preferDirect {@code true} if direct buffers are to be preferred; {@code - * false} otherwise + * Creates a new {@code DefaultDataBufferFactory}, indicating whether direct + * buffers should be created by {@link #allocateBuffer()} and + * {@link #allocateBuffer(int)}. + * @param preferDirect {@code true} if direct buffers are to be preferred; + * {@code false} otherwise */ public DefaultDataBufferFactory(boolean preferDirect) { this(preferDirect, DEFAULT_INITIAL_CAPACITY); } /** - * Creates a new {@code DefaultDataBufferFactory}, indicating whether direct buffers - * should be created by {@link #allocateBuffer()} and {@link #allocateBuffer(int)}, - * and what the capacity is to be used for {@link #allocateBuffer()}. - * @param preferDirect {@code true} if direct buffers are to be preferred; {@code - * false} otherwise + * Creates a new {@code DefaultDataBufferFactory}, indicating whether direct + * buffers should be created by {@link #allocateBuffer()} and + * {@link #allocateBuffer(int)}, and what the capacity is to be used for + * {@link #allocateBuffer()}. + * @param preferDirect {@code true} if direct buffers are to be preferred; + * {@code false} otherwise */ public DefaultDataBufferFactory(boolean preferDirect, int defaultInitialCapacity) { Assert.isTrue(defaultInitialCapacity > 0, @@ -73,6 +76,7 @@ public class DefaultDataBufferFactory implements DataBufferFactory { this.defaultInitialCapacity = defaultInitialCapacity; } + @Override public DefaultDataBuffer allocateBuffer() { return allocateBuffer(this.defaultInitialCapacity); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java index 837015f30c..74d7933542 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/FlushingDataBuffer.java @@ -22,8 +22,8 @@ import java.nio.ByteBuffer; import java.util.function.IntPredicate; /** - * Empty {@link DataBuffer} that indicates to the file or the socket writing it that - * previously buffered data should be flushed. + * Empty {@link DataBuffer} that indicates to the file or the socket writing it + * that previously buffered data should be flushed. * * @author Sebastien Deleuze * @since 5.0 diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java index 488f7dedab..fca89db230 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java @@ -32,8 +32,8 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * Implementation of the {@code DataBuffer} interface that wraps a Netty {@link ByteBuf}. - * Typically constructed using the {@link NettyDataBufferFactory}. + * Implementation of the {@code DataBuffer} interface that wraps a Netty + * {@link ByteBuf}. Typically constructed with {@link NettyDataBufferFactory}. * * @author Arjen Poutsma * @since 5.0 diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java index a37933bb6b..2a6a1d5886 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java @@ -37,6 +37,7 @@ public class NettyDataBufferFactory implements DataBufferFactory { private final ByteBufAllocator byteBufAllocator; + /** * Creates a new {@code NettyDataBufferFactory} based on the given factory. * @param byteBufAllocator the factory to use @@ -49,6 +50,7 @@ public class NettyDataBufferFactory implements DataBufferFactory { this.byteBufAllocator = byteBufAllocator; } + @Override public NettyDataBuffer allocateBuffer() { ByteBuf byteBuf = this.byteBufAllocator.buffer(); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java index f0eaa38721..0f59702920 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/PooledDataBuffer.java @@ -17,8 +17,8 @@ package org.springframework.core.io.buffer; /** - * Extension of {@link DataBuffer} that allows for buffer that share a memory pool. - * Introduces methods for reference counting. + * Extension of {@link DataBuffer} that allows for buffer that share a memory + * pool. Introduces methods for reference counting. * * @author Arjen Poutsma * @since 5.0 @@ -32,8 +32,8 @@ public interface PooledDataBuffer extends DataBuffer { PooledDataBuffer retain(); /** - * Decreases the reference count for this buffer by one, and releases it once the - * count reaches zero. + * Decreases the reference count for this buffer by one, and releases it + * once the count reaches zero. * @return {@code true} if the buffer was released; {@code false} otherwise. */ boolean release(); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java b/spring-core/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java index 27b9423660..4b7b1c0ddf 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/support/DataBufferUtils.java @@ -89,8 +89,8 @@ public abstract class DataBufferUtils { /** * Relays buffers from the given {@link Publisher} until the total - * {@linkplain DataBuffer#readableByteCount() byte count} reaches the given maximum - * byte count, or until the publisher is complete. + * {@linkplain DataBuffer#readableByteCount() byte count} reaches the given + * maximum byte count, or until the publisher is complete. * @param publisher the publisher to filter * @param maxByteCount the maximum byte count * @return a flux whose maximum byte count is {@code maxByteCount} diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/MappingContentTypeResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/MappingContentTypeResolver.java index 4d7d2e0c74..55c53123bb 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/MappingContentTypeResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/MappingContentTypeResolver.java @@ -21,8 +21,8 @@ import java.util.Set; import org.springframework.http.MediaType; /** - * An extension of {@link RequestedContentTypeResolver} that maintains a mapping between - * keys (e.g. file extension, query parameter) and media types. + * An extension of {@link RequestedContentTypeResolver} that maintains a mapping + * between keys (e.g. file extension, query parameter) and media types. * * @author Rossen Stoyanchev * @since 5.0 diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/ParameterContentTypeResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/ParameterContentTypeResolver.java index 49101a0767..294587d2d9 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/ParameterContentTypeResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/ParameterContentTypeResolver.java @@ -27,8 +27,8 @@ import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; /** - * A {@link RequestedContentTypeResolver} that extracts the media type lookup key from a - * known query parameter named "format" by default. + * A {@link RequestedContentTypeResolver} that extracts the media type lookup + * key from a known query parameter named "format" by default. * * @author Rossen Stoyanchev * @since 5.0 diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java index d984a2c50d..6f668bda02 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/PathExtensionContentTypeResolver.java @@ -31,8 +31,8 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.util.WebUtils; /** - * A {@link RequestedContentTypeResolver} that extracts the file extension from the - * request path and uses that as the media type lookup key. + * A {@link RequestedContentTypeResolver} that extracts the file extension from + * the request path and uses that as the media type lookup key. * *

If the file extension is not found in the explicit registrations provided * to the constructor, the Java Activation Framework (JAF) is used as a fallback diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolver.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolver.java index 8cabc16bf1..99c5f229b5 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolver.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolver.java @@ -22,7 +22,8 @@ import org.springframework.web.server.NotAcceptableStatusException; import org.springframework.web.server.ServerWebExchange; /** - * Strategy for resolving the requested media types for a {@code ServerWebExchange}. + * Strategy for resolving the requested media types for a + * {@code ServerWebExchange}. * * @author Rossen Stoyanchev * @since 5.0 diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java index aa1122254a..6bfcd1ecbd 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java @@ -28,9 +28,9 @@ import org.springframework.util.CollectionUtils; /** * Factory to create a {@link CompositeContentTypeResolver} and configure it with - * one or more {@link RequestedContentTypeResolver} instances with build style methods. - * The following table shows methods, resulting strategy instances, and if in - * use by default: + * one or more {@link RequestedContentTypeResolver} instances with build style + * methods. The following table shows methods, resulting strategy instances, and + * if in use by default: * * * @@ -65,9 +65,10 @@ import org.springframework.util.CollectionUtils; * *
* - *

The order in which resolvers are configured is fixed. Config methods may only - * turn individual resolvers on or off. If you need a custom order for any - * reason simply instantiate {@code {@link CompositeContentTypeResolver}} directly. + *

The order in which resolvers are configured is fixed. Config methods may + * only turn individual resolvers on or off. If you need a custom order for any + * reason simply instantiate {@code {@link CompositeContentTypeResolver}} + * directly. * *

For the path extension and parameter resolvers you may explicitly add * {@link #mediaTypes(Map)}. This will be used to resolve path extensions or a diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index 9a7160137c..48c0d5cc1a 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -40,6 +40,9 @@ import org.springframework.web.server.ServerWebExchange; /** + * Extension of HandlerMethod that can invoke the target method after resolving + * its method arguments. + * * @author Rossen Stoyanchev * @since 5.0 */ diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java index 3896b601eb..28e11eb895 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/AbstractView.java @@ -34,6 +34,7 @@ import org.springframework.web.reactive.HandlerResult; import org.springframework.web.server.ServerWebExchange; /** + * Base class for {@link View} implementations. * * @author Rossen Stoyanchev * @since 5.0 diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java index 7c8c4ff218..38d9b24b55 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java @@ -47,6 +47,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { private final List>> beforeCommitActions = new ArrayList<>(4); + public AbstractClientHttpRequest() { this(new HttpHeaders()); } @@ -57,6 +58,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { this.cookies = new LinkedMultiValueMap<>(); } + @Override public HttpHeaders getHeaders() { if (State.COMITTED.equals(this.state.get())) { diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java index f5b1e6b210..a207d3d056 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java @@ -23,10 +23,9 @@ import reactor.core.publisher.Mono; import org.springframework.http.HttpMethod; /** - * Client abstraction for HTTP client runtimes. - * {@link ClientHttpConnector} drives the underlying HTTP client implementation - * so as to connect to the origin server and provide all the necessary infrastructure - * to send the actual {@link ClientHttpRequest} and receive the {@link ClientHttpResponse} + * Abstraction over HTTP clients driving the underlying HTTP client to connect + * to the origin server and provide all necessary infrastructure to send a + * {@link ClientHttpRequest} and receive a {@link ClientHttpResponse}. * * @author Brian Clozel * @since 5.0 @@ -34,16 +33,16 @@ import org.springframework.http.HttpMethod; public interface ClientHttpConnector { /** - * Connect to the origin server using the given {@code HttpMethod} and {@code URI}, - * then apply the given {@code requestCallback} on the {@link ClientHttpRequest} - * once the connection has been established. + * Connect to the origin server using the given {@code HttpMethod} and + * {@code URI}, then apply the given {@code requestCallback} on the + * {@link ClientHttpRequest} once the connection has been established. *

Return a publisher of the {@link ClientHttpResponse}. * * @param method the HTTP request method * @param uri the HTTP request URI * @param requestCallback a function that prepares and writes the request, - * returning a publisher that signals when it's done interacting with the request. - * Implementations should return a {@code Mono} by calling + * returning a publisher that signals when it's done interacting with the + * request. Implementations should return a {@code Mono} by calling * {@link ClientHttpRequest#writeWith} or {@link ClientHttpRequest#setComplete}. * @return a publisher of the {@link ClientHttpResponse} */ diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java index f2288a91ea..6d13e7a198 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpRequest.java @@ -24,7 +24,7 @@ import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.util.MultiValueMap; /** - * Represents a reactive client-side HTTP request. + * Represents a client-side reactive HTTP request. * * @author Arjen Poutsma * @author Brian Clozel diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java index faf1b23156..148c03b71e 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpResponse.java @@ -22,7 +22,7 @@ import org.springframework.http.ResponseCookie; import org.springframework.util.MultiValueMap; /** - * Represents a reactive client-side HTTP response. + * Represents a client-side reactive HTTP response. * * @author Arjen Poutsma * @since 5.0 diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java index 3cfdc07321..5e8bfae84e 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java @@ -47,4 +47,5 @@ public class ReactorClientHttpConnector implements ClientHttpConnector { .otherwise(HttpException.class, exc -> Mono.just(exc.getChannel())) .map(httpInbound -> new ReactorClientHttpResponse(httpInbound)); } + } \ No newline at end of file diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java index 5416d0640c..039411970d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java @@ -33,7 +33,7 @@ import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpMethod; /** - * {@link ClientHttpRequest} implementation for the Reactor-Netty HTTP client + * {@link ClientHttpRequest} implementation for the Reactor-Netty HTTP client. * * @author Brian Clozel * @since 5.0 @@ -49,6 +49,7 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { private final NettyDataBufferFactory bufferFactory; + public ReactorClientHttpRequest(HttpMethod httpMethod, URI uri, HttpClientRequest httpRequest) { this.httpMethod = httpMethod; this.uri = uri; @@ -56,6 +57,7 @@ public class ReactorClientHttpRequest extends AbstractClientHttpRequest { this.bufferFactory = new NettyDataBufferFactory(httpRequest.delegate().alloc()); } + @Override public DataBufferFactory bufferFactory() { return this.bufferFactory; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java index f90cad9def..7af81328e7 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java @@ -31,7 +31,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; /** - * {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client + * {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client. * * @author Brian Clozel * @see reactor.io.netty.http.HttpClient @@ -43,11 +43,13 @@ public class ReactorClientHttpResponse implements ClientHttpResponse { private final HttpInbound response; + public ReactorClientHttpResponse(HttpInbound response) { this.response = response; this.dataBufferFactory = new NettyDataBufferFactory(response.delegate().alloc()); } + @Override public Flux getBody() { return response.receive() diff --git a/spring-web/src/main/java/org/springframework/http/codec/SseEvent.java b/spring-web/src/main/java/org/springframework/http/codec/SseEvent.java index e28afece44..610d639b53 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/SseEvent.java +++ b/spring-web/src/main/java/org/springframework/http/codec/SseEvent.java @@ -20,10 +20,9 @@ import org.springframework.http.MediaType; import org.springframework.http.codec.SseEventEncoder; /** - * Represent a Server-Sent Event. - * - *

{@code Flux} is Spring Web Reactive equivalent to Spring MVC - * {@code SseEmitter} type. It allows to send Server-Sent Events in a reactive way. + * Representation for a Server-Sent Event for use with Spring's reactive Web + * support. {@code Flux} or {@code Observable} is the + * reactive equivalent to Spring MVC's {@code SseEmitter}. * * @author Sebastien Deleuze * @since 5.0 @@ -44,6 +43,7 @@ public class SseEvent { private String comment; + /** * Create an empty instance. */ @@ -65,6 +65,7 @@ public class SseEvent { this.mediaType = mediaType; } + /** * Set the {@code id} SSE field */ diff --git a/spring-web/src/main/java/org/springframework/http/codec/SseEventEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/SseEventEncoder.java index d7d6abf340..9a6ee9aa73 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/SseEventEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/SseEventEncoder.java @@ -36,8 +36,10 @@ import org.springframework.util.Assert; import org.springframework.util.MimeType; /** - * An encoder for {@link SseEvent}s that also supports any other kind of {@link Object} - * (in that case, the object will be the data of the {@link SseEvent}). + * Encoder that supports a stream of {@link SseEvent}s and also plain + * {@link Object}s which is the same as an {@link SseEvent} with data + * only. + * * @author Sebastien Deleuze * @since 5.0 */ diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Decoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Decoder.java index 92c9df245e..b7dfa0b83f 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Decoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Decoder.java @@ -44,7 +44,8 @@ import org.springframework.util.MimeTypeUtils; import org.springframework.util.xml.StaxUtils; /** - * Decode from a bytes stream of XML elements to a stream of {@code Object} (POJO). + * Decode from a bytes stream containing XML elements to a stream of + * {@code Object}s (POJOs). * * @author Sebastien Deleuze * @author Arjen Poutsma @@ -66,10 +67,12 @@ public class Jaxb2Decoder extends AbstractDecoder { private final JaxbContextContainer jaxbContexts = new JaxbContextContainer(); + public Jaxb2Decoder() { super(MimeTypeUtils.APPLICATION_XML, MimeTypeUtils.TEXT_XML); } + @Override public boolean canDecode(ResolvableType elementType, MimeType mimeType, Object... hints) { if (super.canDecode(elementType, mimeType, hints)) { @@ -85,6 +88,7 @@ public class Jaxb2Decoder extends AbstractDecoder { @Override public Flux decode(Publisher inputStream, ResolvableType elementType, MimeType mimeType, Object... hints) { + Class outputClass = elementType.getRawClass(); Flux xmlEventFlux = this.xmlEventDecoder.decode(inputStream, null, mimeType); diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Encoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Encoder.java index e29b7e785f..e34a4783da 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Encoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Encoder.java @@ -34,7 +34,7 @@ import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; /** - * Encode from an {@code Object} stream to a byte stream of XML elements. + * Encode from {@code Object} stream to a byte stream containing XML elements. * * @author Sebastien Deleuze * @author Arjen Poutsma diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java b/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java index f0454910d3..7d379987c8 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java @@ -31,9 +31,11 @@ import org.springframework.util.Assert; */ final class JaxbContextContainer { + private final ConcurrentMap, JAXBContext> jaxbContexts = new ConcurrentHashMap<>(64); + public Marshaller createMarshaller(Class clazz) throws JAXBException { JAXBContext jaxbContext = getJaxbContext(clazz); return jaxbContext.createMarshaller(); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractRequestBodyPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractRequestBodyPublisher.java index b439c54849..b02666f792 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractRequestBodyPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractRequestBodyPublisher.java @@ -34,8 +34,8 @@ import org.springframework.core.io.buffer.DataBuffer; /** * Abstract base class for {@code Publisher} implementations that bridge between - * event-listener APIs and Reactive Streams. Specifically, base class for the Servlet 3.1 - * and Undertow support. + * event-listener APIs and Reactive Streams. Specifically, base class for the + * Servlet 3.1 and Undertow support. * * @author Arjen Poutsma * @since 5.0 diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractResponseBodyProcessor.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractResponseBodyProcessor.java index 240747e9f2..58e1aedf70 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractResponseBodyProcessor.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractResponseBodyProcessor.java @@ -35,8 +35,9 @@ import org.springframework.util.Assert; /** * Abstract base class for {@code Subscriber} implementations that bridge between - * event-listener APIs and Reactive Streams. Specifically, base class for the Servlet 3.1 - * and Undertow support. + * event-listener APIs and Reactive Streams. Specifically, base class for the + * Servlet 3.1 and Undertow support. + * * @author Arjen Poutsma * @since 5.0 * @see ServletServerHttpRequest diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java index 07f7d48bb6..25645ce001 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorHttpHandlerAdapter.java @@ -25,28 +25,27 @@ import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.util.Assert; /** + * Adapt {@link HttpHandler} to the Reactor Netty {@link ChannelHandler}. + * * @author Stephane Maldini * @since 5.0 */ -public class ReactorHttpHandlerAdapter - implements ChannelHandler { +public class ReactorHttpHandlerAdapter implements ChannelHandler { private final HttpHandler httpHandler; + public ReactorHttpHandlerAdapter(HttpHandler httpHandler) { Assert.notNull(httpHandler, "'httpHandler' is required."); this.httpHandler = httpHandler; } + @Override public Mono apply(HttpChannel channel) { - NettyDataBufferFactory dataBufferFactory = - new NettyDataBufferFactory(channel.delegate().alloc()); - - ReactorServerHttpRequest adaptedRequest = - new ReactorServerHttpRequest(channel, dataBufferFactory); - ReactorServerHttpResponse adaptedResponse = - new ReactorServerHttpResponse(channel, dataBufferFactory); + NettyDataBufferFactory bufferFactory = new NettyDataBufferFactory(channel.delegate().alloc()); + ReactorServerHttpRequest adaptedRequest = new ReactorServerHttpRequest(channel, bufferFactory); + ReactorServerHttpResponse adaptedResponse = new ReactorServerHttpResponse(channel, bufferFactory); return this.httpHandler.handle(adaptedRequest, adaptedResponse); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ResponseBodyWriteResultPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ResponseBodyWriteResultPublisher.java index 65562a5001..8648004e98 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ResponseBodyWriteResultPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ResponseBodyWriteResultPublisher.java @@ -28,6 +28,7 @@ import reactor.core.publisher.Operators; /** * Publisher returned from {@link ServerHttpResponse#writeWith(Publisher)}. + * * @author Arjen Poutsma * @since 5.0 */ diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java index 41bb635798..6e10d15b90 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/RxNettyHttpHandlerAdapter.java @@ -28,6 +28,8 @@ import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.util.Assert; /** + * Adapt {@link HttpHandler} to the RxNetty {@link RequestHandler}. + * * @author Rossen Stoyanchev * @since 5.0 */ @@ -35,20 +37,18 @@ public class RxNettyHttpHandlerAdapter implements RequestHandler handle(HttpServerRequest request, HttpServerResponse response) { - NettyDataBufferFactory dataBufferFactory = - new NettyDataBufferFactory(response.unsafeNettyChannel().alloc()); - - RxNettyServerHttpRequest adaptedRequest = - new RxNettyServerHttpRequest(request, dataBufferFactory); - RxNettyServerHttpResponse adaptedResponse = - new RxNettyServerHttpResponse(response, dataBufferFactory); + NettyDataBufferFactory bufferFactory = new NettyDataBufferFactory(response.unsafeNettyChannel().alloc()); + RxNettyServerHttpRequest adaptedRequest = new RxNettyServerHttpRequest(request, bufferFactory); + RxNettyServerHttpResponse adaptedResponse = new RxNettyServerHttpResponse(response, bufferFactory); Publisher result = this.httpHandler.handle(adaptedRequest, adaptedResponse); return RxJava1Adapter.publisherToObservable(result); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java index 557fb69c6b..a564336fab 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletHttpHandlerAdapter.java @@ -34,6 +34,9 @@ import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.util.Assert; /** + * Adapt {@link HttpHandler} to an {@link HttpServlet} using Servlet Async + * support and Servlet 3.1 Non-blocking I/O. + * * @author Arjen Poutsma * @author Rossen Stoyanchev * @since 5.0 @@ -54,6 +57,7 @@ public class ServletHttpHandlerAdapter extends HttpServlet { private int bufferSize = DEFAULT_BUFFER_SIZE; + public void setHandler(HttpHandler handler) { Assert.notNull(handler, "'handler' must not be null"); this.handler = handler; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java index 98468c9d6a..c1e49b61e5 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpRequest.java @@ -43,6 +43,7 @@ import org.springframework.util.StringUtils; /** * Adapt {@link ServerHttpRequest} to the Servlet {@link HttpServletRequest}. + * * @author Rossen Stoyanchev * @since 5.0 */ diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java index a571348525..1875f0057b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java @@ -38,6 +38,7 @@ import org.springframework.util.Assert; /** * Adapt {@link ServerHttpResponse} to the Servlet {@link HttpServletResponse}. + * * @author Rossen Stoyanchev * @since 5.0 */ diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java index eedf6c89c8..f8b65e5b96 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHttpHandlerAdapter.java @@ -26,6 +26,8 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.util.Assert; /** + * Adapt {@link HttpHandler} to the Undertow {@link io.undertow.server.HttpHandler}. + * * @author Marek Hawrylczak * @author Rossen Stoyanchev * @author Arjen Poutsma @@ -40,14 +42,15 @@ public class UndertowHttpHandlerAdapter implements io.undertow.server.HttpHandle private final DataBufferFactory dataBufferFactory; - public UndertowHttpHandlerAdapter(HttpHandler delegate, - DataBufferFactory dataBufferFactory) { + + public UndertowHttpHandlerAdapter(HttpHandler delegate, DataBufferFactory dataBufferFactory) { Assert.notNull(delegate, "'delegate' is required"); Assert.notNull(dataBufferFactory, "'dataBufferFactory' must not be null"); this.delegate = delegate; this.dataBufferFactory = dataBufferFactory; } + @Override public void handleRequest(HttpServerExchange exchange) throws Exception { diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java index 7a065f0fe9..e728807cda 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java @@ -39,7 +39,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; /** - * Adapt {@link ServerHttpRequest} to the Underow {@link HttpServerExchange}. + * Adapt {@link ServerHttpRequest} to the Undertow {@link HttpServerExchange}. * * @author Marek Hawrylczak * @author Rossen Stoyanchev diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java index a9d8ac8d92..01a2487897 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java @@ -42,6 +42,7 @@ import org.springframework.util.Assert; /** * Adapt {@link ServerHttpResponse} to the Undertow {@link HttpServerExchange}. + * * @author Marek Hawrylczak * @author Rossen Stoyanchev * @author Arjen Poutsma diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/BodyExtractor.java b/spring-web/src/main/java/org/springframework/web/client/reactive/BodyExtractor.java index 9bc2837c1c..e5df2c1f2c 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/BodyExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/BodyExtractor.java @@ -22,11 +22,11 @@ import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.converter.reactive.HttpMessageConverter; /** - * A {@code BodyExtractor} extracts the content of a raw {@link ClientHttpResponse}, - * decoding the response body and using a target composition API. + * Contract to extract the content of a raw {@link ClientHttpResponse} decoding + * the response body and using a target composition API. * - *

See static factory methods in {@link ResponseExtractors} - * and {@link org.springframework.web.client.reactive.support.RxJava1ResponseExtractors}. + *

See static factory methods in {@link ResponseExtractors} and + * {@link org.springframework.web.client.reactive.support.RxJava1ResponseExtractors}. * * @author Brian Clozel * @since 5.0 @@ -40,4 +40,5 @@ public interface BodyExtractor { * @return the relevant content */ T extract(ClientHttpResponse clientResponse, List> messageConverters); + } diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequest.java b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequest.java index 8ad3b73e6d..9d0629b52d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequest.java @@ -27,15 +27,18 @@ import org.springframework.http.HttpMethod; import org.springframework.util.MultiValueMap; /** - * Holds all the application information required to build an actual HTTP client request. - *

The request body is materialized by a {@code Publisher} of Objects and their type - * by a {@code ResolvableType} instance; it should be later converted to a - * {@code Publisher} to be written to the actual HTTP client request. + * Simple container for application-level information required to perform an + * HTTP client request. + * + *

The request body is provided through a {@code Publisher} where the + * type of each Object is indicated through a {@link ResolvableType} which + * subsequently is used to correctly serialize into the + * {@code Publisher} actually written to request body. * * @author Brian Clozel * @since 5.0 */ -public class ClientWebRequest { +public class ClientWebRequest { protected final HttpMethod httpMethod; @@ -55,6 +58,7 @@ public class ClientWebRequest { this.url = url; } + public HttpMethod getMethod() { return httpMethod; } diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilder.java b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilder.java index 6078240b2b..e19a6848a8 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilder.java @@ -17,7 +17,7 @@ package org.springframework.web.client.reactive; /** - * Build {@link ClientWebRequest}s + * Build {@link ClientWebRequest}s. * * @author Brian Clozel * @since 5.0 diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilders.java b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilders.java index 35fd61ae60..1b1d715332 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilders.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestBuilders.java @@ -20,7 +20,8 @@ package org.springframework.web.client.reactive; import org.springframework.http.HttpMethod; /** - * Static factory methods for {@link DefaultClientWebRequestBuilder ClientWebRequestBuilders} + * Static factory methods for {@link DefaultClientWebRequestBuilder + * ClientWebRequestBuilders}. * * @author Brian Clozel * @since 5.0 @@ -47,7 +48,6 @@ public abstract class ClientWebRequestBuilders { return new DefaultClientWebRequestBuilder(HttpMethod.POST, urlTemplate, urlVariables); } - /** * Create a {@link DefaultClientWebRequestBuilder} for a PUT request. * diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestPostProcessor.java b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestPostProcessor.java index d0f018b43f..9a367cd217 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestPostProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/ClientWebRequestPostProcessor.java @@ -17,8 +17,9 @@ package org.springframework.web.client.reactive; /** - * Allow post processing and/or wrapping the {@link ClientWebRequest} before - * it's sent to the origin server. + * Contract to post-process the {@link ClientWebRequest} after it is created + * an initialized in order to mofidy or even wrap it. This may be used for + * example to pre-package specific modifications to the request. * * @author Rob Winch * @author Brian Clozel @@ -28,10 +29,10 @@ package org.springframework.web.client.reactive; public interface ClientWebRequestPostProcessor { /** - * Implementations can modify and/or wrap the {@link ClientWebRequest} passed in - * and return it - * + * Implementations can modify and/or wrap the {@link ClientWebRequest} + * passed in and return it * @param request the {@link ClientWebRequest} to be modified and/or wrapped. */ ClientWebRequest postProcess(ClientWebRequest request); + } diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/DefaultClientWebRequestBuilder.java b/spring-web/src/main/java/org/springframework/web/client/reactive/DefaultClientWebRequestBuilder.java index dec58bc601..80a058e44d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/DefaultClientWebRequestBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/DefaultClientWebRequestBuilder.java @@ -41,7 +41,7 @@ import org.springframework.web.util.UriTemplateHandler; * Builds a {@link ClientHttpRequest} using a {@link Publisher} * as request body. * - *

See static factory methods in {@link ClientWebRequestBuilders} + *

See static factory methods in {@link ClientWebRequestBuilders}. * * @author Brian Clozel * @since 5.0 diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/ResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/reactive/ResponseErrorHandler.java index 3f7ac52c9d..734f4594af 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/ResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/ResponseErrorHandler.java @@ -22,8 +22,8 @@ import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.converter.reactive.HttpMessageConverter; /** - * Strategy interface used by the {@link WebClient} to handle - * errors in {@link ClientHttpResponse}s if needed. + * Strategy interface used by the {@link WebClient} to handle errors in + * {@link ClientHttpResponse}s if needed. * * @author Brian Clozel * @see DefaultResponseErrorHandler @@ -33,8 +33,9 @@ public interface ResponseErrorHandler { /** * Handle the error in the given response. - * Implementations will typically inspect the {@link ClientHttpResponse#getStatusCode() HttpStatus} - * of the response and throw {@link WebClientException}s in case of errors. + * Implementations will typically inspect the + * {@link ClientHttpResponse#getStatusCode() HttpStatus} of the response and + * throw {@link WebClientException}s in case of errors. */ void handleError(ClientHttpResponse response, List> messageConverters); diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClient.java b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClient.java index b06e49de8e..2804008b1d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClient.java @@ -55,21 +55,23 @@ import reactor.core.publisher.Mono; *

Here is a simple example of a GET request: * *

+ * static imports: ClientWebRequestBuilder.*, ResponseExtractors.*
+ *
  * // should be shared between HTTP calls
  * WebClient client = new WebClient(new ReactorHttpClient());
  *
  * Mono<String> result = client
- * 		.perform(ClientWebRequestBuilders.get("http://example.org/resource")
- * 				.accept(MediaType.TEXT_PLAIN))
- * 		.extract(ResponseExtractors.body(String.class));
+ * 		.perform(get("http://example.org/resource").accept(MediaType.TEXT_PLAIN))
+ * 		.extract(body(String.class));
  * 
* - *

This Web client relies on + *

This Web client relies on the following: *

    - *
  • an {@link ClientHttpConnector} implementation that drives the underlying library (e.g. Reactor-Netty)
  • - *
  • a {@link ClientWebRequestBuilder} which creates a Web request with a builder API (see - * {@link ClientWebRequestBuilders})
  • - *
  • an {@link ResponseExtractor} which extracts the relevant part of the server + *
  • {@link ClientHttpConnector} implementation to drive the underlying + * library (e.g. Reactor-Netty)
  • + *
  • {@link ClientWebRequestBuilder} to create a Web request with a builder + * API (see {@link ClientWebRequestBuilders})
  • + *
  • {@link ResponseExtractor} to extract the relevant part of the server * response with the composition API of choice (see {@link ResponseExtractors}
  • *
* diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientErrorException.java b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientErrorException.java index 637418e2bb..40109daa4d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientErrorException.java @@ -18,7 +18,6 @@ package org.springframework.web.client.reactive; import java.util.List; -import org.springframework.http.HttpStatus; import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.converter.reactive.HttpMessageConverter; @@ -31,15 +30,21 @@ import org.springframework.http.converter.reactive.HttpMessageConverter; @SuppressWarnings("serial") public class WebClientErrorException extends WebClientResponseException { + /** - * Construct a new instance of {@code HttpClientErrorException} based on a {@link ClientHttpResponse} - * and {@link HttpMessageConverter}s to optionally help decoding the response body - * @param clientResponse the HTTP response - * @param messageConverters the message converters that may decode the HTTP response body + * Construct a new instance of {@code HttpClientErrorException} based on a + * {@link ClientHttpResponse} and {@link HttpMessageConverter}s to optionally + * help decoding the response body + * + * @param response the HTTP response + * @param converters the message converters that may decode the HTTP response body */ - public WebClientErrorException(ClientHttpResponse clientResponse, - List> messageConverters) { - super(clientResponse.getStatusCode().value() + " " + clientResponse.getStatusCode().getReasonPhrase(), - clientResponse, messageConverters); + public WebClientErrorException(ClientHttpResponse response, List> converters) { + super(initMessage(response), response, converters); } + + private static String initMessage(ClientHttpResponse response) { + return response.getStatusCode().value() + " " + response.getStatusCode().getReasonPhrase(); + } + } diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientException.java b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientException.java index c6ca477d3d..e7f351cfe1 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientException.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientException.java @@ -19,8 +19,7 @@ package org.springframework.web.client.reactive; import org.springframework.core.NestedRuntimeException; /** - * Base class for exceptions thrown by {@link WebClient} whenever - * it encounters errors. + * Base class for exceptions thrown by {@link WebClient}. * * @author Brian Clozel * @since 5.0 @@ -35,4 +34,5 @@ public class WebClientException extends NestedRuntimeException { public WebClientException(String msg, Throwable cause) { super(msg, cause); } + } diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientResponseException.java b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientResponseException.java index e273d9b93d..abf5d31f79 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientResponseException.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/WebClientResponseException.java @@ -24,7 +24,8 @@ import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.converter.reactive.HttpMessageConverter; /** - * Base class for exceptions associated with specific HTTP client response status codes. + * Base class for exceptions associated with specific HTTP client response + * status codes. * * @author Brian Clozel * @since 5.0 @@ -36,6 +37,7 @@ public class WebClientResponseException extends WebClientException { private final List> messageConverters; + /** * Construct a new instance of {@code WebClientResponseException} with the given response data * @param message the given error message @@ -49,6 +51,7 @@ public class WebClientResponseException extends WebClientException { this.messageConverters = messageConverters; } + /** * Return the HTTP status */ diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/WebResponseActions.java b/spring-web/src/main/java/org/springframework/web/client/reactive/WebResponseActions.java index 4c9167c812..40c53da7a6 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/WebResponseActions.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/WebResponseActions.java @@ -47,4 +47,5 @@ public interface WebResponseActions { * */ T extract(ResponseExtractor extractor); + } diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/WebServerErrorException.java b/spring-web/src/main/java/org/springframework/web/client/reactive/WebServerErrorException.java index e5f1b25b5c..1d5a02805a 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/WebServerErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/WebServerErrorException.java @@ -32,13 +32,18 @@ import org.springframework.http.converter.reactive.HttpMessageConverter; public class WebServerErrorException extends WebClientResponseException { /** - * Construct a new instance of {@code HttpServerErrorException} based on a {@link ClientHttpResponse} - * and {@link HttpMessageConverter}s to optionally help decoding the response body - * @param clientResponse the HTTP response - * @param messageConverters the message converters that may decode the HTTP response body + * Construct a new instance of {@code HttpServerErrorException} based on a + * {@link ClientHttpResponse} and {@link HttpMessageConverter}s to optionally + * help decoding the response body + * @param response the HTTP response + * @param converters the message converters that may decode the HTTP response body */ - public WebServerErrorException(ClientHttpResponse clientResponse, List> messageConverters) { - super(clientResponse.getStatusCode().value() + " " + clientResponse.getStatusCode().getReasonPhrase(), - clientResponse, messageConverters); + public WebServerErrorException(ClientHttpResponse response, List> converters) { + super(initMessage(response), response, converters); } + + private static String initMessage(ClientHttpResponse response) { + return response.getStatusCode().value() + " " + response.getStatusCode().getReasonPhrase(); + } + } diff --git a/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSession.java b/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSession.java index 7206027d22..22888bbc84 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSession.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSession.java @@ -30,6 +30,8 @@ import reactor.core.publisher.Mono; import org.springframework.util.Assert; /** + * Default implementation of {@link org.springframework.web.server.WebSession}. + * * @author Rossen Stoyanchev * @since 5.0 */