Skip to content

Commit 39f8bd6

Browse files
committed
Polishing
1 parent 4fdd853 commit 39f8bd6

File tree

17 files changed

+69
-105
lines changed

17 files changed

+69
-105
lines changed

spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,13 @@ public boolean canRead(ResolvableType elementType, MediaType mediaType) {
8181
}
8282

8383
@Override
84-
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message,
85-
Map<String, Object> hints) {
86-
84+
public Flux<T> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
8785
MediaType contentType = getContentType(message);
8886
return this.decoder.decode(message.getBody(), elementType, contentType, hints);
8987
}
9088

9189
@Override
92-
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message,
93-
Map<String, Object> hints) {
94-
90+
public Mono<T> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints) {
9591
MediaType contentType = getContentType(message);
9692
return this.decoder.decodeToMono(message.getBody(), elementType, contentType, hints);
9793
}

spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.core.ResolvableType;
2929
import org.springframework.core.codec.Encoder;
3030
import org.springframework.core.io.buffer.DataBuffer;
31-
import org.springframework.core.io.buffer.DataBufferFactory;
3231
import org.springframework.http.MediaType;
3332
import org.springframework.http.ReactiveHttpOutputMessage;
3433
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -92,17 +91,15 @@ public boolean canWrite(ResolvableType elementType, MediaType mediaType) {
9291

9392
@Override
9493
public Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
95-
MediaType mediaType, ReactiveHttpOutputMessage message,
96-
Map<String, Object> hints) {
94+
MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) {
9795

9896
MediaType contentType = updateContentType(message, mediaType);
99-
DataBufferFactory factory = message.bufferFactory();
10097

101-
Flux<DataBuffer> body = this.encoder.encode(inputStream, factory, elementType, contentType, hints);
98+
Flux<DataBuffer> body = this.encoder.encode(
99+
inputStream, message.bufferFactory(), elementType, contentType, hints);
102100

103-
return isStreamingMediaType(contentType) ?
104-
message.writeAndFlushWith(body.map(Flux::just)) :
105-
message.writeWith(body);
101+
return (isStreamingMediaType(contentType) ?
102+
message.writeAndFlushWith(body.map(Flux::just)) : message.writeWith(body));
106103
}
107104

