Java Code Examples for org.springframework.web.method.support.HandlerMethodArgumentResolverComposite

The following examples show how to use org.springframework.web.method.support.HandlerMethodArgumentResolverComposite. These examples are extracted from open source projects. 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
@Test
void getObject_withDefaultConfiguration_createCompositeResolverWithAllDelegatedResolvers()
		throws Exception {
	// Arrange
	AmazonSNS amazonSns = mock(AmazonSNS.class);
	NotificationHandlerMethodArgumentResolverFactoryBean factoryBean;
	factoryBean = new NotificationHandlerMethodArgumentResolverFactoryBean(amazonSns);
	factoryBean.afterPropertiesSet();

	// Act
	HandlerMethodArgumentResolver argumentResolver = factoryBean.getObject();

	// Assert
	assertThat(argumentResolver).isNotNull();
	assertThat(((HandlerMethodArgumentResolverComposite) argumentResolver)
			.getResolvers().size()).isEqualTo(3);
}
 
Example 2
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 3
@Override
public void afterPropertiesSet() {
	// Do this first, it may add ResponseBodyAdvice beans
	initExceptionHandlerAdviceCache();

	if (this.argumentResolvers == null) {
		List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers);
	}
	if (this.returnValueHandlers == null) {
		List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
	}
}
 
Example 4
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 5
/**
 * Configure the supported argument types in {@code @InitBinder} methods.
 */
public void setInitBinderArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.initBinderArgumentResolvers = null;
	}
	else {
		this.initBinderArgumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.initBinderArgumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 6
Source Project: spring-analysis-note   Source File: ModelFactoryTests.java    License: MIT License 5 votes vote down vote up
private ModelFactory createModelFactory(String methodName, Class<?>... parameterTypes) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelMethodProcessor());

	InvocableHandlerMethod modelMethod = createHandlerMethod(methodName, parameterTypes);
	modelMethod.setHandlerMethodArgumentResolvers(resolvers);
	modelMethod.setDataBinderFactory(null);
	modelMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
}
 
Example 7
Source Project: spring-analysis-note   Source File: ModelFactoryOrderingTests.java    License: MIT License 5 votes vote down vote up
private void runTest(Object controller) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelAttributeMethodProcessor(false));
	resolvers.addResolver(new ModelMethodProcessor());
	WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);

	Class<?> type = controller.getClass();
	Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
	List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
	for (Method method : methods) {
		InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
		modelMethod.setHandlerMethodArgumentResolvers(resolvers);
		modelMethod.setDataBinderFactory(dataBinderFactory);
		modelMethods.add(modelMethod);
	}
	Collections.shuffle(modelMethods);

	SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
	ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
	factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
	if (logger.isDebugEnabled()) {
		StringBuilder sb = new StringBuilder();
		for (String name : getInvokedMethods()) {
			sb.append(" >> ").append(name);
		}
		logger.debug(sb);
	}
}
 
Example 8
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 9
@Override
public void afterPropertiesSet() {
	// Do this first, it may add ResponseBodyAdvice beans
	initExceptionHandlerAdviceCache();

	if (this.argumentResolvers == null) {
		List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers);
	}
	if (this.returnValueHandlers == null) {
		List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
	}
}
 
Example 10
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 11
/**
 * Configure the supported argument types in {@code @InitBinder} methods.
 */
public void setInitBinderArgumentResolvers(@Nullable List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.initBinderArgumentResolvers = null;
	}
	else {
		this.initBinderArgumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.initBinderArgumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 12
Source Project: java-technology-stack   Source File: ModelFactoryTests.java    License: MIT License 5 votes vote down vote up
private ModelFactory createModelFactory(String methodName, Class<?>... parameterTypes) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelMethodProcessor());

	InvocableHandlerMethod modelMethod = createHandlerMethod(methodName, parameterTypes);
	modelMethod.setHandlerMethodArgumentResolvers(resolvers);
	modelMethod.setDataBinderFactory(null);
	modelMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new ModelFactory(Collections.singletonList(modelMethod), null, this.attributeHandler);
}
 
Example 13
Source Project: java-technology-stack   Source File: ModelFactoryOrderingTests.java    License: MIT License 5 votes vote down vote up
private void runTest(Object controller) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelAttributeMethodProcessor(false));
	resolvers.addResolver(new ModelMethodProcessor());
	WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);

	Class<?> type = controller.getClass();
	Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
	List<InvocableHandlerMethod> modelMethods = new ArrayList<>();
	for (Method method : methods) {
		InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
		modelMethod.setHandlerMethodArgumentResolvers(resolvers);
		modelMethod.setDataBinderFactory(dataBinderFactory);
		modelMethods.add(modelMethod);
	}
	Collections.shuffle(modelMethods);

	SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
	ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
	factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
	if (logger.isDebugEnabled()) {
		StringBuilder sb = new StringBuilder();
		for (String name : getInvokedMethods()) {
			sb.append(" >> ").append(name);
		}
		logger.debug(sb);
	}
}
 
Example 14
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 15
@Override
public void afterPropertiesSet() {
	// Do this first, it may add ResponseBodyAdvice beans
	initExceptionHandlerAdviceCache();

	if (this.argumentResolvers == null) {
		List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers);
	}
	if (this.returnValueHandlers == null) {
		List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
	}
}
 
Example 16
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 17
/**
 * Configure the supported argument types in {@code @InitBinder} methods.
 */
