diff --git a/gradle.properties b/gradle.properties index 9136e989dd..0114fb7771 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1 @@ version=5.0.0.BUILD-SNAPSHOT -org.gradle.daemon=true diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java index 4def1768ad..ebc0634909 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ServiceActivatorFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -21,8 +21,8 @@ import org.springframework.integration.handler.AbstractMessageProducingHandler; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor; import org.springframework.integration.handler.MessageProcessor; +import org.springframework.integration.handler.ReplyProducingMessageHandlerWrapper; import org.springframework.integration.handler.ServiceActivatingHandler; -import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.util.StringUtils; @@ -32,6 +32,8 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @author Gary Russell * @author David Liu + * @author Artem Bilan + * * @since 2.0 */ public class ServiceActivatorFactoryBean extends AbstractStandardMessageHandlerFactoryBean { @@ -55,8 +57,8 @@ public class ServiceActivatorFactoryBean extends AbstractStandardMessageHandlerF if (handler == null) { handler = configureHandler( StringUtils.hasText(targetMethodName) - ? new ServiceActivatingHandler(targetObject, targetMethodName) - : new ServiceActivatingHandler(targetObject)); + ? new ServiceActivatingHandler(targetObject, targetMethodName) + : new ServiceActivatingHandler(targetObject)); } return handler; } @@ -80,15 +82,7 @@ public class ServiceActivatorFactoryBean extends AbstractStandardMessageHandlerF * Return a reply-producing message handler so that we still get 'produced no reply' messages * and the super class will inject the advice chain to advise the handler method if needed. */ - handler = new AbstractReplyProducingMessageHandler() { - - @Override - protected Object handleRequestMessage(Message> requestMessage) { - - ((MessageHandler) targetObject).handleMessage(requestMessage); - return null; - } - }; + handler = new ReplyProducingMessageHandlerWrapper((MessageHandler) targetObject); } return handler; @@ -135,7 +129,7 @@ public class ServiceActivatorFactoryBean extends AbstractStandardMessageHandlerF else { if (this.requiresReply && logger.isDebugEnabled()) { logger.debug("requires-reply can only be set to AbstractReplyProducingMessageHandler or its subclass, " - + handler.getComponentName() + " doesn't support it."); + + handler.getComponentName() + " doesn't support it."); } } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/ServiceActivatorAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/ServiceActivatorAnnotationPostProcessor.java index aa2fe1480a..c9fabc7ec8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/ServiceActivatorAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/ServiceActivatorAnnotationPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -22,14 +22,13 @@ import java.util.Arrays; import java.util.List; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.context.Lifecycle; import org.springframework.context.annotation.Bean; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; +import org.springframework.integration.handler.ReplyProducingMessageHandlerWrapper; import org.springframework.integration.handler.ServiceActivatingHandler; import org.springframework.integration.util.MessagingAnnotationUtils; -import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.util.StringUtils; @@ -84,41 +83,4 @@ public class ServiceActivatorAnnotationPostProcessor extends AbstractMethodAnnot return serviceActivator; } - private static final class ReplyProducingMessageHandlerWrapper extends AbstractReplyProducingMessageHandler - implements Lifecycle { - - private final MessageHandler target; - - ReplyProducingMessageHandlerWrapper(MessageHandler target) { - this.target = target; - } - - @Override - protected Object handleRequestMessage(Message> requestMessage) { - this.target.handleMessage(requestMessage); - return null; - } - - @Override - public void start() { - if (this.target instanceof Lifecycle) { - ((Lifecycle) this.target).start(); - } - - } - - @Override - public void stop() { - if (this.target instanceof Lifecycle) { - ((Lifecycle) this.target).stop(); - } - } - - @Override - public boolean isRunning() { - return !(this.target instanceof Lifecycle) || ((Lifecycle) this.target).isRunning(); - } - - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java new file mode 100644 index 0000000000..b0bdb02668 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/ReplyProducingMessageHandlerWrapper.java @@ -0,0 +1,71 @@ +/* + * Copyright 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.handler; + +import org.springframework.context.Lifecycle; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHandler; + +/** + * The {@link AbstractReplyProducingMessageHandler} wrapper around raw {@link MessageHandler} + * for request-reply scenarios, e.g. {@code @ServiceActivator} annotation configuration. + *
+ * This class is used internally by Framework in cased when request-reply is important + * and there is no other way to apply advice chain. + *
+ * The lifecycle control is delegated to the {@code target} {@link MessageHandler}.
+ *
+ * @author Artem Bilan
+ *
+ * @since 5.0
+ */
+public class ReplyProducingMessageHandlerWrapper extends AbstractReplyProducingMessageHandler
+ implements Lifecycle {
+
+ private final MessageHandler target;
+
+ public ReplyProducingMessageHandlerWrapper(MessageHandler target) {
+ this.target = target;
+ }
+
+ @Override
+ protected Object handleRequestMessage(Message> requestMessage) {
+ this.target.handleMessage(requestMessage);
+ return null;
+ }
+
+ @Override
+ public void start() {
+ if (this.target instanceof Lifecycle) {
+ ((Lifecycle) this.target).start();
+ }
+
+ }
+
+ @Override
+ public void stop() {
+ if (this.target instanceof Lifecycle) {
+ ((Lifecycle) this.target).stop();
+ }
+ }
+
+ @Override
+ public boolean isRunning() {
+ return !(this.target instanceof Lifecycle) || ((Lifecycle) this.target).isRunning();
+ }
+
+}
diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java
index 13b913c5e3..cbc04dbc71 100644
--- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java
+++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java
@@ -150,7 +150,7 @@ public class ConnectionFactoryTests extends LogAdjustingTestSupport {
List