Polishing
This commit is contained in:
parent
cfc821d179
commit
1f3e195dac
|
@ -43,6 +43,7 @@ final class ObjectToOptionalConverter implements ConditionalGenericConverter {
|
|||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
return Collections.singleton(new ConvertiblePair(Object.class, Optional.class));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.web.method.annotation;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
@ -47,10 +48,11 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
|||
*/
|
||||
public abstract class AbstractWebArgumentResolverAdapter implements HandlerMethodArgumentResolver {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
private final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private final WebArgumentResolver adaptee;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
|
@ -59,6 +61,7 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
|
|||
this.adaptee = adaptee;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Actually resolve the value and check the resolved value is not
|
||||
* {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
|
||||
|
@ -82,21 +85,14 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Required for access to NativeWebRequest in {@link #supportsParameter}.
|
||||
*/
|
||||
protected abstract NativeWebRequest getWebRequest();
|
||||
|
||||
/**
|
||||
* Delegate to the {@link WebArgumentResolver} instance.
|
||||
* @exception IllegalStateException if the resolved value is not assignable
|
||||
* to the method parameter.
|
||||
*/
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
Object result = this.adaptee.resolveArgument(parameter, webRequest);
|
||||
|
@ -108,4 +104,11 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Required for access to NativeWebRequest in {@link #supportsParameter}.
|
||||
*/
|
||||
protected abstract NativeWebRequest getWebRequest();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -47,10 +47,8 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
ModelMap model = mavContainer.getModel();
|
||||
if (model.size() > 0) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -44,10 +44,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
return mavContainer.getModel();
|
||||
}
|
||||
|
@ -59,10 +57,8 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
|
|||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
|
@ -76,4 +72,5 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
|
|||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -43,10 +43,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
return mavContainer.getModel();
|
||||
}
|
||||
|
@ -57,10 +55,8 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
|
@ -74,4 +70,5 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
|||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,18 +47,15 @@ public class RequestHeaderMapMethodArgumentResolver implements HandlerMethodArgu
|
|||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.hasParameterAnnotation(RequestHeader.class) &&
|
||||
Map.class.isAssignableFrom(parameter.getParameterType());
|
||||
return (parameter.hasParameterAnnotation(RequestHeader.class) &&
|
||||
Map.class.isAssignableFrom(parameter.getParameterType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
|
||||
if (MultiValueMap.class.isAssignableFrom(paramType)) {
|
||||
MultiValueMap<String, String> result;
|
||||
if (HttpHeaders.class.isAssignableFrom(paramType)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -30,13 +30,15 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
|||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* Resolves {@link Map} method arguments annotated with an @{@link RequestParam} where the annotation does not
|
||||
* specify a request parameter name. See {@link RequestParamMethodArgumentResolver} for resolving {@link Map}
|
||||
* Resolves {@link Map} method arguments annotated with an @{@link RequestParam}
|
||||
* where the annotation does not specify a request parameter name.
|
||||
* See {@link RequestParamMethodArgumentResolver} for resolving {@link Map}
|
||||
* method arguments with a request parameter name.
|
||||
*
|
||||
* <p>The created {@link Map} contains all request parameter name/value pairs. If the method parameter type
|
||||
* is {@link MultiValueMap} instead, the created map contains all request parameters and all there values for
|
||||
* cases where request parameters have multiple values.
|
||||
* <p>The created {@link Map} contains all request parameter name/value pairs.
|
||||
* If the method parameter type is {@link MultiValueMap} instead, the created
|
||||
* map contains all request parameters and all there values for cases where
|
||||
* request parameters have multiple values.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
|
@ -47,20 +49,18 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
|
|||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
RequestParam requestParamAnnot = parameter.getParameterAnnotation(RequestParam.class);
|
||||
if (requestParamAnnot != null) {
|
||||
RequestParam ann = parameter.getParameterAnnotation(RequestParam.class);
|
||||
if (ann != null) {
|
||||
if (Map.class.isAssignableFrom(parameter.getParameterType())) {
|
||||
return !StringUtils.hasText(requestParamAnnot.value());
|
||||
return !StringUtils.hasText(ann.value());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -38,10 +38,8 @@ public class SessionStatusMethodArgumentResolver implements HandlerMethodArgumen
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
return mavContainer.getSessionStatus();
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -27,6 +27,7 @@ import org.springframework.web.context.request.NativeWebRequest;
|
|||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.1
|
||||
* @see HandlerMethodReturnValueHandler
|
||||
*/
|
||||
public interface HandlerMethodArgumentResolver {
|
||||
|
||||
|
@ -46,13 +47,12 @@ public interface HandlerMethodArgumentResolver {
|
|||
* a {@link WebDataBinder} instance when needed for data binding and
|
||||
* type conversion purposes.
|
||||
* @param parameter the method parameter to resolve. This parameter must
|
||||
* have previously been passed to
|
||||
* {@link #supportsParameter(org.springframework.core.MethodParameter)}
|
||||
* and it must have returned {@code true}
|
||||
* have previously been passed to {@link #supportsParameter} which must
|
||||
* have returned {@code true}.
|
||||
* @param mavContainer the ModelAndViewContainer for the current request
|
||||
* @param webRequest the current request
|
||||
* @param binderFactory a factory for creating {@link WebDataBinder} instances
|
||||
* @return the resolved argument value, or {@code null}.
|
||||
* @return the resolved argument value, or {@code null}
|
||||
* @throws Exception in case of errors with the preparation of argument values
|
||||
*/
|
||||
Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -66,13 +66,11 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
|||
|
||||
/**
|
||||
* Iterate over registered {@link HandlerMethodArgumentResolver}s and invoke the one that supports it.
|
||||
* @exception IllegalStateException if no suitable {@link HandlerMethodArgumentResolver} is found.
|
||||
* @throws IllegalStateException if no suitable {@link HandlerMethodArgumentResolver} is found.
|
||||
*/
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
|
||||
Assert.notNull(resolver, "Unknown parameter type [" + parameter.getParameterType().getName() + "]");
|
||||
|
@ -103,18 +101,17 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
|
|||
/**
|
||||
* Add the given {@link HandlerMethodArgumentResolver}.
|
||||
*/
|
||||
public HandlerMethodArgumentResolverComposite addResolver(HandlerMethodArgumentResolver argumentResolver) {
|
||||
this.argumentResolvers.add(argumentResolver);
|
||||
public HandlerMethodArgumentResolverComposite addResolver(HandlerMethodArgumentResolver resolver) {
|
||||
this.argumentResolvers.add(resolver);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given {@link HandlerMethodArgumentResolver}s.
|
||||
*/
|
||||
public HandlerMethodArgumentResolverComposite addResolvers(
|
||||
List<? extends HandlerMethodArgumentResolver> argumentResolvers) {
|
||||
if (argumentResolvers != null) {
|
||||
for (HandlerMethodArgumentResolver resolver : argumentResolvers) {
|
||||
public HandlerMethodArgumentResolverComposite addResolvers(List<? extends HandlerMethodArgumentResolver> resolvers) {
|
||||
if (resolvers != null) {
|
||||
for (HandlerMethodArgumentResolver resolver : resolvers) {
|
||||
this.argumentResolvers.add(resolver);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -25,6 +25,7 @@ import org.springframework.web.context.request.NativeWebRequest;
|
|||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.1
|
||||
* @see HandlerMethodArgumentResolver
|
||||
*/
|
||||
public interface HandlerMethodReturnValueHandler {
|
||||
|
||||
|
@ -44,9 +45,8 @@ public interface HandlerMethodReturnValueHandler {
|
|||
* to indicate the response has been handled directly.
|
||||
* @param returnValue the value returned from the handler method
|
||||
* @param returnType the type of the return value. This type must have
|
||||
* previously been passed to
|
||||
* {@link #supportsReturnType(org.springframework.core.MethodParameter)}
|
||||
* and it must have returned {@code true}
|
||||
* previously been passed to {@link #supportsReturnType} which must
|
||||
* have returned {@code true}.
|
||||
* @param mavContainer the ModelAndViewContainer for the current request
|
||||
* @param webRequest the current request
|
||||
* @throws Exception if the return value handling results in an error
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
|
@ -40,6 +41,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
|||
private final List<HandlerMethodReturnValueHandler> returnValueHandlers =
|
||||
new ArrayList<HandlerMethodReturnValueHandler>();
|
||||
|
||||
|
||||
/**
|
||||
* Return a read-only list with the registered handlers, or an empty list.
|
||||
*/
|
||||
|
@ -58,13 +60,11 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
|||
|
||||
/**
|
||||
* Iterate over registered {@link HandlerMethodReturnValueHandler}s and invoke the one that supports it.
|
||||
* @exception IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found.
|
||||
* @throws IllegalStateException if no suitable {@link HandlerMethodReturnValueHandler} is found.
|
||||
*/
|
||||
@Override
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType);
|
||||
Assert.notNull(handler, "Unknown return value type [" + returnType.getParameterType().getName() + "]");
|
||||
|
@ -90,18 +90,17 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe
|
|||
/**
|
||||
* Add the given {@link HandlerMethodReturnValueHandler}.
|
||||
*/
|
||||
public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler returnValuehandler) {
|
||||
returnValueHandlers.add(returnValuehandler);
|
||||
public HandlerMethodReturnValueHandlerComposite addHandler(HandlerMethodReturnValueHandler handler) {
|
||||
returnValueHandlers.add(handler);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given {@link HandlerMethodReturnValueHandler}s.
|
||||
*/
|
||||
public HandlerMethodReturnValueHandlerComposite addHandlers(
|
||||
List<? extends HandlerMethodReturnValueHandler> returnValueHandlers) {
|
||||
if (returnValueHandlers != null) {
|
||||
for (HandlerMethodReturnValueHandler handler : returnValueHandlers) {
|
||||
public HandlerMethodReturnValueHandlerComposite addHandlers(List<? extends HandlerMethodReturnValueHandler> handlers) {
|
||||
if (handlers != null) {
|
||||
for (HandlerMethodReturnValueHandler handler : handlers) {
|
||||
this.returnValueHandlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -58,11 +58,6 @@ public class ModelAndViewContainer {
|
|||
|
||||
private final SessionStatus sessionStatus = new SimpleSessionStatus();
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public ModelAndViewContainer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a view name to be resolved by the DispatcherServlet via a ViewResolver.
|
||||
|
@ -145,7 +140,7 @@ public class ModelAndViewContainer {
|
|||
* Whether to use the default model or the redirect model.
|
||||
*/
|
||||
private boolean useDefaultModel() {
|
||||
return !this.redirectModelScenario || ((this.redirectModel == null) && !this.ignoreDefaultModelOnRedirect);
|
||||
return (!this.redirectModelScenario || (this.redirectModel == null && !this.ignoreDefaultModelOnRedirect));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,7 +178,7 @@ public class ModelAndViewContainer {
|
|||
* signal that session processing is complete.
|
||||
*/
|
||||
public SessionStatus getSessionStatus() {
|
||||
return sessionStatus;
|
||||
return this.sessionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -243,6 +238,7 @@ public class ModelAndViewContainer {
|
|||
return getModel().containsAttribute(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return diagnostic information.
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -39,16 +39,15 @@ public class AsyncTaskMethodReturnValueHandler implements HandlerMethodReturnVal
|
|||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
Class<?> paramType = returnType.getParameterType();
|
||||
return WebAsyncTask.class.isAssignableFrom(paramType);
|
||||
return WebAsyncTask.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -34,14 +34,12 @@ public class CallableMethodReturnValueHandler implements HandlerMethodReturnValu
|
|||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
Class<?> paramType = returnType.getParameterType();
|
||||
return Callable.class.isAssignableFrom(paramType);
|
||||
return Callable.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -18,8 +18,8 @@ package org.springframework.web.servlet.mvc.method.annotation;
|
|||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
|
@ -33,14 +33,12 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu
|
|||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
Class<?> paramType = returnType.getParameterType();
|
||||
return DeferredResult.class.isAssignableFrom(paramType);
|
||||
return DeferredResult.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
|
|
@ -36,14 +36,12 @@ public class ListenableFutureReturnValueHandler implements HandlerMethodReturnVa
|
|||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
Class<?> paramType = returnType.getParameterType();
|
||||
return ListenableFuture.class.isAssignableFrom(paramType);
|
||||
return ListenableFuture.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
|
|
@ -50,11 +50,9 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
|
|||
* Configure one more simple patterns (as described in
|
||||
* {@link org.springframework.util.PatternMatchUtils#simpleMatch}) to use in order to recognize
|
||||
* custom redirect prefixes in addition to "redirect:".
|
||||
*
|
||||
* <p>Note that simply configuring this property will not make a custom
|
||||
* redirect prefix work. There must be a custom View that recognizes the
|
||||
* prefix as well.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public void setRedirectPatterns(String... redirectPatterns) {
|
||||
|
@ -75,10 +73,8 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
|
|
@ -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.
|
||||
|
@ -57,6 +57,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
|||
|
||||
private final ModelAttributeMethodProcessor modelAttributeProcessor = new ModelAttributeMethodProcessor(true);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
|
@ -64,6 +65,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
|||
this.mavResolvers = mavResolvers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Always returns {@code true}. See class-level note.
|
||||
*/
|
||||
|
@ -73,17 +75,15 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest request)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (this.mavResolvers != null) {
|
||||
for (ModelAndViewResolver mavResolver : this.mavResolvers) {
|
||||
Class<?> handlerType = returnType.getContainingClass();
|
||||
Method method = returnType.getMethod();
|
||||
ExtendedModelMap model = (ExtendedModelMap) mavContainer.getModel();
|
||||
ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, request);
|
||||
ModelAndView mav = mavResolver.resolveModelAndView(method, handlerType, returnValue, model, webRequest);
|
||||
if (mav != ModelAndViewResolver.UNRESOLVED) {
|
||||
mavContainer.addAllAttributes(mav.getModel());
|
||||
mavContainer.setViewName(mav.getViewName());
|
||||
|
@ -97,7 +97,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
|||
|
||||
// No suitable ModelAndViewResolver...
|
||||
if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
|
||||
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request);
|
||||
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, webRequest);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -44,9 +44,9 @@ public class PathVariableMapMethodArgumentResolver implements HandlerMethodArgum
|
|||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
PathVariable annot = parameter.getParameterAnnotation(PathVariable.class);
|
||||
return ((annot != null) && (Map.class.isAssignableFrom(parameter.getParameterType()))
|
||||
&& (!StringUtils.hasText(annot.value())));
|
||||
PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
|
||||
return (ann != null && (Map.class.isAssignableFrom(parameter.getParameterType()))
|
||||
&& !StringUtils.hasText(ann.value()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -32,10 +32,12 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
|
|||
/**
|
||||
* Resolves method arguments of type {@link RedirectAttributes}.
|
||||
*
|
||||
* <p>This resolver must be listed ahead of {@link org.springframework.web.method.annotation.ModelMethodProcessor} and
|
||||
* {@link org.springframework.web.method.annotation.MapMethodProcessor}, which support {@link Map} and {@link Model}
|
||||
* arguments both of which are "super" types of {@code RedirectAttributes}
|
||||
* and would also attempt to resolve a {@code RedirectAttributes} argument.
|
||||
* <p>This resolver must be listed ahead of
|
||||
* {@link org.springframework.web.method.annotation.ModelMethodProcessor} and
|
||||
* {@link org.springframework.web.method.annotation.MapMethodProcessor},
|
||||
* which support {@link Map} and {@link Model} arguments both of which are
|
||||
* "super" types of {@code RedirectAttributes} and would also attempt to
|
||||
* resolve a {@code RedirectAttributes} argument.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
|
@ -48,10 +50,8 @@ public class RedirectAttributesMethodArgumentResolver implements HandlerMethodAr
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
|
||||
ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder);
|
||||
|
|
|
@ -69,11 +69,13 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
|
|||
|
||||
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> messageConverters,
|
||||
ContentNegotiationManager contentNegotiationManager) {
|
||||
|
||||
super(messageConverters, contentNegotiationManager);
|
||||
}
|
||||
|
||||
public RequestResponseBodyMethodProcessor(List<HttpMessageConverter<?>> messageConverters,
|
||||
ContentNegotiationManager contentNegotiationManager, List<Object> responseBodyAdvice) {
|
||||
|
||||
super(messageConverters, contentNegotiationManager, responseBodyAdvice);
|
||||
}
|
||||
|
||||
|
@ -85,12 +87,11 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
|
|||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return ((AnnotationUtils.findAnnotation(returnType.getContainingClass(), ResponseBody.class) != null) ||
|
||||
(returnType.getMethodAnnotation(ResponseBody.class) != null));
|
||||
return (AnnotationUtils.findAnnotation(returnType.getContainingClass(), ResponseBody.class) != null ||
|
||||
returnType.getMethodAnnotation(ResponseBody.class) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @throws MethodArgumentNotValidException if validation fails
|
||||
* @throws HttpMessageNotReadableException if {@link RequestBody#required()}
|
||||
* is {@code true} and there is no body content or if there is no suitable
|
||||
|
@ -101,25 +102,20 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
|
|||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Object argument = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType());
|
||||
|
||||
String name = Conventions.getVariableNameForParameter(parameter);
|
||||
WebDataBinder binder = binderFactory.createBinder(webRequest, argument, name);
|
||||
|
||||
if (argument != null) {
|
||||
validate(binder, parameter);
|
||||
}
|
||||
|
||||
mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());
|
||||
|
||||
return argument;
|
||||
}
|
||||
|
||||
private void validate(WebDataBinder binder, MethodParameter parameter) throws Exception, MethodArgumentNotValidException {
|
||||
|
||||
private void validate(WebDataBinder binder, MethodParameter parameter) throws Exception {
|
||||
Annotation[] annotations = parameter.getParameterAnnotations();
|
||||
for (Annotation annot : annotations) {
|
||||
if (annot.annotationType().getSimpleName().startsWith("Valid")) {
|
||||
Object hints = AnnotationUtils.getValue(annot);
|
||||
for (Annotation ann : annotations) {
|
||||
if (ann.annotationType().getSimpleName().startsWith("Valid")) {
|
||||
Object hints = AnnotationUtils.getValue(ann);
|
||||
binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
|
||||
BindingResult bindingResult = binder.getBindingResult();
|
||||
if (bindingResult.hasErrors()) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -18,7 +18,6 @@ package org.springframework.web.servlet.mvc.method.annotation;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
|
@ -36,7 +35,7 @@ import org.springframework.web.method.annotation.ModelAttributeMethodProcessor;
|
|||
import org.springframework.web.servlet.HandlerMapping;
|
||||
|
||||
/**
|
||||
* A Servlet-specific {@link org.springframework.web.method.annotation.ModelAttributeMethodProcessor} that applies data
|
||||
* A Servlet-specific {@link ModelAttributeMethodProcessor} that applies data
|
||||
* binding through a WebDataBinder of type {@link ServletRequestDataBinder}.
|
||||
*
|
||||
* <p>Also adds a fall-back strategy to instantiate the model attribute from a
|
||||
|
@ -57,6 +56,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
|
|||
super(annotationNotRequired);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate the model attribute from a URI template variable or from a
|
||||
* request parameter if the name matches to the model attribute name and
|
||||
|
@ -65,10 +65,8 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
|
|||
* @see #createAttributeFromRequestValue(String, String, MethodParameter, WebDataBinderFactory, NativeWebRequest)
|
||||
*/
|
||||
@Override
|
||||
protected final Object createAttribute(String attributeName,
|
||||
MethodParameter parameter,
|
||||
WebDataBinderFactory binderFactory,
|
||||
NativeWebRequest request) throws Exception {
|
||||
protected final Object createAttribute(String attributeName, MethodParameter parameter,
|
||||
WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception {
|
||||
|
||||
String value = getRequestValueForAttribute(attributeName, request);
|
||||
if (value != null) {
|
||||
|
@ -106,9 +104,9 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
|
|||
@SuppressWarnings("unchecked")
|
||||
protected final Map<String, String> getUriTemplateVariables(NativeWebRequest request) {
|
||||
Map<String, String> variables =
|
||||
(Map<String, String>) request.getAttribute(
|
||||
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
return (variables != null) ? variables : Collections.<String, String>emptyMap();
|
||||
(Map<String, String>) request.getAttribute(
|
||||
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
|
||||
return (variables != null ? variables : Collections.<String, String>emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,11 +122,10 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
|
|||
* @return the created model attribute, or {@code null}
|
||||
* @throws Exception
|
||||
*/
|
||||
protected Object createAttributeFromRequestValue(String sourceValue,
|
||||
String attributeName,
|
||||
MethodParameter parameter,
|
||||
WebDataBinderFactory binderFactory,
|
||||
NativeWebRequest request) throws Exception {
|
||||
protected Object createAttributeFromRequestValue(String sourceValue, String attributeName,
|
||||
MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request)
|
||||
throws Exception {
|
||||
|
||||
DataBinder binder = binderFactory.createBinder(request, null, attributeName);
|
||||
ConversionService conversionService = binder.getConversionService();
|
||||
if (conversionService != null) {
|
||||
|
@ -142,8 +139,8 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Downcast {@link WebDataBinder} to {@link ServletRequestDataBinder} before binding.
|
||||
* This implementation downcasts {@link WebDataBinder} to
|
||||
* {@link ServletRequestDataBinder} before binding.
|
||||
* @see ServletRequestDataBinderFactory
|
||||
*/
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.security.Principal;
|
||||
|
@ -65,7 +64,7 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
|||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
return WebRequest.class.isAssignableFrom(paramType) ||
|
||||
return (WebRequest.class.isAssignableFrom(paramType) ||
|
||||
ServletRequest.class.isAssignableFrom(paramType) ||
|
||||
MultipartRequest.class.isAssignableFrom(paramType) ||
|
||||
HttpSession.class.isAssignableFrom(paramType) ||
|
||||
|
@ -75,14 +74,12 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
|||
"java.time.ZoneId".equals(paramType.getName()) ||
|
||||
InputStream.class.isAssignableFrom(paramType) ||
|
||||
Reader.class.isAssignableFrom(paramType) ||
|
||||
HttpMethod.class.equals(paramType);
|
||||
HttpMethod.class.equals(paramType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws IOException {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
if (WebRequest.class.isAssignableFrom(paramType)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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,9 @@
|
|||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -47,9 +45,9 @@ public class ServletResponseMethodArgumentResolver implements HandlerMethodArgum
|
|||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
return ServletResponse.class.isAssignableFrom(paramType)
|
||||
|| OutputStream.class.isAssignableFrom(paramType)
|
||||
|| Writer.class.isAssignableFrom(paramType);
|
||||
return (ServletResponse.class.isAssignableFrom(paramType) ||
|
||||
OutputStream.class.isAssignableFrom(paramType) ||
|
||||
Writer.class.isAssignableFrom(paramType));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,10 +57,8 @@ public class ServletResponseMethodArgumentResolver implements HandlerMethodArgum
|
|||
* {@code null}, the request is considered directly handled.
|
||||
*/
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws IOException {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
if (mavContainer != null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -43,10 +43,8 @@ public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethod
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
|
||||
return ServletUriComponentsBuilder.fromServletMapping(request);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
|
@ -46,10 +46,8 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
|
|
|
@ -48,11 +48,9 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
|||
* Configure one more simple patterns (as described in
|
||||
* {@link PatternMatchUtils#simpleMatch}) to use in order to recognize
|
||||
* custom redirect prefixes in addition to "redirect:".
|
||||
*
|
||||
* <p>Note that simply configuring this property will not make a custom
|
||||
* redirect prefix work. There must be a custom View that recognizes the
|
||||
* prefix as well.
|
||||
*
|
||||
* @since 4.1
|
||||
*/
|
||||
public void setRedirectPatterns(String... redirectPatterns) {
|
||||
|
@ -66,6 +64,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
|||
return this.redirectPatterns;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
Class<?> paramType = returnType.getParameterType();
|
||||
|
@ -73,10 +72,8 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
|||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
|
|
|
@ -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.
|
||||
|
@ -1568,7 +1568,6 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
|||
|
||||
@Test
|
||||
public void restController() throws Exception {
|
||||
|
||||
initServletWithControllers(ThisWillActuallyRun.class);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
|
@ -3039,7 +3038,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
|||
}
|
||||
|
||||
|
||||
// Test cases deleted from the original SevletAnnotationControllerTests:
|
||||
// Test cases deleted from the original ServletAnnotationControllerTests:
|
||||
|
||||
// @Ignore("Controller interface => no method-level @RequestMapping annotation")
|
||||
// public void standardHandleMethod() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue