Skip to content

Commit 6242e30

Browse files
committed
Polishing
1 parent 7582adc commit 6242e30

File tree

55 files changed

+346
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+346
-470
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*
2929
* @param <T> the type of data to extract
3030
* @param <M> the type of {@link ReactiveHttpInputMessage} this extractor can be applied to
31+
*
3132
* @author Arjen Poutsma
3233
* @since 5.0
3334
* @see BodyExtractors
@@ -37,20 +38,21 @@ public interface BodyExtractor<T, M extends ReactiveHttpInputMessage> {
3738

3839
/**
3940
* Extract from the given input message.
40-
* @param inputMessage request to extract from
41+
* @param inputMessage the request to extract from
4142
* @param context the configuration to use
4243
* @return the extracted data
4344
*/
4445
T extract(M inputMessage, Context context);
4546

47+
4648
/**
4749
* Defines the context used during the extraction.
4850
*/
4951
interface Context {
5052

5153
/**
52-
* Supply a {@linkplain Stream stream} of {@link HttpMessageReader}s to be used for body
53-
* extraction.
54+
* Supply a {@linkplain Stream stream} of {@link HttpMessageReader}s
55+
* to be used for body extraction.
5456
* @return the stream of message readers
5557
*/
5658
Supplier<Stream<HttpMessageReader<?>>> messageReaders();

spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyExtractors.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,6 @@ public static BodyExtractor<Mono<MultiValueMap<String, String>>, ServerHttpReque
112112
};
113113
}
114114

