Java 类org.springframework.web.bind.support.WebArgumentResolver 实例源码

项目:lams    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * Actually resolve the value and check the resolved value is not
 * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
 */
@Override
public boolean supportsParameter(MethodParameter parameter) {
    try {
        NativeWebRequest webRequest = getWebRequest();
        Object result = this.adaptee.resolveArgument(parameter, webRequest);
        if (result == WebArgumentResolver.UNRESOLVED) {
            return false;
        }
        else {
            return ClassUtils.isAssignableValue(parameter.getParameterType(), result);
        }
    }
    catch (Exception ex) {
        // ignore (see class-level doc)
        logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage());
        return false;
    }
}
项目:lams    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * 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 {

    Class<?> paramType = parameter.getParameterType();
    Object result = this.adaptee.resolveArgument(parameter, webRequest);
    if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
        throw new IllegalStateException(
                "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
                "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
                "]. Consider declaring the argument type in a less specific fashion.");
    }
    return result;
}
项目:spring4-understanding    文件:AnnotationMethodHandlerExceptionResolver.java   
/**
 * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}.
 */
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
        NativeWebRequest webRequest, Exception thrownException) throws Exception {

    Class<?>[] paramTypes = handlerMethod.getParameterTypes();
    Object[] args = new Object[paramTypes.length];
    Class<?> handlerType = handler.getClass();
    for (int i = 0; i < args.length; i++) {
        MethodParameter methodParam = new SynthesizingMethodParameter(handlerMethod, i);
        GenericTypeResolver.resolveParameterType(methodParam, handlerType);
        Class<?> paramType = methodParam.getParameterType();
        Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException);
        if (argValue != WebArgumentResolver.UNRESOLVED) {
            args[i] = argValue;
        }
        else {
            throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
                    "] for @ExceptionHandler method: " + handlerMethod);
        }
    }
    return args;
}
项目:spring4-understanding    文件:AnnotationMethodHandlerExceptionResolver.java   
/**
 * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}.
 */
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
        NativeWebRequest webRequest, Exception thrownException) throws Exception {

    Class<?>[] paramTypes = handlerMethod.getParameterTypes();
    Object[] args = new Object[paramTypes.length];
    Class<?> handlerType = handler.getClass();
    for (int i = 0; i < args.length; i++) {
        MethodParameter methodParam = new SynthesizingMethodParameter(handlerMethod, i);
        GenericTypeResolver.resolveParameterType(methodParam, handlerType);
        Class<?> paramType = methodParam.getParameterType();
        Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException);
        if (argValue != WebArgumentResolver.UNRESOLVED) {
            args[i] = argValue;
        }
        else {
            throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
                    "] for @ExceptionHandler method: " + handlerMethod);
        }
    }
    return args;
}
项目:spring4-understanding    文件:AnnotationDrivenBeanDefinitionParser.java   
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
    ManagedList<Object> result = new ManagedList<Object>();
    for (Object object : list) {
        if (object instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
            String className = beanDef.getBeanDefinition().getBeanClassName();
            Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
            if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
                RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
                adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
                result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
                continue;
            }
        }
        result.add(object);
    }
    return result;
}
项目:spring4-understanding    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * Actually resolve the value and check the resolved value is not
 * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
 */
@Override
public boolean supportsParameter(MethodParameter parameter) {
    try {
        NativeWebRequest webRequest = getWebRequest();
        Object result = this.adaptee.resolveArgument(parameter, webRequest);
        if (result == WebArgumentResolver.UNRESOLVED) {
            return false;
        }
        else {
            return ClassUtils.isAssignableValue(parameter.getParameterType(), result);
        }
    }
    catch (Exception ex) {
        // ignore (see class-level doc)
        logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage());
        return false;
    }
}
项目:class-guard    文件:AnnotationMethodHandlerExceptionResolver.java   
/**
 * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}.
 */
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
        NativeWebRequest webRequest, Exception thrownException) throws Exception {

    Class<?>[] paramTypes = handlerMethod.getParameterTypes();
    Object[] args = new Object[paramTypes.length];
    Class<?> handlerType = handler.getClass();
    for (int i = 0; i < args.length; i++) {
        MethodParameter methodParam = new MethodParameter(handlerMethod, i);
        GenericTypeResolver.resolveParameterType(methodParam, handlerType);
        Class<?> paramType = methodParam.getParameterType();
        Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException);
        if (argValue != WebArgumentResolver.UNRESOLVED) {
            args[i] = argValue;
        }
        else {
            throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
                    "] for @ExceptionHandler method: " + handlerMethod);
        }
    }
    return args;
}
项目:class-guard    文件:AnnotationMethodHandlerExceptionResolver.java   
/**
 * Resolves the arguments for the given method. Delegates to {@link #resolveCommonArgument}.
 */
