Skip to content

Commit d75f128

Browse files
committed
Polishing
1 parent 86b7118 commit d75f128

File tree

4 files changed

+28
-39
lines changed

4 files changed

+28
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected void writeInternal(Object o, HttpOutputMessage outputMessage)
204204
this.gson.toJson(o, writer);
205205
writer.close();
206206
}
207-
catch(JsonIOException ex) {
207+
catch (JsonIOException ex) {
208208
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
209209
}
210210
}

spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -16,11 +16,8 @@
1616

1717
package org.springframework.web.bind.support;
1818

19-
import java.io.IOException;
2019
import java.util.List;
2120
import java.util.Map;
22-
23-
import javax.servlet.ServletException;
2421
import javax.servlet.http.HttpServletRequest;
2522
import javax.servlet.http.Part;
2623

@@ -73,7 +70,6 @@
7370
*/
7471
public class WebRequestDataBinder extends WebDataBinder {
7572

76-
7773
/**
7874
* Create a new WebRequestDataBinder instance, with default object name.
7975
* @param target the target object to bind onto (or {@code null}
@@ -115,8 +111,7 @@ public WebRequestDataBinder(Object target, String objectName) {
115111
*/
116112
public void bind(WebRequest request) {
117113
MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap());
118-
119-
if (isMultipartRequest(request) && (request instanceof NativeWebRequest)) {
114+
if (isMultipartRequest(request) && request instanceof NativeWebRequest) {
120115
MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class);
121116
if (multipartRequest != null) {
122117
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
@@ -129,6 +124,15 @@ else if (ClassUtils.hasMethod(HttpServletRequest.class, "getParts")) {
129124
doBind(mpvs);
130125
}
131126

127+
/**
128+
* Check if the request is a multipart request (by checking its Content-Type header).
129+
* @param request request with parameters to bind
130+
*/
131+
private boolean isMultipartRequest(WebRequest request) {
132+
String contentType = request.getHeader("Content-Type");
133+
return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
134+
}
135+
132136
/**
133137
* Treats errors as fatal.
134138
* <p>Use this method only if it's an error if the input isn't valid.
@@ -141,16 +145,6 @@ public void closeNoCatch() throws BindException {
141145
}
142146
}
143147

144-
/**
145-
* Check if the request is a multipart request (by checking its Content-Type header).
146-
*
147-
* @param request request with parameters to bind
148-
*/
149-
private boolean isMultipartRequest(WebRequest request) {
150-
String contentType = request.getHeader("Content-Type");
151-
return ((contentType != null) && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
152-
}
153-
154148

155149
/**
156150
* Encapsulate Part binding code for Servlet 3.0+ only containers.
@@ -160,12 +154,10 @@ private static class Servlet3MultipartHelper {
160154

161155
private final boolean bindEmptyMultipartFiles;
162156

163-
164157
public Servlet3MultipartHelper(boolean bindEmptyMultipartFiles) {
165158
this.bindEmptyMultipartFiles = bindEmptyMultipartFiles;
166159
}
167160

168-
169161
public void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) {
170162
try {
171163
MultiValueMap<String, Part> map = new LinkedMultiValueMap<String, Part>();
@@ -184,14 +176,10 @@ public void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) {
184176
}
185177
}
186178
}
187-
catch (IOException ex) {
188-
throw new MultipartException("Failed to get request parts", ex);
189-
}
190-
catch(ServletException ex) {
179+
catch (Exception ex) {
191180
throw new MultipartException("Failed to get request parts", ex);
192181
}
193182
}
194-
195183
}
196184

197185
}

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
9999
handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef).add("urlPathHelper", pathHelperRef);
100100

101101
String order = element.getAttribute("order");
102-
// use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
102+
// Use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
103103
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1);
104104

105105
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
@@ -278,7 +278,7 @@ else if (VERSION_STRATEGY_ELEMENT.equals(beanElement.getLocalName())) {
278278
Element childElement = DomUtils.getChildElementsByTagName(beanElement, "bean", "ref").get(0);
279279
strategy = parserContext.getDelegate().parsePropertySubElement(childElement, null);
280280
}
281-
for(String pattern : patterns) {
281+
for (String pattern : patterns) {
282282
strategyMap.put(pattern, strategy);
283283
}
284284
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package org.springframework.web.servlet.resource;
1717

18-
import java.util.*;
19-
18+
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.Comparator;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import java.util.Map;
2024
import javax.servlet.http.HttpServletRequest;
2125

2226
import org.springframework.core.io.Resource;
@@ -56,12 +60,9 @@ public class VersionResourceResolver extends AbstractResourceResolver {
5660

5761

5862
/**
59-
* Set a Map with URL paths as keys and {@code VersionStrategy}
60-
* as values.
61-
*
63+
* Set a Map with URL paths as keys and {@code VersionStrategy} as values.
6264
* <p>Supports direct URL matches and Ant-style pattern matches. For syntax
6365
* details, see the {@link org.springframework.util.AntPathMatcher} javadoc.
64-
*
6566
* @param map map with URLs as keys and version strategies as values
6667
*/
6768
public void setStrategyMap(Map<String, VersionStrategy> map) {
@@ -118,7 +119,7 @@ public VersionResourceResolver addFixedVersionStrategy(String version, String...
118119
* @see VersionStrategy
119120
*/
120121
public VersionResourceResolver addVersionStrategy(VersionStrategy strategy, String... pathPatterns) {
121-
for(String pattern : pathPatterns) {
122+
for (String pattern : pathPatterns) {
122123
getStrategyMap().put(pattern, strategy);
123124
}
124125
return this;
@@ -148,7 +149,6 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
148149
}
149150

150151
String simplePath = versionStrategy.removeVersion(requestPath, candidateVersion);
151-
152152
if (logger.isTraceEnabled()) {
153153
logger.trace("Extracted version from path, re-resolving without version, path=\"" + simplePath + "\"");
154154
}
@@ -166,8 +166,10 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
166166
return baseResource;
167167
}
168168
else {
169-
logger.trace("Potential resource found for [" + requestPath + "], but version ["
170-
+ candidateVersion + "] doesn't match.");
169+
if (logger.isTraceEnabled()) {
170+
logger.trace("Potential resource found for [" + requestPath + "], but version [" +
171+
candidateVersion + "] doesn't match.");
172+
}
171173
return null;
172174
}
173175
}
@@ -194,7 +196,7 @@ protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends R
194196
}
195197

196198
/**
197-
* Finds a {@code VersionStrategy} for the request path of the requested resource.
199+
* Find a {@code VersionStrategy} for the request path of the requested resource.
198200
* @return an instance of a {@code VersionStrategy} or null if none matches that request path
199201
*/
200202
protected VersionStrategy getStrategyForPath(String requestPath) {
@@ -210,7 +212,6 @@ protected VersionStrategy getStrategyForPath(String requestPath) {
210212
Collections.sort(matchingPatterns, comparator);
211213
return this.versionStrategyMap.get(matchingPatterns.get(0));
212214
}
213-
214215
return null;
215216
}
216217

0 commit comments

Comments
 (0)