From 99f72ce3dbb27028fcb9cf3aa9f559e0fbddaa3f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 9 Sep 2015 11:45:12 +0200 Subject: [PATCH] Polishing --- .../ServletInvocableHandlerMethod.java | 7 +++-- .../view/ContentNegotiatingViewResolver.java | 29 +++++++++---------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index 5928afd128..05cbba3c09 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -25,7 +25,6 @@ import java.util.concurrent.Callable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.http.HttpStatus; -import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.ResponseStatus; @@ -269,8 +268,10 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { StreamingResponseBody.class.isAssignableFrom(parameterType)) { return parameterType; } - Assert.isTrue(!ResolvableType.NONE.equals(this.returnType), "Expected one of" + - "Callable, DeferredResult, or ListenableFuture: " + super.getParameterType()); + if (ResolvableType.NONE.equals(this.returnType)) { + throw new IllegalArgumentException("Expected one of Callable, DeferredResult, or ListenableFuture: " + + super.getParameterType()); + } return this.returnType.getRawClass(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java index 3281a1c8c9..1d5a4f8d8c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java @@ -28,9 +28,6 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.Ordered; @@ -87,15 +84,14 @@ import org.springframework.web.servlet.ViewResolver; * @see InternalResourceViewResolver * @see BeanNameViewResolver */ -public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered, InitializingBean { - - private static final Log logger = LogFactory.getLog(ContentNegotiatingViewResolver.class); +public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport + implements ViewResolver, Ordered, InitializingBean { private int order = Ordered.HIGHEST_PRECEDENCE; private ContentNegotiationManager contentNegotiationManager; - private final ContentNegotiationManagerFactoryBean cnManagerFactoryBean = new ContentNegotiationManagerFactoryBean(); + private final ContentNegotiationManagerFactoryBean cnmFactoryBean = new ContentNegotiationManagerFactoryBean(); private boolean useNotAcceptableStatusCode = false; @@ -181,7 +177,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport } } else { - for (int i=0; i < viewResolvers.size(); i++) { + for (int i = 0; i < viewResolvers.size(); i++) { if (matchingBeans.contains(viewResolvers.get(i))) { continue; } @@ -195,17 +191,18 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport "'viewResolvers' property on the ContentNegotiatingViewResolver"); } AnnotationAwareOrderComparator.sort(this.viewResolvers); - this.cnManagerFactoryBean.setServletContext(servletContext); + this.cnmFactoryBean.setServletContext(servletContext); } @Override public void afterPropertiesSet() { if (this.contentNegotiationManager == null) { - this.cnManagerFactoryBean.afterPropertiesSet(); - this.contentNegotiationManager = this.cnManagerFactoryBean.getObject(); + this.cnmFactoryBean.afterPropertiesSet(); + this.contentNegotiationManager = this.cnmFactoryBean.getObject(); } } + @Override public View resolveViewName(String viewName, Locale locale) throws Exception { RequestAttributes attrs = RequestContextHolder.getRequestAttributes(); @@ -240,8 +237,8 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport ServletWebRequest webRequest = new ServletWebRequest(request); List acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest); - acceptableMediaTypes = acceptableMediaTypes.isEmpty() ? - Collections.singletonList(MediaType.ALL) : acceptableMediaTypes; + acceptableMediaTypes = (!acceptableMediaTypes.isEmpty() ? acceptableMediaTypes : + Collections.singletonList(MediaType.ALL)); List producibleMediaTypes = getProducibleMediaTypes(request); Set compatibleMediaTypes = new LinkedHashSet(); @@ -283,7 +280,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport */ private MediaType getMostSpecificMediaType(MediaType acceptType, MediaType produceType) { produceType = produceType.copyQualityValue(acceptType); - return MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceType) < 0 ? acceptType : produceType; + return (MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceType) < 0 ? acceptType : produceType); } private List getCandidateViews(String viewName, Locale locale, List requestedMediaTypes) @@ -330,8 +327,8 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport MediaType candidateContentType = MediaType.parseMediaType(candidateView.getContentType()); if (mediaType.isCompatibleWith(candidateContentType)) { if (logger.isDebugEnabled()) { - logger.debug("Returning [" + candidateView + "] based on requested media type '" - + mediaType + "'"); + logger.debug("Returning [" + candidateView + "] based on requested media type '" + + mediaType + "'"); } attrs.setAttribute(View.SELECTED_CONTENT_TYPE, mediaType, RequestAttributes.SCOPE_REQUEST); return candidateView;