master
Juergen Hoeller 9 years ago
parent 5f598586ea
commit 99f72ce3db
  1. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java
  2. 29
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.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();
}

@ -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<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest);
acceptableMediaTypes = acceptableMediaTypes.isEmpty() ?
Collections.singletonList(MediaType.ALL) : acceptableMediaTypes;
acceptableMediaTypes = (!acceptableMediaTypes.isEmpty() ? acceptableMediaTypes :
Collections.singletonList(MediaType.ALL));
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request);
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>();
@ -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<View> getCandidateViews(String viewName, Locale locale, List<MediaType> 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;

Loading…
Cancel
Save