org.springframework.web.bind.support.WebArgumentResolver Java Examples

The following examples show how to use org.springframework.web.bind.support.WebArgumentResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Assert.notNull(className, "No resolver class");
			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;
}
 
Example #2
Source File: CurrentUserHandlerMethodArgumentResolverTest.java    From spring-boot-security-saml-sample with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #3
Source File: AbstractWebArgumentResolverAdapter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #4
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: AnnotationMethodHandlerExceptionResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: AnnotationMethodHandlerExceptionResolver.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: AbstractWebArgumentResolverAdapter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #8
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: AnnotationMethodHandlerExceptionResolver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: AbstractWebArgumentResolverAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Delegate to the {@link WebArgumentResolver} instance.
 * @throws IllegalStateException if the resolved value is not assignable
 * to the method parameter.
 */
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, @Nullable 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;
}
 
Example #11
Source File: AbstractWebArgumentResolverAdapter.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #12
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Assert.notNull(className, "No resolver class");
			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;
}
 
Example #13
Source File: AbstractWebArgumentResolverAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Delegate to the {@link WebArgumentResolver} instance.
 * @throws IllegalStateException if the resolved value is not assignable
 * to the method parameter.
 */
@Override
@Nullable
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, @Nullable 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;
}
 
Example #14
Source File: AbstractWebArgumentResolverAdapter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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)
		if (logger.isDebugEnabled()) {
			logger.debug("Error in checking support for parameter [" + parameter + "]: " + ex.getMessage());
		}
		return false;
	}
}
 
Example #15
Source File: WebArgumentResolverAdapterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #16
Source File: WebArgumentResolverAdapterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #17
Source File: HandlerMethodInvoker.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: AbstractWebArgumentResolverAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: WebArgumentResolverAdapterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #20
Source File: AbstractWebArgumentResolverAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #21
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #22
Source File: WebArgumentResolverAdapterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: WebArgumentResolverAdapterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: UserDetailsArgumentResolver.java    From slackspace-angular-spring-keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
		NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

	if (supportsParameter(methodParameter)) {
		return createUserDetails(webRequest);
	}
	else {
		return WebArgumentResolver.UNRESOLVED;
	}
}
 
Example #25
Source File: CurrentUserHandlerMethodArgumentResolver.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
public Object resolveArgument(MethodParameter methodParameter,
                              ModelAndViewContainer mavContainer, NativeWebRequest webRequest,
                              WebDataBinderFactory binderFactory) throws Exception {
    if (this.supportsParameter(methodParameter)) {
        return securityUtils.getCurrentUser();
    } else {
        return WebArgumentResolver.UNRESOLVED;
    }
}
 
Example #26
Source File: CurrentUserHandlerMethodArgumentResolver.java    From spring-boot-security-saml-sample with Apache License 2.0 5 votes vote down vote up
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;
	}
}
 
Example #27
Source File: WebArgumentResolverAdapterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #28
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected Object resolveStandardArgument(Class<?> parameterType, NativeWebRequest webRequest) throws Exception {
	if (WebRequest.class.isAssignableFrom(parameterType)) {
		return webRequest;
	}
	return WebArgumentResolver.UNRESOLVED;
}
 
Example #29
Source File: HandlerMethodInvoker.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #30
Source File: WebArgumentResolverAdapterTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void resolveArgumentUnresolved() throws Exception {
	given(adaptee.resolveArgument(parameter, webRequest)).willReturn(WebArgumentResolver.UNRESOLVED);

	adapter.resolveArgument(parameter, null, webRequest, null);
}