private Object[] resolveHandlerArguments(Method handlerMethod, Object handler,
        NativeWebRequest webRequest, Exception thrownException) throws Exception {

    Class<?>[] paramTypes = handlerMethod.getParameterTypes();
    Object[] args = new Object[paramTypes.length];
    Class<?> handlerType = handler.getClass();
    for (int i = 0; i < args.length; i++) {
        MethodParameter methodParam = new MethodParameter(handlerMethod, i);
        GenericTypeResolver.resolveParameterType(methodParam, handlerType);
        Class<?> paramType = methodParam.getParameterType();
        Object argValue = resolveCommonArgument(methodParam, webRequest, thrownException);
        if (argValue != WebArgumentResolver.UNRESOLVED) {
            args[i] = argValue;
        }
        else {
            throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
                    "] for @ExceptionHandler method: " + handlerMethod);
        }
    }
    return args;
}
项目:class-guard    文件:AnnotationDrivenBeanDefinitionParser.java   
private ManagedList<BeanDefinitionHolder> wrapWebArgumentResolverBeanDefs(
        List<BeanDefinitionHolder> beanDefs, ParserContext parserContext) {

    ManagedList<BeanDefinitionHolder> result = new ManagedList<BeanDefinitionHolder>();
    for (BeanDefinitionHolder beanDef : beanDefs) {
        String className = beanDef.getBeanDefinition().getBeanClassName();
        Class<?> clazz = ClassUtils.resolveClassName(className, parserContext.getReaderContext().getBeanClassLoader());
        if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
            RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
            adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
            result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
        }
        else {
            result.add(beanDef);
        }
    }
    return result;
}
项目:class-guard    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * Actually resolve the value and check the resolved value is not
 * {@link WebArgumentResolver#UNRESOLVED} absorbing _any_ exceptions.
 */
public boolean supportsParameter(MethodParameter parameter) {
    try {
        NativeWebRequest webRequest = getWebRequest();
        Object result = this.adaptee.resolveArgument(parameter, webRequest);
        if (result == WebArgumentResolver.UNRESOLVED) {
            return false;
        }
        else {
            return ClassUtils.isAssignableValue(parameter.getParameterType(), result);
        }
    }
    catch (Exception ex) {
        // ignore (see class-level doc)
        logger.debug("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage());
        return false;
    }
}
项目:class-guard    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * Delegate to the {@link WebArgumentResolver} instance.
 * @exception IllegalStateException if the resolved value is not assignable
 * to the method parameter.
 */
public Object resolveArgument(
        MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
        throws Exception {

    Class<?> paramType = parameter.getParameterType();
    Object result = this.adaptee.resolveArgument(parameter, webRequest);
    if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
        throw new IllegalStateException(
                "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
                "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
                "]. Consider declaring the argument type in a less specific fashion.");
    }
    return result;
}
项目:spring-boot-security-saml-sample    文件:CurrentUserHandlerMethodArgumentResolverTest.java   
@Test
public void testResolveArgument() throws Exception {
    // given
    ModelAndViewContainer mavContainer = mock(ModelAndViewContainer.class);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    NativeWebRequest webRequest = mock(NativeWebRequest.class);
    User stubUser = new User(USER_NAME, "", Collections.emptyList());
    Principal stubPrincipal = new UsernamePasswordAuthenticationToken(stubUser, null);
    when(webRequest.getUserPrincipal()).thenReturn(stubPrincipal);

    // when/then
    assertEquals(stubUser,
            resolver.resolveArgument(validParam, mavContainer, webRequest,binderFactory));
    assertEquals(WebArgumentResolver.UNRESOLVED,
            resolver.resolveArgument(notAnnotatedParam, mavContainer, webRequest,binderFactory));
    assertEquals(WebArgumentResolver.UNRESOLVED,
            resolver.resolveArgument(wrongTypeParam, mavContainer, webRequest,binderFactory));
}
项目:lams    文件:HandlerMethodInvoker.java   
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
        SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
        WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter<?>[] messageConverters) {

    this.methodResolver = methodResolver;
    this.bindingInitializer = bindingInitializer;
    this.sessionAttributeStore = sessionAttributeStore;
    this.parameterNameDiscoverer = parameterNameDiscoverer;
    this.customArgumentResolvers = customArgumentResolvers;
    this.messageConverters = messageConverters;
}
项目:spring4-understanding    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * 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 {

    Class<?> paramType = parameter.getParameterType();
    Object result = this.adaptee.resolveArgument(parameter, webRequest);
    if (result == WebArgumentResolver.UNRESOLVED || !ClassUtils.isAssignableValue(paramType, result)) {
        throw new IllegalStateException(
                "Standard argument type [" + paramType.getName() + "] in method " + parameter.getMethod() +
                "resolved to incompatible value of type [" + (result != null ? result.getClass() : null) +
                "]. Consider declaring the argument type in a less specific fashion.");
    }
    return result;
}
项目:spring4-understanding    文件:HandlerMethodInvoker.java   
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
        SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
        WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter<?>[] messageConverters) {

    this.methodResolver = methodResolver;
    this.bindingInitializer = bindingInitializer;
    this.sessionAttributeStore = sessionAttributeStore;
    this.parameterNameDiscoverer = parameterNameDiscoverer;
    this.customArgumentResolvers = customArgumentResolvers;
    this.messageConverters = messageConverters;
}
项目:spring4-understanding    文件:WebArgumentResolverAdapterTests.java   
@Before
public void setUp() throws Exception {
    adaptee = mock(WebArgumentResolver.class);
    adapter = new TestWebArgumentResolverAdapter(adaptee);
    parameter = new MethodParameter(getClass().getMethod("handle", Integer.TYPE), 0);
    webRequest = new ServletWebRequest(new MockHttpServletRequest());

    // Expose request to the current thread (for SpEL expressions)
    RequestContextHolder.setRequestAttributes(webRequest);
}
项目:spring4-understanding    文件:WebArgumentResolverAdapterTests.java   
@Test
public void supportsParameterUnresolved() throws Exception {
    given(adaptee.resolveArgument(parameter, webRequest)).willReturn(WebArgumentResolver.UNRESOLVED);

    assertFalse("Parameter supported", adapter.supportsParameter(parameter));

    verify(adaptee).resolveArgument(parameter, webRequest);
}
项目:slackspace-angular-spring-keycloak    文件:UserDetailsArgumentResolver.java   
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    if (supportsParameter(methodParameter)) {
        return createUserDetails(webRequest);
    }
    else {
        return WebArgumentResolver.UNRESOLVED;
    }
}
项目:spring-tsers-auth    文件:CurrentUserHandlerMethodArgumentResolver.java   
public Object resolveArgument(MethodParameter methodParameter,
                              ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
                              WebDataBinderFactory binderFactory) throws Exception {
    if (this.supportsParameter(methodParameter)) {
        return securityUtils.getCurrentUser();
    } else {
        return WebArgumentResolver.UNRESOLVED;
    }
}
项目:nbone    文件:JsonRequestParamMethodArgumentResolver.java   
/**
* spring 3.1之前
*/
  @Override
  public Object resolveArgument(MethodParameter parameter, NativeWebRequest request) throws Exception {
      if(!supportsParameter(parameter)) {
          return WebArgumentResolver.UNRESOLVED;
      }
      return resolveArgument(parameter, null, request, null);
  }
