Polishing
This commit is contained in:
parent
86b7118da8
commit
d75f128752
|
@ -204,7 +204,7 @@ public class GsonHttpMessageConverter extends AbstractHttpMessageConverter<Objec
|
|||
this.gson.toJson(o, writer);
|
||||
writer.close();
|
||||
}
|
||||
catch(JsonIOException ex) {
|
||||
catch (JsonIOException ex) {
|
||||
throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
|
@ -16,11 +16,8 @@
|
|||
|
||||
package org.springframework.web.bind.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.Part;
|
||||
|
||||
|
@ -73,7 +70,6 @@ import org.springframework.web.multipart.MultipartRequest;
|
|||
*/
|
||||
public class WebRequestDataBinder extends WebDataBinder {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new WebRequestDataBinder instance, with default object name.
|
||||
* @param target the target object to bind onto (or {@code null}
|
||||
|
@ -115,8 +111,7 @@ public class WebRequestDataBinder extends WebDataBinder {
|
|||
*/
|
||||
public void bind(WebRequest request) {
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap());
|
||||
|
||||
if (isMultipartRequest(request) && (request instanceof NativeWebRequest)) {
|
||||
if (isMultipartRequest(request) && request instanceof NativeWebRequest) {
|
||||
MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class);
|
||||
if (multipartRequest != null) {
|
||||
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
|
||||
|
@ -129,6 +124,15 @@ public class WebRequestDataBinder extends WebDataBinder {
|
|||
doBind(mpvs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the request is a multipart request (by checking its Content-Type header).
|
||||
* @param request request with parameters to bind
|
||||
*/
|
||||
private boolean isMultipartRequest(WebRequest request) {
|
||||
String contentType = request.getHeader("Content-Type");
|
||||
return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Treats errors as fatal.
|
||||
* <p>Use this method only if it's an error if the input isn't valid.
|
||||
|
@ -141,16 +145,6 @@ public class WebRequestDataBinder extends WebDataBinder {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the request is a multipart request (by checking its Content-Type header).
|
||||
*
|
||||
* @param request request with parameters to bind
|
||||
*/
|
||||
private boolean isMultipartRequest(WebRequest request) {
|
||||
String contentType = request.getHeader("Content-Type");
|
||||
return ((contentType != null) && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encapsulate Part binding code for Servlet 3.0+ only containers.
|
||||
|
@ -160,12 +154,10 @@ public class WebRequestDataBinder extends WebDataBinder {
|
|||
|
||||
private final boolean bindEmptyMultipartFiles;
|
||||
|
||||
|
||||
public Servlet3MultipartHelper(boolean bindEmptyMultipartFiles) {
|
||||
this.bindEmptyMultipartFiles = bindEmptyMultipartFiles;
|
||||
}
|
||||
|
||||
|
||||
public void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) {
|
||||
try {
|
||||
MultiValueMap<String, Part> map = new LinkedMultiValueMap<String, Part>();
|
||||
|
@ -184,14 +176,10 @@ public class WebRequestDataBinder extends WebDataBinder {
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new MultipartException("Failed to get request parts", ex);
|
||||
}
|
||||
catch(ServletException ex) {
|
||||
catch (Exception ex) {
|
||||
throw new MultipartException("Failed to get request parts", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
|
|||
handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef).add("urlPathHelper", pathHelperRef);
|
||||
|
||||
String order = element.getAttribute("order");
|
||||
// use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
|
||||
// Use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
|
||||
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1);
|
||||
|
||||
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
|
||||
|
@ -278,7 +278,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
|
|||
Element childElement = DomUtils.getChildElementsByTagName(beanElement, "bean", "ref").get(0);
|
||||
strategy = parserContext.getDelegate().parsePropertySubElement(childElement, null);
|
||||
}
|
||||
for(String pattern : patterns) {
|
||||
for (String pattern : patterns) {
|
||||
strategyMap.put(pattern, strategy);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,12 @@
|
|||
*/
|
||||
package org.springframework.web.servlet.resource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
@ -56,12 +60,9 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
|||
|
||||
|
||||
/**
|
||||
* Set a Map with URL paths as keys and {@code VersionStrategy}
|
||||
* as values.
|
||||
*
|
||||
* Set a Map with URL paths as keys and {@code VersionStrategy} as values.
|
||||
* <p>Supports direct URL matches and Ant-style pattern matches. For syntax
|
||||
* details, see the {@link org.springframework.util.AntPathMatcher} javadoc.
|
||||
*
|
||||
* @param map map with URLs as keys and version strategies as values
|
||||
*/
|
||||
public void setStrategyMap(Map<String, VersionStrategy> map) {
|
||||
|
@ -118,7 +119,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
|||
* @see VersionStrategy
|
||||
*/
|
||||
public VersionResourceResolver addVersionStrategy(VersionStrategy strategy, String... pathPatterns) {
|
||||
for(String pattern : pathPatterns) {
|
||||
for (String pattern : pathPatterns) {
|
||||
getStrategyMap().put(pattern, strategy);
|
||||
}
|
||||
return this;
|
||||
|
@ -148,7 +149,6 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
|||
}
|
||||
|
||||
String simplePath = versionStrategy.removeVersion(requestPath, candidateVersion);
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Extracted version from path, re-resolving without version, path=\"" + simplePath + "\"");
|
||||
}
|
||||
|
@ -166,8 +166,10 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
|||
return baseResource;
|
||||
}
|
||||
else {
|
||||
logger.trace("Potential resource found for [" + requestPath + "], but version ["
|
||||
+ candidateVersion + "] doesn't match.");
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Potential resource found for [" + requestPath + "], but version [" +
|
||||
candidateVersion + "] doesn't match.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +196,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
|||
}
|
||||
|
||||
/**
|
||||
* Finds a {@code VersionStrategy} for the request path of the requested resource.
|
||||
* Find a {@code VersionStrategy} for the request path of the requested resource.
|
||||
* @return an instance of a {@code VersionStrategy} or null if none matches that request path
|
||||
*/
|
||||
protected VersionStrategy getStrategyForPath(String requestPath) {
|
||||
|
@ -210,7 +212,6 @@ public class VersionResourceResolver extends AbstractResourceResolver {
|
|||
Collections.sort(matchingPatterns, comparator);
|
||||
return this.versionStrategyMap.get(matchingPatterns.get(0));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue