From 8b1c5b13150d49a6cc5c7b3fa8d729174dbaa711 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 2 Aug 2010 01:53:45 +0000 Subject: [PATCH] INT-1302, MarshallingWebServiceInboundGateway now implements SmartLifecycle, so it will register itself as a subscriber to the reply-channel. It wasn't doing this. --- .../MarshallingWebServiceInboundGateway.java | 61 +++++++++++++++++-- .../WebServiceInboundGatewayParserTests.java | 2 + 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java index 9329512559..97f65bc09f 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/MarshallingWebServiceInboundGateway.java @@ -16,18 +16,20 @@ package org.springframework.integration.ws; +import java.util.concurrent.locks.ReentrantLock; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.context.Lifecycle; +import org.springframework.context.SmartLifecycle; import org.springframework.expression.ExpressionException; import org.springframework.integration.MessagingException; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.gateway.SimpleMessagingGateway; -import org.springframework.scheduling.TaskScheduler; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; +import org.springframework.scheduling.TaskScheduler; import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint; /** @@ -35,8 +37,9 @@ import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint * @since 1.0.2 */ public class MarshallingWebServiceInboundGateway extends AbstractMarshallingPayloadEndpoint - implements BeanNameAware, BeanFactoryAware, InitializingBean, Lifecycle { + implements BeanNameAware, BeanFactoryAware, InitializingBean, SmartLifecycle { + private final ReentrantLock lifecycleLock = new ReentrantLock(); private final SimpleMessagingGateway gatewayDelegate = new SimpleMessagingGateway(); @@ -127,15 +130,61 @@ public class MarshallingWebServiceInboundGateway extends AbstractMarshallingPayl // Lifecycle implementation public boolean isRunning() { - return this.gatewayDelegate.isRunning(); + this.lifecycleLock.lock(); + try { + return this.gatewayDelegate.isRunning(); + } + finally { + this.lifecycleLock.unlock(); + } } public void start() { - this.gatewayDelegate.start(); + this.lifecycleLock.lock(); + try { + if (!gatewayDelegate.isRunning()) { + this.gatewayDelegate.start(); + if (logger.isInfoEnabled()) { + logger.info("started " + this); + } + } + } + finally { + this.lifecycleLock.unlock(); + } } public void stop() { - this.gatewayDelegate.stop(); + this.lifecycleLock.lock(); + try { + if (gatewayDelegate.isRunning()) { + this.gatewayDelegate.stop(); + if (logger.isInfoEnabled()) { + logger.info("stopped " + this); + } + } + } + finally { + this.lifecycleLock.unlock(); + } } + public boolean isAutoStartup() { + return true; + } + + public void stop(Runnable callback) { + this.lifecycleLock.lock(); + try { + this.stop(); + callback.run(); + } + finally { + this.lifecycleLock.unlock(); + } + } + + public int getPhase() { + return 0; + } } diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java index 18a08734d9..87281c17c9 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java @@ -17,6 +17,7 @@ package org.springframework.integration.ws.config; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +import static junit.framework.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; @@ -87,5 +88,6 @@ public class WebServiceInboundGatewayParserTests { is(marshaller)); assertThat((AbstractMarshaller) accessor.getPropertyValue("unmarshaller"), is(marshaller)); + assertTrue("messaging gateway is not running", marshallingGateway.isRunning()); } }