Polishing
This commit is contained in:
@@ -81,17 +81,13 @@ public class DecoderHttpMessageReader<T> implements HttpMessageReader<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message,
|
||||
Map<String, Object> hints) {
|
||||
|
||||
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
|
||||
MediaType contentType = getContentType(message);
|
||||
return this.decoder.decode(message.getBody(), elementType, contentType, hints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message,
|
||||
Map<String, Object> hints) {
|
||||
|
||||
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
|
||||
MediaType contentType = getContentType(message);
|
||||
return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ReactiveHttpOutputMessage;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
@@ -92,17 +91,15 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
|
||||
|
||||
@Override
|
||||
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
|
||||
MediaType mediaType, ReactiveHttpOutputMessage message,
|
||||
Map<String, Object> hints) {
|
||||
MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) {
|
||||
|
||||
MediaType contentType = updateContentType(message, mediaType);
|
||||
DataBufferFactory factory = message.bufferFactory();
|
||||
|
||||
Flux<DataBuffer> body = this.encoder.encode(inputStream, factory, elementType, contentType, hints);
|
||||
Flux<DataBuffer> body = this.encoder.encode(
|
||||
inputStream, message.bufferFactory(), elementType, contentType, hints);
|
||||
|
||||
return isStreamingMediaType(contentType) ?
|
||||
message.writeAndFlushWith(body.map(Flux::just)) :
|
||||
message.writeWith(body);
|
||||
return (isStreamingMediaType(contentType) ?
|
||||
message.writeAndFlushWith(body.map(Flux::just)) : message.writeWith(body));
|
||||
}
|
||||
|
||||
private MediaType updateContentType(ReactiveHttpOutputMessage message, MediaType mediaType) {
|
||||
@@ -120,8 +117,8 @@ public class EncoderHttpMessageWriter<T> implements HttpMessageWriter<T> {
|
||||
}
|
||||
|
||||
private static boolean useFallback(MediaType main, MediaType fallback) {
|
||||
return main == null || !main.isConcrete() ||
|
||||
main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null;
|
||||
return (main == null || !main.isConcrete() ||
|
||||
main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null);
|
||||
}
|
||||
|
||||
private static MediaType addDefaultCharset(MediaType main, MediaType defaultType) {
|
||||
|
||||
@@ -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.
|
||||
@@ -53,7 +53,6 @@ public class FormHttpMessageReader implements HttpMessageReader<MultiValueMap<St
|
||||
private static final ResolvableType MULTIVALUE_TYPE =
|
||||
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
|
||||
private Charset defaultCharset = DEFAULT_CHARSET;
|
||||
|
||||
|
||||
@@ -63,7 +62,7 @@ public class FormHttpMessageReader implements HttpMessageReader<MultiValueMap<St
|
||||
* <p>By default this is set to "UTF-8".
|
||||
*/
|
||||
public void setDefaultCharset(Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
Assert.notNull(charset, "Charset must not be null");
|
||||
this.defaultCharset = charset;
|
||||
}
|
||||
|
||||
@@ -77,8 +76,8 @@ public class FormHttpMessageReader implements HttpMessageReader<MultiValueMap<St
|
||||
|
||||
@Override
|
||||
public boolean canRead(ResolvableType elementType, MediaType mediaType) {
|
||||
return MULTIVALUE_TYPE.isAssignableFrom(elementType) &&
|
||||
(mediaType == null || MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType));
|
||||
return (MULTIVALUE_TYPE.isAssignableFrom(elementType) &&
|
||||
(mediaType == null || MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.
|
||||
@@ -62,7 +62,7 @@ public class FormHttpMessageWriter implements HttpMessageWriter<MultiValueMap<St
|
||||
* <p>By default this is set to "UTF-8".
|
||||
*/
|
||||
public void setDefaultCharset(Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
Assert.notNull(charset, "Charset must not be null");
|
||||
this.defaultCharset = charset;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ public interface HttpMessageDecoder<T> extends Decoder<T> {
|
||||
/**
|
||||
* Get decoding hints based on the server request or annotations on the
|
||||
* target controller method parameter.
|
||||
*
|
||||
* @param actualType the actual target type to decode to, possibly a reactive
|
||||
* wrapper and sourced from {@link org.springframework.core.MethodParameter},
|
||||
* i.e. providing access to method parameter annotations.
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Extension of {@code Encoder} exposing extra methods relevant in the context
|
||||
* of HTTP request or response body encoding.
|
||||
@@ -45,7 +44,6 @@ public interface HttpMessageEncoder<T> extends Encoder<T> {
|
||||
/**
|
||||
* Get decoding hints based on the server request or annotations on the
|
||||
* target controller method parameter.
|
||||
*
|
||||
* @param actualType the actual source type to encode, possibly a reactive
|
||||
* wrapper and sourced from {@link org.springframework.core.MethodParameter},
|
||||
* i.e. providing access to method annotations.
|
||||
|
||||
@@ -57,7 +57,6 @@ public interface HttpMessageReader<T> {
|
||||
|
||||
/**
|
||||
* Read from the input message and encode to a stream of objects.
|
||||
*
|
||||
* @param elementType the type of objects in the stream which must have been
|
||||
* previously checked via {@link #canRead(ResolvableType, MediaType)}
|
||||
* @param message the message to read from
|
||||
@@ -68,7 +67,6 @@ public interface HttpMessageReader<T> {
|
||||
|
||||
/**
|
||||
* Read from the input message and encode to a single object.
|
||||
*
|
||||
* @param elementType the type of objects in the stream which must have been
|
||||
* previously checked via {@link #canRead(ResolvableType, MediaType)}
|
||||
* @param message the message to read from
|
||||
@@ -79,12 +77,11 @@ public interface HttpMessageReader<T> {
|
||||
|
||||
/**
|
||||
* Server-side only alternative to
|
||||
* {@link #read(ResolvableType, ReactiveHttpInputMessage, Map)} with
|
||||
* additional context available.
|
||||
*
|
||||
* @param actualType the actual type of the target method parameter; for
|
||||
* annotated controllers, the {@link MethodParameter} can be accessed via
|
||||
* {@link ResolvableType#getSource()}.
|
||||
* {@link #read(ResolvableType, ReactiveHttpInputMessage, Map)}
|
||||
* with additional context available.
|
||||
* @param actualType the actual type of the target method parameter;
|
||||
* for annotated controllers, the {@link MethodParameter} can be accessed
|
||||
* via {@link ResolvableType#getSource()}.
|
||||
* @param elementType the type of Objects in the output stream
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
@@ -99,12 +96,11 @@ public interface HttpMessageReader<T> {
|
||||
|
||||
/**
|
||||
* Server-side only alternative to
|
||||
* {@link #readMono(ResolvableType, ReactiveHttpInputMessage, Map)} with
|
||||
* additional, context available.
|
||||
*
|
||||
* @param actualType the actual type of the target method parameter; for
|
||||
* annotated controllers, the {@link MethodParameter} can be accessed via
|
||||
* {@link ResolvableType#getSource()}.
|
||||
* {@link #readMono(ResolvableType, ReactiveHttpInputMessage, Map)}
|
||||
* with additional, context available.
|
||||
* @param actualType the actual type of the target method parameter;
|
||||
* for annotated controllers, the {@link MethodParameter} can be accessed
|
||||
* via {@link ResolvableType#getSource()}.
|
||||
* @param elementType the type of Objects in the output stream
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
|
||||
@@ -69,7 +69,6 @@ public interface HttpMessageWriter<T> {
|
||||
Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
|
||||
MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints);
|
||||
|
||||
|
||||
/**
|
||||
* Server-side only alternative to
|
||||
* {@link #write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)}
|
||||
|
||||
@@ -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.
|
||||
@@ -26,14 +26,14 @@ import javax.xml.bind.Unmarshaller;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Holder for {@link JAXBContext} isntances.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.0
|
||||
*/
|
||||
final class JaxbContextContainer {
|
||||
|
||||
|
||||
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts =
|
||||
new ConcurrentHashMap<>(64);
|
||||
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<>(64);
|
||||
|
||||
|
||||
public Marshaller createMarshaller(Class<?> clazz) throws JAXBException {
|
||||
@@ -47,7 +47,7 @@ final class JaxbContextContainer {
|
||||
}
|
||||
|
||||
private JAXBContext getJaxbContext(Class<?> clazz) throws JAXBException {
|
||||
Assert.notNull(clazz, "'clazz' must not be null");
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
JAXBContext jaxbContext = this.jaxbContexts.get(clazz);
|
||||
if (jaxbContext == null) {
|
||||
jaxbContext = JAXBContext.newInstance(clazz);
|
||||
|
||||
@@ -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.
|
||||
@@ -109,9 +109,9 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(IOException | HttpMessageNotReadableException exc) {
|
||||
throw new RestClientException("Error while extracting response for type ["
|
||||
+ this.responseType + "] and content type [" + contentType + "]", exc);
|
||||
catch (IOException | HttpMessageNotReadableException ex) {
|
||||
throw new RestClientException("Error while extracting response for type [" +
|
||||
this.responseType + "] and content type [" + contentType + "]", ex);
|
||||
}
|
||||
|
||||
throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " +
|
||||
|
||||
Reference in New Issue
Block a user