项目:nbone    文件:RequestJsonParamMethodArgumentResolver.java   
/**
* spring 3.1之前
*/
  @Override
  public Object resolveArgument(MethodParameter parameter, NativeWebRequest request) throws Exception {
      if(!supportsParameter(parameter)) {
          return WebArgumentResolver.UNRESOLVED;
      }
      return resolveArgument(parameter, null, request, null);
  }
项目:web-harvester    文件:CurrentUserResolver.java   
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavc,
        NativeWebRequest webRequest, WebDataBinderFactory wdbf) throws Exception {
    if (this.supportsParameter(methodParameter)) {
        Principal principal = webRequest.getUserPrincipal();
        return (User) ((Authentication) principal).getPrincipal();
    } else {
        return WebArgumentResolver.UNRESOLVED;
    }
}
项目:websec-saml2sp    文件:CurrentUserHandlerMethodArgumentResolver.java   
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
                              NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    if (this.supportsParameter(methodParameter)) {
        return getCurrentUser();
    }
    else {
        return WebArgumentResolver.UNRESOLVED;
    }
}
项目:class-guard    文件:HandlerMethodInvoker.java   
public HandlerMethodInvoker(HandlerMethodResolver methodResolver, WebBindingInitializer bindingInitializer,
        SessionAttributeStore sessionAttributeStore, ParameterNameDiscoverer parameterNameDiscoverer,
        WebArgumentResolver[] customArgumentResolvers, HttpMessageConverter[] messageConverters) {

    this.methodResolver = methodResolver;
    this.bindingInitializer = bindingInitializer;
    this.sessionAttributeStore = sessionAttributeStore;
    this.parameterNameDiscoverer = parameterNameDiscoverer;
    this.customArgumentResolvers = customArgumentResolvers;
    this.messageConverters = messageConverters;
}
项目:class-guard    文件:WebArgumentResolverAdapterTests.java   
@Before
public void setUp() throws Exception {
    adaptee = mock(WebArgumentResolver.class);
    adapter = new TestWebArgumentResolverAdapter(adaptee);
    parameter = new MethodParameter(getClass().getMethod("handle", Integer.TYPE), 0);
    webRequest = new ServletWebRequest(new MockHttpServletRequest());

    // Expose request to the current thread (for SpEL expressions)
    RequestContextHolder.setRequestAttributes(webRequest);
}
项目:class-guard    文件:WebArgumentResolverAdapterTests.java   
@Test
public void supportsParameterUnresolved() throws Exception {
    given(adaptee.resolveArgument(parameter, webRequest)).willReturn(WebArgumentResolver.UNRESOLVED);

    assertFalse("Parameter supported", adapter.supportsParameter(parameter));

    verify(adaptee).resolveArgument(parameter, webRequest);
}
项目:spring-boot-security-saml-sample    文件:CurrentUserHandlerMethodArgumentResolver.java   
public Object resolveArgument(MethodParameter methodParameter,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
        WebDataBinderFactory binderFactory) throws Exception {
    if (this.supportsParameter(methodParameter)) {
        Principal principal = (Principal) webRequest.getUserPrincipal();
        return (User) ((Authentication) principal).getPrincipal();
    } else {
        return WebArgumentResolver.UNRESOLVED;
    }
}
项目:springmvc-uadetector    文件:ReadableUserAgentResolverTest.java   
@Test
public void it_should_not_resolved_arguments_with_unknown_class() throws Exception {
    Class klass = Integer.class;
    when(methodParameter.getParameterType()).thenReturn(klass);

    Object argument = readableUserAgentResolver.resolveArgument(methodParameter, nativeWebRequest);

    assertThat(argument)
            .isNotNull()
            .isSameAs(WebArgumentResolver.UNRESOLVED);

    verify(methodParameter).getParameterType();
    verifyZeroInteractions(nativeWebRequest);
}
项目:springmvc-uadetector    文件:BrowserResolverTest.java   
@Test
public void it_should_not_resolved_arguments_with_unknown_class() throws Exception {
    Class klass = Integer.class;
    when(methodParameter.getParameterType()).thenReturn(klass);

    Object argument = browserResolver.resolveArgument(methodParameter, nativeWebRequest);

    assertThat(argument)
            .isNotNull()
            .isSameAs(WebArgumentResolver.UNRESOLVED);

    verify(methodParameter).getParameterType();
    verifyZeroInteractions(nativeWebRequest);
}
项目:dandelion-datatables    文件:DatatablesCriteriasResolver.java   
public Object resolveArgument(MethodParameter methodParam, NativeWebRequest nativeWebRequest) throws Exception {
   DatatablesParams parameterAnnotation = methodParam.getParameterAnnotation(DatatablesParams.class);

   if (parameterAnnotation != null) {
      HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest();
      return DatatablesCriterias.getFromRequest(request);
   }

   return WebArgumentResolver.UNRESOLVED;
}
项目:lams    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * Create a new instance.
 */