108105
private MediaType updateContentType(ReactiveHttpOutputMessage message, MediaType mediaType) {
@@ -120,8 +117,8 @@ private MediaType updateContentType(ReactiveHttpOutputMessage message, MediaType
120117
}
121118

122119
private static boolean useFallback(MediaType main, MediaType fallback) {
123-
return main == null || !main.isConcrete() ||
124-
main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null;
120+
return (main == null || !main.isConcrete() ||
121+
main.equals(MediaType.APPLICATION_OCTET_STREAM) && fallback != null);
125122
}
126123

127124
private static MediaType addDefaultCharset(MediaType main, MediaType defaultType) {

spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -53,7 +53,6 @@ public class FormHttpMessageReader implements HttpMessageReader<MultiValueMap<St
5353
private static final ResolvableType MULTIVALUE_TYPE =
5454
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
5555

56-
5756
private Charset defaultCharset = DEFAULT_CHARSET;
5857

5958

@@ -63,7 +62,7 @@ public class FormHttpMessageReader implements HttpMessageReader<MultiValueMap<St
6362
* <p>By default this is set to "UTF-8".
6463
*/
6564
public void setDefaultCharset(Charset charset) {
66-
Assert.notNull(charset, "'charset' must not be null");
65+
Assert.notNull(charset, "Charset must not be null");
6766
this.defaultCharset = charset;
6867
}
6968

@@ -77,8 +76,8 @@ public Charset getDefaultCharset() {
7776

7877
@Override
7978
public boolean canRead(ResolvableType elementType, MediaType mediaType) {
80-
return MULTIVALUE_TYPE.isAssignableFrom(elementType) &&
81-
(mediaType == null || MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType));
79+
return (MULTIVALUE_TYPE.isAssignableFrom(elementType) &&
80+
(mediaType == null || MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)));
8281
}
8382

8483
@Override

spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public class FormHttpMessageWriter implements HttpMessageWriter<MultiValueMap<St
6262
* <p>By default this is set to "UTF-8".
6363
*/
6464
public void setDefaultCharset(Charset charset) {
65-
Assert.notNull(charset, "'charset' must not be null");
65+
Assert.notNull(charset, "Charset must not be null");
6666
this.defaultCharset = charset;
6767
}
6868

spring-web/src/main/java/org/springframework/http/codec/HttpMessageDecoder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public interface HttpMessageDecoder<T> extends Decoder<T> {
3535
/**
3636
* Get decoding hints based on the server request or annotations on the
3737
* target controller method parameter.
38-
*
3938
* @param actualType the actual target type to decode to, possibly a reactive
4039
* wrapper and sourced from {@link org.springframework.core.MethodParameter},
4140
* i.e. providing access to method parameter annotations.

spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.springframework.http.server.reactive.ServerHttpRequest;
2727
import org.springframework.http.server.reactive.ServerHttpResponse;
2828

29-
3029
/**
3130
* Extension of {@code Encoder} exposing extra methods relevant in the context
3231
* of HTTP request or response body encoding.
@@ -45,7 +44,6 @@ public interface HttpMessageEncoder<T> extends Encoder<T> {
4544
/**
4645
* Get decoding hints based on the server request or annotations on the
4746
* target controller method parameter.
48-
*
4947
* @param actualType the actual source type to encode, possibly a reactive
5048
* wrapper and sourced from {@link org.springframework.core.MethodParameter},
5149
* i.e. providing access to method annotations.

spring-web/src/main/java/org/springframework/http/codec/HttpMessageReader.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public interface HttpMessageReader<T> {
5757

5858
/**
5959
* Read from the input message and encode to a stream of objects.
60-
*
6160
* @param elementType the type of objects in the stream which must have been
6261
* previously checked via {@link #canRead(ResolvableType, MediaType)}
6362
* @param message the message to read from
@@ -68,7 +67,6 @@ public interface HttpMessageReader<T> {
6867

6968
/**
7069
* Read from the input message and encode to a single object.
71-
*
7270
* @param elementType the type of objects in the stream which must have been
7371
* previously checked via {@link #canRead(ResolvableType, MediaType)}
7472
* @param message the message to read from
@@ -79,12 +77,11 @@ public interface HttpMessageReader<T> {
7977

8078
/**
8179
* Server-side only alternative to
82-
* {@link #read(ResolvableType, ReactiveHttpInputMessage, Map)} with
83-
* additional context available.
84-
*
85-
* @param actualType the actual type of the target method parameter; for
86-
* annotated controllers, the {@link MethodParameter} can be accessed via
87-
* {@link ResolvableType#getSource()}.
80+
* {@link #read(ResolvableType, ReactiveHttpInputMessage, Map)}
81+
* with additional context available.
82+
* @param actualType the actual type of the target method parameter;
83+
* for annotated controllers, the {@link MethodParameter} can be accessed
84+
* via {@link ResolvableType#getSource()}.
8885
* @param elementType the type of Objects in the output stream
8986
* @param request the current request
9087
* @param response the current response
@@ -99,12 +96,11 @@ default Flux<T> read(ResolvableType actualType, ResolvableType elementType, Serv
9996

10097
/**
10198
* Server-side only alternative to
102-
* {@link #readMono(ResolvableType, ReactiveHttpInputMessage, Map)} with
103-
* additional, context available.
104-
*
105-
* @param actualType the actual type of the target method parameter; for
106-
* annotated controllers, the {@link MethodParameter} can be accessed via
107-
* {@link ResolvableType#getSource()}.
99+
* {@link #readMono(ResolvableType, ReactiveHttpInputMessage, Map)}
100+
* with additional, context available.
101+
* @param actualType the actual type of the target method parameter;
102+
* for annotated controllers, the {@link MethodParameter} can be accessed
103+
* via {@link ResolvableType#getSource()}.
108104
* @param elementType the type of Objects in the output stream
109105
* @param request the current request
110106
* @param response the current response

spring-web/src/main/java/org/springframework/http/codec/HttpMessageWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public interface HttpMessageWriter<T> {
6969
Mono<Void> write(Publisher<? extends T> inputStream, ResolvableType elementType,
7070
MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints);
7171

72-
7372
/**
7473
* Server-side only alternative to
7574
* {@link #write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)}

spring-web/src/main/java/org/springframework/http/codec/xml/JaxbContextContainer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,14 +26,14 @@
2626
import org.springframework.util.Assert;
2727

2828
/**
29+
* Holder for {@link JAXBContext} isntances.
30+
*
2931
* @author Arjen Poutsma
3032
* @since 5.0
3133
*/
3234
final class JaxbContextContainer {
3335

34-
35-
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts =
36-
new ConcurrentHashMap<>(64);
36+
private final ConcurrentMap<Class<?>, JAXBContext> jaxbContexts = new ConcurrentHashMap<>(64);
3737

3838

3939
public Marshaller createMarshaller(Class<?> clazz) throws JAXBException {
@@ -47,7 +47,7 @@ public Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException {
4747
}
4848

4949
private JAXBContext getJaxbContext(Class<?> clazz) throws JAXBException {
50-
Assert.notNull(clazz, "'clazz' must not be null");
50+
Assert.notNull(clazz, "Class must not be null");
5151
JAXBContext jaxbContext = this.jaxbContexts.get(clazz);
5252
if (jaxbContext == null) {
5353
jaxbContext = JAXBContext.newInstance(clazz);

spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -109,9 +109,9 @@ public T extractData(ClientHttpResponse response) throws IOException {
109109
}
110110
}
111111
}
112-
catch(IOException | HttpMessageNotReadableException exc) {
113-
throw new RestClientException("Error while extracting response for type ["
114-
+ this.responseType + "] and content type [" + contentType + "]", exc);
112+
catch (IOException | HttpMessageNotReadableException ex) {
113+
throw new RestClientException("Error while extracting response for type [" +
114+
this.responseType + "] and content type [" + contentType + "]", ex);
115115
}
116116

117117
throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " +

0 commit comments

Comments
 (0)