Search in sources :

Example 1 with HandlerMethodArgumentResolverComposite

use of org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite in project spring-cloud-stream by spring-cloud.

the class AbstractBinderTests method buildStreamListener.

private StreamListenerMessageHandler buildStreamListener(Class<?> handlerClass, String handlerMethodName, Class<?>... parameters) throws Exception {
    String channelName = "reply_" + System.nanoTime();
    GenericApplicationContext context = new GenericApplicationContext();
    context.getBeanFactory().registerSingleton(channelName, new QueueChannel());
    Method m = ReflectionUtils.findMethod(handlerClass, handlerMethodName, parameters);
    InvocableHandlerMethod method = new InvocableHandlerMethod(this, m);
    HandlerMethodArgumentResolverComposite resolver = new HandlerMethodArgumentResolverComposite();
    CompositeMessageConverterFactory factory = new CompositeMessageConverterFactory();
    resolver.addResolver(new PayloadArgumentResolver(factory.getMessageConverterForAllRegistered()));
    method.setMessageMethodArgumentResolvers(resolver);
    Constructor<?> c = ReflectionUtils.accessibleConstructor(StreamListenerMessageHandler.class, InvocableHandlerMethod.class, boolean.class, String[].class);
    StreamListenerMessageHandler handler = (StreamListenerMessageHandler) c.newInstance(method, false, new String[] {});
    handler.setOutputChannelName(channelName);
    handler.setBeanFactory(context);
    handler.afterPropertiesSet();
    context.refresh();
    return handler;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) QueueChannel(org.springframework.integration.channel.QueueChannel) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) InvocableHandlerMethod(org.springframework.messaging.handler.invocation.InvocableHandlerMethod) Method(java.lang.reflect.Method) CompositeMessageConverterFactory(org.springframework.cloud.stream.converter.CompositeMessageConverterFactory) PayloadArgumentResolver(org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver) HandlerMethodArgumentResolverComposite(org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite) StreamListenerMessageHandler(org.springframework.cloud.stream.binding.StreamListenerMessageHandler)

Aggregations

Method (java.lang.reflect.Method)1 StreamListenerMessageHandler (org.springframework.cloud.stream.binding.StreamListenerMessageHandler)1 CompositeMessageConverterFactory (org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 PayloadArgumentResolver (org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver)1 HandlerMethodArgumentResolverComposite (org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite)1 InvocableHandlerMethod (org.springframework.messaging.handler.invocation.InvocableHandlerMethod)1