Skip to content

Commit 8dbe753

Browse files
committed
Polishing
1 parent 23fa37b commit 8dbe753

File tree

10 files changed

+107
-107
lines changed

10 files changed

+107
-107
lines changed

spring-core/src/main/java/org/springframework/core/MethodParameter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -309,6 +309,7 @@ public Class<?> getParameterType() {
309309
/**
310310
* Return the generic type of the method/constructor parameter.
311311
* @return the parameter type (never {@code null})
312+
* @since 3.0
312313
*/
313314
public Type getGenericParameterType() {
314315
if (this.genericParameterType == null) {
@@ -324,6 +325,12 @@ public Type getGenericParameterType() {
324325
return this.genericParameterType;
325326
}
326327

328+
/**
329+
* Return the nested type of the method/constructor parameter.
330+
* @return the parameter type (never {@code null})
331+
* @see #getNestingLevel()
332+
* @since 3.1
333+
*/
327334
public Class<?> getNestedParameterType() {
328335
if (this.nestingLevel > 1) {
329336
Type type = getGenericParameterType();

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -1092,9 +1092,8 @@ public static ResolvableType forMethodParameter(MethodParameter methodParameter,
10921092
public static ResolvableType forMethodParameter(MethodParameter methodParameter, Type targetType) {
10931093
Assert.notNull(methodParameter, "MethodParameter must not be null");
10941094
ResolvableType owner = forType(methodParameter.getContainingClass()).as(methodParameter.getDeclaringClass());
1095-
return forType(targetType, new MethodParameterTypeProvider(methodParameter),
1096-
owner.asVariableResolver()).getNested(methodParameter.getNestingLevel(),
1097-
methodParameter.typeIndexesPerLevel);
1095+
return forType(targetType, new MethodParameterTypeProvider(methodParameter), owner.asVariableResolver()).
1096+
getNested(methodParameter.getNestingLevel(), methodParameter.typeIndexesPerLevel);
10981097
}
10991098

11001099
/**

spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -32,10 +32,10 @@
3232
import org.springframework.util.MimeType;
3333

3434
/**
35-
* Abstract base class for {@link MessageConverter} implementations including support for
36-
* common properties and a partial implementation of the conversion methods mainly to
37-
* check if the converter supports the conversion based on the payload class and MIME
38-
* type.
35+
* Abstract base class for {@link MessageConverter} implementations including support
36+
* for common properties and a partial implementation of the conversion methods,
37+
* mainly to check if the converter supports the conversion based on the payload class
38+
* and MIME type.
3939
*
4040
* @author Rossen Stoyanchev
4141
* @since 4.0
@@ -68,7 +68,7 @@ protected AbstractMessageConverter(MimeType supportedMimeType) {
6868
* @param supportedMimeTypes the supported MIME types
6969
*/
7070
protected AbstractMessageConverter(Collection<MimeType> supportedMimeTypes) {
71-
Assert.notNull(supportedMimeTypes, "SupportedMimeTypes must not be null");
71+
Assert.notNull(supportedMimeTypes, "supportedMimeTypes must not be null");
7272
this.supportedMimeTypes = new ArrayList<MimeType>(supportedMimeTypes);
7373
}
7474

@@ -83,13 +83,11 @@ public List<MimeType> getSupportedMimeTypes() {
8383
/**
8484
* Configure the {@link ContentTypeResolver} to use to resolve the content
8585
* type of an input message.
86-
* <p>
87-
* Note that if no resolver is configured, then
86+
* <p>Note that if no resolver is configured, then
8887
* {@link #setStrictContentTypeMatch(boolean) strictContentTypeMatch} should
8988
* be left as {@code false} (the default) or otherwise this converter will
9089
* ignore all messages.
91-
* <p>
92-
* By default, a {@code DefaultContentTypeResolver} instance is used.
90+
* <p>By default, a {@code DefaultContentTypeResolver} instance is used.
9391
*/
9492
public void setContentTypeResolver(ContentTypeResolver resolver) {
9593
this.contentTypeResolver = resolver;
@@ -106,20 +104,17 @@ public ContentTypeResolver getContentTypeResolver() {
106104
* Whether this converter should convert messages for which no content type
107105
* could be resolved through the configured
108106
* {@link org.springframework.messaging.converter.ContentTypeResolver}.
109-
* A converter can configured to be strict only when a
110-
* {@link #setContentTypeResolver(ContentTypeResolver) contentTypeResolver}
111-
* is configured and the list of {@link #getSupportedMimeTypes() supportedMimeTypes}
112-
* is not be empty.
113-
*
114-
* then requires the content type of a message to be resolved
115-
*
116-
* When set to true, #supportsMimeType(MessageHeaders) will return false if the
117-
* contentTypeResolver is not defined or if no content-type header is present.
107+
* <p>A converter can configured to be strict only when a
108+
* {@link #setContentTypeResolver contentTypeResolver} is configured and the
109+
* list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty.
110+
* <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)}
111+
* will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver}
112+
* is not defined or if no content-type header is present.
118113
*/
119114
public void setStrictContentTypeMatch(boolean strictContentTypeMatch) {
120115
if (strictContentTypeMatch) {
121-
Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types.");
122-
Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver.");
116+
Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types");
117+
Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver");
123118
}
124119
this.strictContentTypeMatch = strictContentTypeMatch;
125120
}
@@ -166,14 +161,6 @@ protected MimeType getDefaultContentType(Object payload) {
166161
return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null);
167162
}
168163

169-
/**
170-
* Whether the given class is supported by this converter.
171-
* @param clazz the class to test for support
172-
* @return {@code true} if supported; {@code false} otherwise
173-
*/
174-
protected abstract boolean supports(Class<?> clazz);
175-
176-
177164
@Override
178165
public final Object fromMessage(Message<?> message, Class<?> targetClass) {
179166
if (!canConvertFrom(message, targetClass)) {
@@ -186,14 +173,8 @@ protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
186173
return (supports(targetClass) && supportsMimeType(message.getHeaders()));
187174
}
188175

189-
/**
190-
* Convert the message payload from serialized form to an Object.
191-
*/
192-
public abstract Object convertFromInternal(Message<?> message, Class<?> targetClass);
193-
194176
@Override
195177
public final Message<?> toMessage(Object payload, MessageHeaders headers) {
196-
197178
if (!canConvertTo(payload, headers)) {
198179
return null;
199180
}
@@ -218,15 +199,10 @@ public final Message<?> toMessage(Object payload, MessageHeaders headers) {
218199
}
219200

220201
protected boolean canConvertTo(Object payload, MessageHeaders headers) {
221-
Class<?> clazz = (payload != null) ? payload.getClass() : null;
202+
Class<?> clazz = (payload != null ? payload.getClass() : null);
222203
return (supports(clazz) && supportsMimeType(headers));
223204
}
224205

225-
/**
226-
* Convert the payload object to serialized form.
227-
*/
228-
public abstract Object convertToInternal(Object payload, MessageHeaders headers);
229-
230206
protected boolean supportsMimeType(MessageHeaders headers) {
231207
if (getSupportedMimeTypes().isEmpty()) {
232208
return true;
@@ -249,7 +225,26 @@ protected boolean supportsMimeType(MessageHeaders headers) {
249225
}
250226

251227
protected MimeType getMimeType(MessageHeaders headers) {
252-
return (this.contentTypeResolver != null) ? this.contentTypeResolver.resolve(headers) : null;
228+
return (this.contentTypeResolver != null ? this.contentTypeResolver.resolve(headers) : null);
253229
}
254230

231+
232+
/**
233+
* Whether the given class is supported by this converter.
234+
* @param clazz the class to test for support
235+
* @return {@code true} if supported; {@code false} otherwise
236+
*/
237+
protected abstract boolean supports(Class<?> clazz);
238+
239+
/**
240+
* Convert the message payload from serialized form to an Object.
241+
*/
242+
public abstract Object convertFromInternal(Message<?> message, Class<?> targetClass);
243+
244+
245+
/**
246+
* Convert the payload object to serialized form.
247+
*/
248+
public abstract Object convertToInternal(Object payload, MessageHeaders headers);
249+
255250
}

spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -29,7 +29,6 @@
2929
* @author Arjen Poutsma
3030
* @author Rossen Stoyanchev
3131
* @since 3.2
32-
*
3332
* @see org.springframework.core.ParameterizedTypeReference
3433
*/
3534
public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T> {
@@ -38,7 +37,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
3837
* Indicates whether the given type can be read by this converter.
3938
* @param type the type to test for readability
4039
* @param contextClass a context class for the target type, for example a class
41-
* in which the target type appears in a method signature, can be {@code null}
40+
* in which the target type appears in a method signature (can be {@code null})
4241
* @param mediaType the media type to read, can be {@code null} if not specified.
4342
* Typically the value of a {@code Content-Type} header.
4443
* @return {@code true} if readable; {@code false} otherwise
@@ -51,7 +50,7 @@ public interface GenericHttpMessageConverter<T> extends HttpMessageConverter<T>
5150
* been passed to the {@link #canRead canRead} method of this interface,
5251
* which must have returned {@code true}.
5352
* @param contextClass a context class for the target type, for example a class
54-
* in which the target type appears in a method signature, can be {@code null}
53+
* in which the target type appears in a method signature (can be {@code null})
5554
* @param inputMessage the HTTP input message to read from
5655
* @return the converted object
5756
* @throws IOException in case of I/O errors

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -596,7 +596,7 @@ private void logResponseStatus(HttpMethod method, URI url, ClientHttpResponse re
596596
logger.debug(method.name() + " request for \"" + url + "\" resulted in " +
597597
response.getRawStatusCode() + " (" + response.getStatusText() + ")");
598598
}
599-
catch (IOException e) {
599+
catch (IOException ex) {
600600
// ignore
601601
}
602602
}
@@ -608,7 +608,7 @@ private void handleResponseError(HttpMethod method, URI url, ClientHttpResponse
608608
logger.warn(method.name() + " request for \"" + url + "\" resulted in " +
609609
response.getRawStatusCode() + " (" + response.getStatusText() + "); invoking error handler");
610610
}
611-
catch (IOException e) {
611+
catch (IOException ex) {
612612
// ignore
613613
}
614614
}
@@ -668,12 +668,11 @@ private AcceptHeaderRequestCallback(Type responseType) {
668668

669669
@Override
670670
public void doWithRequest(ClientHttpRequest request) throws IOException {
671-
if (responseType != null) {
671+
if (this.responseType != null) {
672672
Class<?> responseClass = null;
673-
if (responseType instanceof Class) {
674-
responseClass = (Class<?>) responseType;
673+
if (this.responseType instanceof Class) {
674+
responseClass = (Class<?>) this.responseType;
675675
}
676-
677676
List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
678677
for (HttpMessageConverter<?> converter : getMessageConverters()) {
679678
if (responseClass != null) {
@@ -682,13 +681,11 @@ public void doWithRequest(ClientHttpRequest request) throws IOException {
682681
}
683682
}
684683
else if (converter instanceof GenericHttpMessageConverter) {
685-
686684
GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
687-
if (genericConverter.canRead(responseType, null, null)) {
685+
if (genericConverter.canRead(this.responseType, null, null)) {
688686
allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
689687
}
690688
}
691-
692689
}
693690
if (!allSupportedMediaTypes.isEmpty()) {
694691
MediaType.sortBySpecificity(allSupportedMediaTypes);
@@ -744,9 +741,9 @@ else if (requestBody != null) {
744741
@SuppressWarnings("unchecked")
745742
public void doWithRequest(ClientHttpRequest httpRequest) throws IOException {
746743
super.doWithRequest(httpRequest);
747-
if (!requestEntity.hasBody()) {
744+
if (!this.requestEntity.hasBody()) {
748745
HttpHeaders httpHeaders = httpRequest.getHeaders();
749-
HttpHeaders requestHeaders = requestEntity.getHeaders();
746+
HttpHeaders requestHeaders = this.requestEntity.getHeaders();
750747
if (!requestHeaders.isEmpty()) {
751748
httpHeaders.putAll(requestHeaders);
752749
}
@@ -755,9 +752,9 @@ public void doWithRequest(ClientHttpRequest httpRequest) throws IOException {
755752
}
756753
}
757754
else {
758-
Object requestBody = requestEntity.getBody();
755+
Object requestBody = this.requestEntity.getBody();
759756
Class<?> requestType = requestBody.getClass();
760-
HttpHeaders requestHeaders = requestEntity.getHeaders();
757+
HttpHeaders requestHeaders = this.requestEntity.getHeaders();
761758
MediaType requestContentType = requestHeaders.getContentType();
762759
for (HttpMessageConverter<?> messageConverter : getMessageConverters()) {
763760
if (messageConverter.canWrite(requestType, requestContentType)) {

spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ public static UriComponentsBuilder fromHttpUrl(String httpUrl) {
268268
* Create a new {@code UriComponents} object from the URI associated with
269269
* the given HttpRequest while also overlaying with values from the headers
270270
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if present.
271-
*
272271
* @param request the source request
273-
* @return the URI components of the UR
272+
* @return the URI components of the URI
273+
* @since 4.1.5
274274
*/
275275
public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
276276
URI uri = request.getURI();

spring-web/src/main/java/org/springframework/web/util/WebUtils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import java.io.File;
2020
import java.io.FileNotFoundException;
21+
import java.util.Collection;
2122
import java.util.Enumeration;
22-
import java.util.List;
2323
import java.util.Map;
2424
import java.util.StringTokenizer;
2525
import java.util.TreeMap;
@@ -33,7 +33,7 @@
3333
import javax.servlet.http.HttpServletResponse;
3434
import javax.servlet.http.HttpSession;
3535

36-
import org.springframework.http.server.ServerHttpRequest;
36+
import org.springframework.http.HttpRequest;
3737
import org.springframework.util.Assert;
3838
import org.springframework.util.LinkedMultiValueMap;
3939
import org.springframework.util.MultiValueMap;
@@ -742,9 +742,9 @@ public static String extractFullFilenameFromUrlPath(String urlPath) {
742742
* like this {@code "q1=a;q1=b;q2=a,b,c"}. The resulting map would contain
743743
* keys {@code "q1"} and {@code "q2"} with values {@code ["a","b"]} and
744744
* {@code ["a","b","c"]} respectively.
745-
*
746745
* @param matrixVariables the unparsed matrix variables string
747746
* @return a map with matrix variable names and values, never {@code null}
747+
* @since 3.2
748748
*/
749749
public static MultiValueMap<String, String> parseMatrixVariables(String matrixVariables) {
750750
MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>();
@@ -773,12 +773,11 @@ public static MultiValueMap<String, String> parseMatrixVariables(String matrixVa
773773
* Check the given request origin against a list of allowed origins.
774774
* A list containing "*" means that all origins are allowed.
775775
* An empty list means only same origin is allowed.
776-
*
777776
* @return true if the request origin is valid, false otherwise
778777
* @since 4.1.5
779778
* @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454: The Web Origin Concept</a>
780779
*/
781-
public static boolean isValidOrigin(ServerHttpRequest request, List<String> allowedOrigins) {
780+
public static boolean isValidOrigin(HttpRequest request, Collection<String> allowedOrigins) {
782781
Assert.notNull(request, "Request must not be null");
783782
Assert.notNull(allowedOrigins, "Allowed origins must not be null");
784783

@@ -791,7 +790,7 @@ else if (allowedOrigins.isEmpty()) {
791790
UriComponents requestComponents = UriComponentsBuilder.fromHttpRequest(request).build();
792791
int originPort = getPort(originComponents);
793792
int requestPort = getPort(requestComponents);
794-
return originComponents.getHost().equals(requestComponents.getHost()) && (originPort == requestPort);
793+
return (originComponents.getHost().equals(requestComponents.getHost()) && originPort == requestPort);
795794
}
796795
else {
797796
return allowedOrigins.contains(origin);

0 commit comments

Comments
 (0)