public AbstractWebArgumentResolverAdapter(WebArgumentResolver adaptee) {
    Assert.notNull(adaptee, "'adaptee' must not be null");
    this.adaptee = adaptee;
}
项目:lams    文件:HandlerMethodInvoker.java   
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod,
        WebDataBinder binder, NativeWebRequest webRequest) throws Exception {

    Class<?>[] initBinderParams = initBinderMethod.getParameterTypes();
    Object[] initBinderArgs = new Object[initBinderParams.length];

    for (int i = 0; i < initBinderArgs.length; i++) {
        MethodParameter methodParam = new MethodParameter(initBinderMethod, i);
        methodParam.initParameterNameDiscovery(this.parameterNameDiscoverer);
        GenericTypeResolver.resolveParameterType(methodParam, handler.getClass());
        String paramName = null;
        boolean paramRequired = false;
        String paramDefaultValue = null;
        String pathVarName = null;
        Annotation[] paramAnns = methodParam.getParameterAnnotations();

        for (Annotation paramAnn : paramAnns) {
            if (RequestParam.class.isInstance(paramAnn)) {
                RequestParam requestParam = (RequestParam) paramAnn;
                paramName = requestParam.value();
                paramRequired = requestParam.required();
                paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
                break;
            }
            else if (ModelAttribute.class.isInstance(paramAnn)) {
                throw new IllegalStateException(
                        "@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
            }
            else if (PathVariable.class.isInstance(paramAnn)) {
                PathVariable pathVar = (PathVariable) paramAnn;
                pathVarName = pathVar.value();
            }
        }

        if (paramName == null && pathVarName == null) {
            Object argValue = resolveCommonArgument(methodParam, webRequest);
            if (argValue != WebArgumentResolver.UNRESOLVED) {
                initBinderArgs[i] = argValue;
            }
            else {
                Class<?> paramType = initBinderParams[i];
                if (paramType.isInstance(binder)) {
                    initBinderArgs[i] = binder;
                }
                else if (BeanUtils.isSimpleProperty(paramType)) {
                    paramName = "";
                }
                else {
                    throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
                            "] for @InitBinder method: " + initBinderMethod);
                }
            }
        }

        if (paramName != null) {
            initBinderArgs[i] =
                    resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
        }
        else if (pathVarName != null) {
            initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
        }
    }

    return initBinderArgs;
}
项目:lams    文件:HandlerMethodInvoker.java   
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception {
    if (WebRequest.class.isAssignableFrom(parameterType)) {
        return webRequest;
    }
    return WebArgumentResolver.UNRESOLVED;
}
项目:spring4-understanding    文件:AnnotationMethodHandlerExceptionResolver.java   
/**
 * Resolves standard method arguments. The default implementation handles {@link NativeWebRequest},
 * {@link ServletRequest}, {@link ServletResponse}, {@link HttpSession}, {@link Principal},
 * {@link Locale}, request {@link InputStream}, request {@link Reader}, response {@link OutputStream},
 * response {@link Writer}, and the given {@code thrownException}.
 * @param parameterType the method parameter type
 * @param webRequest the request
 * @param thrownException the exception thrown
 * @return the argument value, or {@link WebArgumentResolver#UNRESOLVED}
 */
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest,
        Exception thrownException) throws Exception {

    if (parameterType.isInstance(thrownException)) {
        return thrownException;
    }
    else if (WebRequest.class.isAssignableFrom(parameterType)) {
        return webRequest;
    }

    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);

    if (ServletRequest.class.isAssignableFrom(parameterType)) {
        return request;
    }
    else if (ServletResponse.class.isAssignableFrom(parameterType)) {
        return response;
    }
    else if (HttpSession.class.isAssignableFrom(parameterType)) {
        return request.getSession();
    }
    else if (Principal.class.isAssignableFrom(parameterType)) {
        return request.getUserPrincipal();
    }
    else if (Locale.class == parameterType) {
        return RequestContextUtils.getLocale(request);
    }
    else if (InputStream.class.isAssignableFrom(parameterType)) {
        return request.getInputStream();
    }
    else if (Reader.class.isAssignableFrom(parameterType)) {
        return request.getReader();
    }
    else if (OutputStream.class.isAssignableFrom(parameterType)) {
        return response.getOutputStream();
    }
    else if (Writer.class.isAssignableFrom(parameterType)) {
        return response.getWriter();
    }
    else {
        return WebArgumentResolver.UNRESOLVED;

    }
}
项目:spring4-understanding    文件:ServletWebArgumentResolverAdapter.java   
public ServletWebArgumentResolverAdapter(WebArgumentResolver adaptee) {
    super(adaptee);
}
项目:spring4-understanding    文件:AbstractWebArgumentResolverAdapter.java   
/**
 * Create a new instance.
 */