public void setInitBinderArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.initBinderArgumentResolvers = null;
	}
	else {
		this.initBinderArgumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.initBinderArgumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 18
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 19
@Override
public void afterPropertiesSet() {
	// Do this first, it may add ResponseBodyAdvice beans
	initExceptionHandlerAdviceCache();

	if (this.argumentResolvers == null) {
		List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers);
	}
	if (this.returnValueHandlers == null) {
		List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
	}
}
 
Example 20
/**
 * Configure the complete list of supported argument types thus overriding
 * the resolvers that would otherwise be configured by default.
 */
public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.argumentResolvers = null;
	}
	else {
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.argumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 21
/**
 * Configure the supported argument types in {@code @InitBinder} methods.
 */
public void setInitBinderArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
	if (argumentResolvers == null) {
		this.initBinderArgumentResolvers = null;
	}
	else {
		this.initBinderArgumentResolvers = new HandlerMethodArgumentResolverComposite();
		this.initBinderArgumentResolvers.addResolvers(argumentResolvers);
	}
}
 
Example 22
Source Project: spring4-understanding   Source File: ModelFactoryTests.java    License: Apache License 2.0 5 votes vote down vote up
private ModelFactory createModelFactory(String methodName, Class<?>... parameterTypes) throws Exception{
	Method method = TestController.class.getMethod(methodName, parameterTypes);

	HandlerMethodArgumentResolverComposite argResolvers = new HandlerMethodArgumentResolverComposite();
	argResolvers.addResolver(new ModelMethodProcessor());

	InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(this.controller, method);
	handlerMethod.setHandlerMethodArgumentResolvers(argResolvers);
	handlerMethod.setDataBinderFactory(null);
	handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());

	return new ModelFactory(Arrays.asList(handlerMethod), null, this.sessionAttrsHandler);
}
 
Example 23
private void runTest(Object controller) throws Exception {
	HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite();
	resolvers.addResolver(new ModelAttributeMethodProcessor(false));
	resolvers.addResolver(new ModelMethodProcessor());
	WebDataBinderFactory dataBinderFactory = new DefaultDataBinderFactory(null);

	Class<?> type = controller.getClass();
	Set<Method> methods = MethodIntrospector.selectMethods(type, METHOD_FILTER);
	List<InvocableHandlerMethod> modelMethods = new ArrayList<InvocableHandlerMethod>();
	for (Method method : methods) {
		InvocableHandlerMethod modelMethod = new InvocableHandlerMethod(controller, method);
		modelMethod.setHandlerMethodArgumentResolvers(resolvers);
		modelMethod.setDataBinderFactory(dataBinderFactory);
		modelMethods.add(modelMethod);
	}
	Collections.shuffle(modelMethods);

	SessionAttributesHandler sessionHandler = new SessionAttributesHandler(type, this.sessionAttributeStore);
	ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
	factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
	if (logger.isDebugEnabled()) {
		StringBuilder sb = new StringBuilder();
		for (String name : getInvokedMethods()) {
			sb.append(" >> ").append(name);
		}
		logger.debug(sb);
	}
}
 
Example 24
public SpringParameterProvider(ConfigurableBeanFactory beanFactory, HttpServletRequest request) {
    this.request = request;
    this.beanFactory = beanFactory;

    List<HttpMessageConverter<?>> messageConverters = getHttpMessageConverters();
    argumentResolvers = new HandlerMethodArgumentResolverComposite()
        .addResolvers(getArgumentResolvers(messageConverters));

}
 
Example 25
public static HandlerMethodArgumentResolver getNotificationHandlerMethodArgumentResolver(
		AmazonSNS amazonSns) {
	HandlerMethodArgumentResolverComposite composite = new HandlerMethodArgumentResolverComposite();
	composite.addResolver(
			new NotificationStatusHandlerMethodArgumentResolver(amazonSns));
	composite.addResolver(new NotificationMessageHandlerMethodArgumentResolver());
	composite.addResolver(new NotificationSubjectHandlerMethodArgumentResolver());
	return composite;
}
 
Example 26
/**
 * Return the configured argument resolvers, or possibly {@code null} if
 * not initialized yet via {@link #afterPropertiesSet()}.
 */
@Nullable
public HandlerMethodArgumentResolverComposite getArgumentResolvers() {
	return this.argumentResolvers;
}
 
Example 27
/**
 * Return the configured argument resolvers, or possibly {@code null} if
 * not initialized yet via {@link #afterPropertiesSet()}.
 */
@Nullable
public HandlerMethodArgumentResolverComposite getArgumentResolvers() {
	return this.argumentResolvers;
}
 
Example 28
@Before
public void setUp() throws Exception {
	bindingInitializer = new ConfigurableWebBindingInitializer();
	argumentResolvers = new HandlerMethodArgumentResolverComposite();
	webRequest = new ServletWebRequest(new MockHttpServletRequest());
}
 
Example 29
/**
 * Return the configured argument resolvers, or possibly {@code null} if
 * not initialized yet via {@link #afterPropertiesSet()}.
 */
public HandlerMethodArgumentResolverComposite getArgumentResolvers() {
	return this.argumentResolvers;
}
 
Example 30
/**
 * Return the configured argument resolvers, or possibly {@code null} if
 * not initialized yet via {@link #afterPropertiesSet()}.
 */
public HandlerMethodArgumentResolverComposite getArgumentResolvers() {
	return this.argumentResolvers;
}