INT-4245: Improve ReplyProducingMHWrapper

JIRA: https://jira.spring.io/browse/INT-4245

* Move `ReplyProducingMessageHandlerWrapper` outside of
`ServiceActivatorAnnotationPostProcessor`.
* Use it from the `ServiceActivatorFactoryBean` as well to fix
the missed `Lifecycle` control
* Increase wait timeout in the `ConnectionFactoryTests`
* Mark endpoint as `auto-startup="false"` in the SFTP parser tests
* Remove redundant `org.gradle.daemon=true` from the `gradle.properties`
since it is like that by default for a while already
This commit is contained in:
Artem Bilan
2017-05-17 14:18:49 -04:00
committed by Gary Russell
parent 95d2cc2352
commit ea6cf0f4ef
8 changed files with 96 additions and 76 deletions

View File

@@ -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.");
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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.
* <p>
* This class is used internally by Framework in cased when request-reply is important
* and there is no other way to apply advice chain.
* <p>
* 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();
}
}