public AbstractWebArgumentResolverAdapter(WebArgumentResolver adaptee) {
    Assert.notNull(adaptee, "'adaptee' must not be null");
    this.adaptee = adaptee;
}
项目:spring4-understanding    文件:HandlerMethodInvoker.java   
private Object[] resolveInitBinderArguments(Object handler, Method initBinderMethod,
        WebDataBinder binder, NativeWebRequest webRequest) throws Exception {

    Class<?>[] initBinderParams = initBinderMethod.getParameterTypes();
    Object[] initBinderArgs = new Object[initBinderParams.length];

    for (int i = 0; i < initBinderArgs.length; i++) {
        MethodParameter methodParam = new SynthesizingMethodParameter(initBinderMethod, i);
        methodParam.initParameterNameDiscovery(this.parameterNameDiscoverer);
        GenericTypeResolver.resolveParameterType(methodParam, handler.getClass());
        String paramName = null;
        boolean paramRequired = false;
        String paramDefaultValue = null;
        String pathVarName = null;
        Annotation[] paramAnns = methodParam.getParameterAnnotations();

        for (Annotation paramAnn : paramAnns) {
            if (RequestParam.class.isInstance(paramAnn)) {
                RequestParam requestParam = (RequestParam) paramAnn;
                paramName = requestParam.name();
                paramRequired = requestParam.required();
                paramDefaultValue = parseDefaultValueAttribute(requestParam.defaultValue());
                break;
            }
            else if (ModelAttribute.class.isInstance(paramAnn)) {
                throw new IllegalStateException(
                        "@ModelAttribute is not supported on @InitBinder methods: " + initBinderMethod);
            }
            else if (PathVariable.class.isInstance(paramAnn)) {
                PathVariable pathVar = (PathVariable) paramAnn;
                pathVarName = pathVar.value();
            }
        }

        if (paramName == null && pathVarName == null) {
            Object argValue = resolveCommonArgument(methodParam, webRequest);
            if (argValue != WebArgumentResolver.UNRESOLVED) {
                initBinderArgs[i] = argValue;
            }
            else {
                Class<?> paramType = initBinderParams[i];
                if (paramType.isInstance(binder)) {
                    initBinderArgs[i] = binder;
                }
                else if (BeanUtils.isSimpleProperty(paramType)) {
                    paramName = "";
                }
                else {
                    throw new IllegalStateException("Unsupported argument [" + paramType.getName() +
                            "] for @InitBinder method: " + initBinderMethod);
                }
            }
        }

        if (paramName != null) {
            initBinderArgs[i] =
                    resolveRequestParam(paramName, paramRequired, paramDefaultValue, methodParam, webRequest, null);
        }
        else if (pathVarName != null) {
            initBinderArgs[i] = resolvePathVariable(pathVarName, methodParam, webRequest, null);
        }
    }

    return initBinderArgs;
}
项目:spring4-understanding    文件:HandlerMethodInvoker.java   
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception {
    if (WebRequest.class.isAssignableFrom(parameterType)) {
        return webRequest;
    }
    return WebArgumentResolver.UNRESOLVED;
}
项目:spring4-understanding    文件:WebArgumentResolverAdapterTests.java   
@Test(expected = IllegalStateException.class)
public void resolveArgumentUnresolved() throws Exception {
    given(adaptee.resolveArgument(parameter, webRequest)).willReturn(WebArgumentResolver.UNRESOLVED);

    adapter.resolveArgument(parameter, null, webRequest, null);
}
项目:spring4-understanding    文件:WebArgumentResolverAdapterTests.java   
public TestWebArgumentResolverAdapter(WebArgumentResolver adaptee) {
    super(adaptee);
}