115-
private static HttpMessageReader<MultiValueMap<String, String>> formMessageReader(BodyExtractor.Context context) {
116-
return context.messageReaders().get()
117-
.filter(messageReader -> messageReader
118-
.canRead(FORM_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
119-
.findFirst()
120-
.map(BodyExtractors::<MultiValueMap<String, String>>cast)
121-
.orElseThrow(() -> new IllegalStateException(
122-
"Could not find HttpMessageReader that supports " +
123-
MediaType.APPLICATION_FORM_URLENCODED_VALUE));
124-
}
125-
126-
127115
/**
128116
* Return a {@code BodyExtractor} that returns the body of the message as a {@link Flux} of
129117
* {@link DataBuffer}s.
@@ -136,12 +124,10 @@ public static BodyExtractor<Flux<DataBuffer>, ReactiveHttpInputMessage> toDataBu
136124
return (inputMessage, context) -> inputMessage.getBody();
137125
}
138126

127+
139128
private static <T, S extends Publisher<T>> S readWithMessageReaders(
140-
ReactiveHttpInputMessage inputMessage,
141-
BodyExtractor.Context context,
142-
ResolvableType elementType,
143-
Function<HttpMessageReader<T>, S> readerFunction,
144-
Function<Throwable, S> unsupportedError) {
129+
ReactiveHttpInputMessage inputMessage, BodyExtractor.Context context, ResolvableType elementType,
130+
Function<HttpMessageReader<T>, S> readerFunction, Function<Throwable, S> unsupportedError) {
145131

146132
MediaType contentType = contentType(inputMessage);
147133
Supplier<Stream<HttpMessageReader<?>>> messageReaders = context.messageReaders();
@@ -160,6 +146,17 @@ private static <T, S extends Publisher<T>> S readWithMessageReaders(
160146
});
161147
}
162148

149+
private static HttpMessageReader<MultiValueMap<String, String>> formMessageReader(BodyExtractor.Context context) {
150+
return context.messageReaders().get()
151+
.filter(messageReader -> messageReader
152+
.canRead(FORM_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
153+
.findFirst()
154+
.map(BodyExtractors::<MultiValueMap<String, String>>cast)
155+
.orElseThrow(() -> new IllegalStateException(
156+
"Could not find HttpMessageReader that supports " +
157+
MediaType.APPLICATION_FORM_URLENCODED_VALUE));
158+
}
159+
163160
private static MediaType contentType(HttpMessage message) {
164161
MediaType result = message.getHeaders().getContentType();
165162
return result != null ? result : MediaType.APPLICATION_OCTET_STREAM;

spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*
3131
* @param <T> the type of data to insert
3232
* @param <M> the type of {@link ReactiveHttpOutputMessage} this inserter can be applied to
33+
*
3334
* @author Arjen Poutsma
3435
* @since 5.0
3536
* @see BodyInserters
@@ -45,14 +46,15 @@ public interface BodyInserter<T, M extends ReactiveHttpOutputMessage> {
4546
*/
4647
Mono<Void> insert(M outputMessage, Context context);
4748

49+
4850
/**
4951
* Defines the context used during the insertion.
5052
*/
5153
interface Context {
5254

5355
/**
54-
* Supply a {@linkplain Stream stream} of {@link HttpMessageWriter}s to be used for response
55-
* body conversion.
56+
* Supply a {@linkplain Stream stream} of {@link HttpMessageWriter}s
57+
* to be used for response body conversion.
5658
* @return the stream of message writers
5759
*/
5860
Supplier<Stream<HttpMessageWriter<?>>> messageWriters();
@@ -61,8 +63,6 @@ interface Context {
6163
* Return the map of hints to use for response body conversion.
6264
*/
6365
Map<String, Object> hints();
64-
6566
}
6667

67-
6868
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
*/
4646
public abstract class BodyInserters {
4747

48-
private static final ResolvableType RESOURCE_TYPE = ResolvableType.forClass(Resource.class);
48+
private static final ResolvableType RESOURCE_TYPE =
49+
ResolvableType.forClass(Resource.class);
4950

5051
private static final ResolvableType SERVER_SIDE_EVENT_TYPE =
5152
ResolvableType.forClass(ServerSentEvent.class);
5253

5354
private static final ResolvableType FORM_TYPE =
5455
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
5556

56-
5757
private static final BodyInserter<Void, ReactiveHttpOutputMessage> EMPTY =
5858
(response, context) -> response.setComplete();
5959

@@ -223,19 +223,6 @@ public static BodyInserter<MultiValueMap<String, String>, ClientHttpRequest> fro
223223
};
224224
}
225225

226-
private static <T> HttpMessageWriter<T> findMessageWriter(
227-
BodyInserter.Context context, ResolvableType type, MediaType mediaType) {
228-
229-
return context.messageWriters().get()
230-
.filter(messageWriter -> messageWriter.canWrite(type, mediaType))
231-
.findFirst()
232-
.map(BodyInserters::<T>cast)
233-
.orElseThrow(() -> new IllegalStateException(
234-
"Could not find HttpMessageWriter that supports " + mediaType));
235-
}
236-
237-
238-
239226
/**
240227
* Return a {@code BodyInserter} that writes the given {@code Publisher<DataBuffer>} to the body.
241228
* @param publisher the data buffer publisher to write
@@ -274,6 +261,17 @@ private static <T, P extends Publisher<?>, M extends ReactiveHttpOutputMessage>
274261
};
275262
}
276263

264+
private static <T> HttpMessageWriter<T> findMessageWriter(
265+
BodyInserter.Context context, ResolvableType type, MediaType mediaType) {
266+
267+
return context.messageWriters().get()
268+
.filter(messageWriter -> messageWriter.canWrite(type, mediaType))
269+
.findFirst()
270+
.map(BodyInserters::<T>cast)
271+
.orElseThrow(() -> new IllegalStateException(
272+
"Could not find HttpMessageWriter that supports " + mediaType));
273+
}
274+
277275
@SuppressWarnings("unchecked")
278276
private static <T> HttpMessageWriter<T> cast(HttpMessageWriter<?> messageWriter) {
279277
return (HttpMessageWriter<T>) messageWriter;

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public interface ClientRequest {
8181

8282
/**
8383
* Create a builder with the method, URI, headers, and cookies of the given request.
84-
*
8584
* @param other the request to copy the method, URI, headers, and cookies from
8685
* @return the created builder
8786
*/
@@ -120,7 +119,6 @@ interface Builder {
120119

121120
/**
122121
* Copy the given headers into the entity's headers map.
123-
*
124122
* @param headers the existing HttpHeaders to copy from
125123
* @return this builder
126124
*/
@@ -136,7 +134,6 @@ interface Builder {
136134

137135
/**
138136
* Copy the given cookies into the entity's cookies map.
139-
*
140137
* @param cookies the existing cookies to copy from
141138
* @return this builder
142139
*/
@@ -164,7 +161,6 @@ interface Builder {
164161
* @return the request entity
165162
*/
166163
ClientRequest build();
167-
168164
}
169165

170166
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ interface Headers {
110110
/**
111111
* Return the header value(s), if any, for the header of the given name.
112112
* <p>Return an empty list if no header values are found.
113-
*
114113
* @param headerName the header name
115114
*/
116115
List<String> header(String headerName);

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public DefaultClientRequestBuilder(HttpMethod method, URI url) {
6161
this.url = url;
6262
}
6363

64+
6465
@Override
6566
public ClientRequest.Builder header(String headerName, String... headerValues) {
6667
for (String headerValue : headerValues) {
@@ -113,6 +114,7 @@ public ClientRequest build() {
113114
this.inserter);
114115
}
115116

117+
116118
private static class BodyInserterRequest implements ClientRequest {
117119

118120
private final HttpMethod method;
@@ -126,8 +128,8 @@ private static class BodyInserterRequest implements ClientRequest {
126128
private final BodyInserter<?, ? super ClientHttpRequest> inserter;
127129

128130
public BodyInserterRequest(HttpMethod method, URI url, HttpHeaders headers,
129-
MultiValueMap<String, String> cookies,
130-
BodyInserter<?, ? super ClientHttpRequest> inserter) {
131+
MultiValueMap<String, String> cookies, BodyInserter<?, ? super ClientHttpRequest> inserter) {
132+
131133
this.method = method;
132134
this.url = url;
133135
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
@@ -169,6 +171,7 @@ public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategi
169171
.forEach(entry -> requestHeaders
170172
.put(entry.getKey(), entry.getValue()));
171173
}
174+
172175
MultiValueMap<String, HttpCookie> requestCookies = request.getCookies();
173176
if (!this.cookies.isEmpty()) {
174177
this.cookies.entrySet().forEach(entry -> {
@@ -185,12 +188,12 @@ public Mono<Void> writeTo(ClientHttpRequest request, ExchangeStrategies strategi
185188
public Supplier<Stream<HttpMessageWriter<?>>> messageWriters() {
186189
return strategies.messageWriters();
187190
}
188-
189191
@Override
190192
public Map<String, Object> hints() {
191193
return Collections.emptyMap();
192194
}
193195
});
194196
}
195197
}
198+
196199
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public DefaultClientResponse(ClientHttpResponse response, ExchangeStrategies str
6060
this.headers = new DefaultHeaders();
6161
}
6262

63+
6364
@Override
6465
public HttpStatus statusCode() {
6566
return this.response.getStatusCode();
@@ -99,6 +100,7 @@ public <T> Flux<T> bodyToFlux(Class<? extends T> elementClass) {
99100
return bodyToPublisher(BodyExtractors.toFlux(elementClass), Flux::error);
100101
}
101102

103+
102104
private <T extends Publisher<?>> T bodyToPublisher(
103105
BodyExtractor<T, ? super ClientHttpResponse> extractor,
104106
Function<WebClientException, T> errorFunction) {
@@ -115,6 +117,7 @@ private <T extends Publisher<?>> T bodyToPublisher(
115117
}
116118
}
117119

120+
118121
private class DefaultHeaders implements Headers {
119122

120123
private HttpHeaders delegate() {

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultExchangeStrategiesBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,16 @@ public ExchangeStrategies build() {
130130
return new DefaultExchangeStrategies(this.messageReaders, this.messageWriters);
131131
}
132132

133+
133134
private static class DefaultExchangeStrategies implements ExchangeStrategies {
134135

135136
private final List<HttpMessageReader<?>> messageReaders;
136137

137138
private final List<HttpMessageWriter<?>> messageWriters;
138139

139140
public DefaultExchangeStrategies(
140-
List<HttpMessageReader<?>> messageReaders,
141-
List<HttpMessageWriter<?>> messageWriters) {
141+
List<HttpMessageReader<?>> messageReaders, List<HttpMessageWriter<?>> messageWriters) {
142+
142143
this.messageReaders = unmodifiableCopy(messageReaders);
143144
this.messageWriters = unmodifiableCopy(messageWriters);
144145
}
@@ -156,7 +157,6 @@ public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
156157
public Supplier<Stream<HttpMessageWriter<?>>> messageWriters() {
157158
return this.messageWriters::stream;
158159
}
159-
160160
}
161161

162162
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
public interface ExchangeFilterFunction {
3333

3434
/**
35-
* Apply this filter to the given request and exchange function. The given
36-
* {@linkplain ExchangeFunction exchange function} represents the next entity in the
37-
* chain, and can be {@linkplain ExchangeFunction#exchange(ClientRequest) invoked} in order
38-
* to proceed to the exchange, or not invoked to block the chain.
39-
*
35+
* Apply this filter to the given request and exchange function.
36+
* <p>The given {@linkplain ExchangeFunction exchange function} represents the next entity
37+
* in the chain, and can be {@linkplain ExchangeFunction#exchange(ClientRequest) invoked}
38+
* in order to proceed to the exchange, or not invoked to block the chain.
4039
* @param request the request
4140
* @param next the next exchange function in the chain
4241
* @return the filtered response

0 commit comments

Comments
 (0)