From 79f78a36f7744eb24fb30677d80de02b8686cdb0 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 9 Jan 2019 21:38:20 +0100 Subject: [PATCH] INT-4571 Make MessageHandlerMethodFactory injectable Make MessageHandlerMethodFactory injectable into MessagingMethodInvokerHelper Allow 'handlerMethod' to be overriden Deprecate HandlerMethodArgumentResolversHolder Add 'integrationMessageHandlerMethodFactory' property to IntegrationContextUtils Add test that actually validates that custom resolver gets picked up --- .../context/IntegrationContextUtils.java | 5 +- .../HandlerMethodArgumentResolversHolder.java | 5 +- .../support/MessagingMethodInvokerHelper.java | 92 +++++++++++-------- .../MethodInvokingMessageProcessorTests.java | 65 ++++++++++++- 4 files changed, 127 insertions(+), 40 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java index 5adc4954151..40e0bf66a41 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ * @author Josh Long * @author Artem Bilan * @author Gary Russell + * @author Oleg Zhurakousky */ public abstract class IntegrationContextUtils { @@ -105,6 +106,8 @@ public abstract class IntegrationContextUtils { public static final String DISPOSABLES_BEAN_NAME = "integrationDisposableAutoCreatedBeans"; + public static final String MESSAGE_HANDLER_FACTORY_BEAN_NAME = "integrationMessageHandlerMethodFactory"; + /** * @param beanFactory BeanFactory for lookup, must not be null. * @return The {@link MetadataStore} bean whose name is "metadataStore". diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/HandlerMethodArgumentResolversHolder.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/HandlerMethodArgumentResolversHolder.java index 242a40a68d4..8f29286dc13 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/HandlerMethodArgumentResolversHolder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/HandlerMethodArgumentResolversHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,9 @@ * @author Gary Russell * * @since 5.0 - * + * @deprecated as of 5.1.2. Instead simply configure your own MessageHandlerMethodFactory as a bean. */ +@Deprecated public class HandlerMethodArgumentResolversHolder { private final List resolvers; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java index 24cdfcc1609..331557f96b6 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/support/MessagingMethodInvokerHelper.java @@ -94,6 +94,7 @@ import org.springframework.messaging.handler.annotation.Headers; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; +import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; import org.springframework.messaging.handler.invocation.MethodArgumentResolutionException; @@ -167,7 +168,7 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator SPEL_COMPILERS.put(SpelCompilerMode.MIXED, EXPRESSION_PARSER_MIXED); } - private final DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = + private MessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory(); private final Object targetObject; @@ -184,7 +185,7 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator private final List, HandlerMethod>> handlerMethodsList; - private final HandlerMethod handlerMethod; + private HandlerMethod handlerMethod; private final TypeDescriptor expectedType; @@ -257,16 +258,7 @@ private MessagingMethodInvokerHelper(Object targetObject, Class message) throws Exception { + String[] names = ((String) message.getPayload()).split(" "); + return new Person(names[0], names[1]); + } + }; + f.setArgumentResolvers(Collections.singletonList(resolver)); + f.afterPropertiesSet(); + return f; + } + + public static class Person { + private final String name; + public Person(String fname, String lname) { + this.name = fname + " " + lname; + } + public String toString() { + return "Person: " + name; + } + } + } + @Test public void testHandlerInheritanceMethodImplInSuper() { class A {