Search in sources :

Example 6 with HandlerMethodArgumentResolver

use of org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class DefaultMessageHandlerMethodFactory method initArgumentResolvers.

protected List<HandlerMethodArgumentResolver> initArgumentResolvers() {
    List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
    ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) this.beanFactory : null);
    // Annotation-based argument resolution
    resolvers.add(new HeaderMethodArgumentResolver(this.conversionService, cbf));
    resolvers.add(new HeadersMethodArgumentResolver());
    // Type-based argument resolution
    resolvers.add(new MessageMethodArgumentResolver(this.messageConverter));
    if (this.customArgumentResolvers != null) {
        resolvers.addAll(this.customArgumentResolvers);
    }
    resolvers.add(new PayloadArgumentResolver(this.messageConverter, this.validator));
    return resolvers;
}
Also used : ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) ArrayList(java.util.ArrayList) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver)

Example 7 with HandlerMethodArgumentResolver

use of org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver in project spring-framework by spring-projects.

the class DefaultMessageHandlerMethodFactoryTests method customArgumentResolver.

@Test
public void customArgumentResolver() throws Exception {
    DefaultMessageHandlerMethodFactory instance = createInstance();
    List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<>();
    customResolvers.add(new CustomHandlerMethodArgumentResolver());
    instance.setCustomArgumentResolvers(customResolvers);
    instance.afterPropertiesSet();
    InvocableHandlerMethod invocableHandlerMethod = createInvocableHandlerMethod(instance, "customArgumentResolver", Locale.class);
    invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build());
    assertMethodInvocation(sample, "customArgumentResolver");
}
Also used : InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) ArrayList(java.util.ArrayList) HandlerMethodArgumentResolver(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver) Test(org.junit.Test)

Aggregations

HandlerMethodArgumentResolver (org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 HandlerMethodReturnValueHandler (org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler)3 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)3 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)2 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 DestinationVariableMethodArgumentResolver (org.springframework.messaging.handler.annotation.support.DestinationVariableMethodArgumentResolver)1 HeaderMethodArgumentResolver (org.springframework.messaging.handler.annotation.support.HeaderMethodArgumentResolver)1 HeadersMethodArgumentResolver (org.springframework.messaging.handler.annotation.support.HeadersMethodArgumentResolver)1 MessageMethodArgumentResolver (org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver)1 PayloadArgumentResolver (org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver)1 PathMatcher (org.springframework.util.PathMatcher)1