From 5a362b62ff543fdca794e8c911729e20a39493ff Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 15 Jun 2018 08:40:11 -0400 Subject: [PATCH] Destroy RmiInboundGateway.RmiServiceExporter (#2481) * Destroy RmiInboundGateway.RmiServiceExporter The internal instance `RmiServiceExporter` of the `RmiInboundGateway` has to be destroyed together with the outer instance to unbind `service` from the RMI registry * Perform some polishing for the `RmiInboundGateway` and optimize a `AbstractInboundGatewayParser` for late channels binding * * Polishing some tests * Expose getters for channels on the `MessagingGatewaySupport` * Fix RMI tests to use random port --- .../xml/AbstractInboundGatewayParser.java | 11 +-- .../gateway/MessagingGatewaySupport.java | 9 ++- .../ip/config/ParserUnitTests.java | 4 +- .../ChannelPublishingJmsMessageListener.java | 7 +- .../RedisQueueInboundGatewayParserTests.java | 4 +- .../integration/rmi/RmiInboundGateway.java | 72 ++++++++++--------- .../rmi/BackToBackTests-context.xml | 2 +- .../RmiInboundGatewayParserTests-context.xml | 24 ++++--- .../config/RmiInboundGatewayParserTests.java | 8 +-- .../RmiOutboundGatewayParserTests-context.xml | 24 ++++--- .../config/RmiOutboundGatewayParserTests.java | 25 +++++-- .../WebServiceInboundGatewayParserTests.java | 63 +++++++--------- 12 files changed, 136 insertions(+), 117 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractInboundGatewayParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractInboundGatewayParser.java index c161aa96c8..3b1a84e76d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractInboundGatewayParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractInboundGatewayParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -31,12 +31,14 @@ import org.springframework.util.StringUtils; * * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ public abstract class AbstractInboundGatewayParser extends AbstractSimpleBeanDefinitionParser { @Override protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException { + String id = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(id)) { id = element.getAttribute("name"); @@ -58,21 +60,20 @@ public abstract class AbstractInboundGatewayParser extends AbstractSimpleBeanDef protected final void postProcess(BeanDefinitionBuilder builder, Element element) { String requestChannelRef = element.getAttribute("request-channel"); Assert.hasText(requestChannelRef, "a 'request-channel' reference is required"); - builder.addPropertyReference("requestChannel", requestChannelRef); + builder.addPropertyValue("requestChannelName", requestChannelRef); String replyChannel = element.getAttribute("reply-channel"); if (StringUtils.hasText(replyChannel)) { - builder.addPropertyReference("replyChannel", replyChannel); + builder.addPropertyValue("replyChannelName", replyChannel); } String errorChannel = element.getAttribute("error-channel"); if (StringUtils.hasText(errorChannel)) { - builder.addPropertyReference("errorChannel", errorChannel); + builder.addPropertyValue("errorChannelName", errorChannel); } this.doPostProcess(builder, element); } /** * Subclasses may add to the bean definition by overriding this method. - * * @param builder The builder. * @param element The element. */ diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java index 0e78dee1b7..5d1c941f73 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/MessagingGatewaySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -372,7 +372,12 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint return this.requestChannel; } - protected MessageChannel getReplyChannel() { + /** + * Return this gateway's reply channel if any. + * @return the reply channel instance + * @since 5.1 + */ + public MessageChannel getReplyChannel() { if (this.replyChannelName != null) { synchronized (this) { if (this.replyChannelName != null) { diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java index e80ce360c1..83740a30e3 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -444,7 +444,7 @@ public class ParserUnitTests { assertEquals(456L, dfa.getPropertyValue("replyTimeout")); assertEquals("inGateway1", tcpInboundGateway1.getComponentName()); assertEquals("ip:tcp-inbound-gateway", tcpInboundGateway1.getComponentType()); - assertEquals(errorChannel, dfa.getPropertyValue("errorChannel")); + assertEquals(errorChannel, tcpInboundGateway1.getErrorChannel()); assertTrue(cfS2.isLookupHost()); assertFalse(tcpInboundGateway1.isAutoStartup()); assertEquals(126, tcpInboundGateway1.getPhase()); diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java index 194eacb5a6..e9092f9ed6 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/ChannelPublishingJmsMessageListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -501,11 +501,6 @@ public class ChannelPublishingJmsMessageListener super(); } - @Override - public MessageChannel getErrorChannel() { - return super.getErrorChannel(); - } - @Override protected void send(Object request) { super.send(request); diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueInboundGatewayParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueInboundGatewayParserTests.java index e69b6b103c..6abaa28210 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueInboundGatewayParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueInboundGatewayParserTests.java @@ -73,8 +73,8 @@ public class RedisQueueInboundGatewayParserTests { assertFalse(TestUtils.getPropertyValue(this.defaultGateway, "extractPayload", Boolean.class)); assertSame(this.serializer, TestUtils.getPropertyValue(this.defaultGateway, "serializer")); assertTrue(TestUtils.getPropertyValue(this.defaultGateway, "serializerExplicitlySet", Boolean.class)); - assertSame(this.receiveChannel, TestUtils.getPropertyValue(this.defaultGateway, "replyChannel")); - assertSame(this.requestChannel, TestUtils.getPropertyValue(this.defaultGateway, "requestChannel")); + assertSame(this.receiveChannel, this.defaultGateway.getReplyChannel()); + assertSame(this.requestChannel, this.defaultGateway.getRequestChannel()); assertEquals(2000L, TestUtils.getPropertyValue(this.defaultGateway, "replyTimeout")); assertNotNull(TestUtils.getPropertyValue(this.defaultGateway, "taskExecutor")); assertFalse(TestUtils.getPropertyValue(this.defaultGateway, "autoStartup", Boolean.class)); diff --git a/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java b/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java index f9c811bbc1..460a7ee612 100644 --- a/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java +++ b/spring-integration-rmi/src/main/java/org/springframework/integration/rmi/RmiInboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2018 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. @@ -33,25 +33,25 @@ import org.springframework.util.StringUtils; * An inbound Messaging Gateway for RMI-based remoting. * * @author Mark Fisher + * @author Artem Bilan */ -public class RmiInboundGateway extends MessagingGatewaySupport implements RequestReplyExchanger, InitializingBean { +public class RmiInboundGateway extends MessagingGatewaySupport + implements RequestReplyExchanger, InitializingBean { public static final String SERVICE_NAME_PREFIX = "org.springframework.integration.rmiGateway."; - private volatile String requestChannelName; + private final RmiServiceExporter exporter = new RmiServiceExporter(); - private volatile String registryHost; + private String requestChannelName; - private volatile int registryPort = Registry.REGISTRY_PORT; + private String registryHost; - private volatile boolean expectReply = true; + private int registryPort = Registry.REGISTRY_PORT; - private volatile RemoteInvocationExecutor remoteInvocationExecutor; + private boolean expectReply = true; - private volatile RmiServiceExporter exporter; - - private final Object initializationMonitor = new Object(); + private RemoteInvocationExecutor remoteInvocationExecutor; /** @@ -62,16 +62,21 @@ public class RmiInboundGateway extends MessagingGatewaySupport implements Reques public void setRequestChannel(MessageChannel requestChannel) { Assert.notNull(requestChannel, "requestChannel must not be null"); Assert.isTrue(requestChannel instanceof NamedComponent && - StringUtils.hasText(((NamedComponent) requestChannel).getComponentName()), + StringUtils.hasText(((NamedComponent) requestChannel).getComponentName()), "RmiGateway's request channel must have a name."); this.requestChannelName = ((NamedComponent) requestChannel).getComponentName(); super.setRequestChannel(requestChannel); } + @Override + public void setRequestChannelName(String requestChannelName) { + this.requestChannelName = requestChannelName; + super.setRequestChannelName(requestChannelName); + } + /** * Specify whether the gateway should be expected to return a reply. * The default is 'true'. - * * @param expectReply true when a reply is expected. */ public void setExpectReply(boolean expectReply) { @@ -97,33 +102,36 @@ public class RmiInboundGateway extends MessagingGatewaySupport implements Reques @Override protected void onInit() throws Exception { - synchronized (this.initializationMonitor) { - if (this.exporter == null) { - RmiServiceExporter exporter = new RmiServiceExporter(); - if (this.registryHost != null) { - exporter.setRegistryHost(this.registryHost); - } - exporter.setRegistryPort(this.registryPort); - if (this.remoteInvocationExecutor != null) { - exporter.setRemoteInvocationExecutor(this.remoteInvocationExecutor); - } - exporter.setService(this); - exporter.setServiceInterface(RequestReplyExchanger.class); - exporter.setServiceName(SERVICE_NAME_PREFIX + this.requestChannelName); - exporter.afterPropertiesSet(); - this.exporter = exporter; - } - } super.onInit(); + + if (this.registryHost != null) { + this.exporter.setRegistryHost(this.registryHost); + } + this.exporter.setRegistryPort(this.registryPort); + if (this.remoteInvocationExecutor != null) { + this.exporter.setRemoteInvocationExecutor(this.remoteInvocationExecutor); + } + this.exporter.setService(this); + this.exporter.setServiceInterface(RequestReplyExchanger.class); + this.exporter.setServiceName(SERVICE_NAME_PREFIX + this.requestChannelName); + this.exporter.afterPropertiesSet(); } @Override public Message exchange(Message message) { if (this.expectReply) { - return this.sendAndReceiveMessage(message); + return sendAndReceiveMessage(message); } - this.send(message); - return null; + else { + send(message); + return null; + } + } + + @Override + public void destroy() throws Exception { + super.destroy(); + this.exporter.destroy(); } } diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests-context.xml b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests-context.xml index d5a8d97ced..cbf1355e78 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests-context.xml +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/BackToBackTests-context.xml @@ -29,7 +29,7 @@ - + diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests-context.xml b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests-context.xml index 4f4a753390..570279870b 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests-context.xml +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests-context.xml @@ -1,9 +1,9 @@ - + + expect-reply="false" request-timeout="123" reply-timeout="456" auto-startup="false"/> + error-channel="testErrorChannel" auto-startup="false"/> - + - + - + diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java index 322f3ae582..27ad59d6b6 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -59,7 +59,7 @@ public class RmiInboundGatewayParserTests { assertEquals("gatewayWithDefaults", gateway.getComponentName()); assertEquals("rmi:inbound-gateway", gateway.getComponentType()); assertTrue(TestUtils.getPropertyValue(gateway, "expectReply", Boolean.class)); - assertSame(this.channel, TestUtils.getPropertyValue(gateway, "requestChannel")); + assertSame(this.channel, gateway.getRequestChannel()); assertEquals(1000L, TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout")); assertEquals(1000L, TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout")); } @@ -69,7 +69,7 @@ public class RmiInboundGatewayParserTests { RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithCustomProperties"); assertFalse(TestUtils.getPropertyValue(gateway, "expectReply", Boolean.class)); - assertSame(this.channel, TestUtils.getPropertyValue(gateway, "requestChannel")); + assertSame(this.channel, gateway.getRequestChannel()); assertEquals(123L, TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout")); assertEquals(456L, TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout")); } @@ -78,7 +78,7 @@ public class RmiInboundGatewayParserTests { public void gatewayWithHost() { RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithHostAndErrorChannel"); assertEquals("localhost", TestUtils.getPropertyValue(gateway, "registryHost")); - assertSame(context.getBean("testErrorChannel"), TestUtils.getPropertyValue(gateway, "errorChannel")); + assertSame(context.getBean("testErrorChannel"), gateway.getErrorChannel()); } @Test diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests-context.xml b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests-context.xml index 102914efee..eb26d18874 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests-context.xml +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests-context.xml @@ -17,7 +17,8 @@ request-channel="localChannel" remote-channel="testChannel" configurer="configurer" - host="localhost"/> + host="localhost" + port="#{T(org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests).port}"/> @@ -25,28 +26,33 @@ request-channel="advisedChannel" remote-channel="testChannel" requires-reply="false" - host="localhost"> + host="localhost" + port="#{T(org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests).port}"> - + + value="org.springframework.integration.rmi.RmiOutboundGateway$RmiProxyFactoryBeanConfigurer"/> + class="org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests$FooAdvice"/> - + - + @@ -56,7 +62,9 @@ - + diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java index bb39e9b8ed..210809cb17 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiOutboundGatewayParserTests.java @@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,6 +47,7 @@ import org.springframework.remoting.rmi.RmiProxyFactoryBean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.SocketUtils; /** * @author Mark Fisher @@ -57,8 +59,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @DirtiesContext public class RmiOutboundGatewayParserTests { + public final static int port = SocketUtils.findAvailableTcpPort(); + private static final QueueChannel testChannel = new QueueChannel(); + private static final RmiInboundGateway rmiInboundGateway = new RmiInboundGateway(); + @Autowired public FooAdvice advice; @@ -86,13 +92,18 @@ public class RmiOutboundGatewayParserTests { RmiOutboundGateway advised; @BeforeClass - public static void setupTestInboundGateway() throws Exception { + public static void setupTestInboundGateway() { testChannel.setBeanName("testChannel"); - RmiInboundGateway gateway = new RmiInboundGateway(); - gateway.setRequestChannel(testChannel); - gateway.setExpectReply(false); - gateway.setBeanFactory(mock(BeanFactory.class)); - gateway.afterPropertiesSet(); + rmiInboundGateway.setRequestChannel(testChannel); + rmiInboundGateway.setRegistryPort(port); + rmiInboundGateway.setExpectReply(false); + rmiInboundGateway.setBeanFactory(mock(BeanFactory.class)); + rmiInboundGateway.afterPropertiesSet(); + } + + @AfterClass + public static void destroyInboundGateway() throws Exception { + rmiInboundGateway.destroy(); } @Test @@ -107,7 +118,7 @@ public class RmiOutboundGatewayParserTests { public void directInvocation() { assertFalse(TestUtils.getPropertyValue(advised, "requiresReply", Boolean.class)); - advisedChannel.send(new GenericMessage("test")); + advisedChannel.send(new GenericMessage<>("test")); Message result = testChannel.receive(1000); assertNotNull(result); assertEquals("test", result.getPayload()); 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 1a840bdbf8..da860637cb 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -30,8 +30,6 @@ import java.util.Collections; import java.util.Map; import java.util.Properties; -import javax.xml.transform.Source; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -50,9 +48,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.PollableChannel; import org.springframework.oxm.Unmarshaller; -import org.springframework.oxm.support.AbstractMarshaller; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.ws.context.DefaultMessageContext; @@ -69,7 +65,7 @@ import org.springframework.ws.soap.SoapMessage; */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration -@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class WebServiceInboundGatewayParserTests { @Autowired @@ -88,22 +84,25 @@ public class WebServiceInboundGatewayParserTests { @Qualifier("requestsVerySimple") MessageChannel requestsVerySimple; - @Test - public void configOk() throws Exception { - // config valid - } - //Simple @Autowired @Qualifier("simple") SimpleWebServiceInboundGateway simpleGateway; + //marshalling + @Autowired + @Qualifier("marshalling") + MarshallingWebServiceInboundGateway marshallingGateway; + + @Autowired + Unmarshaller marshaller; + @Test - public void simpleGatewayProperties() throws Exception { - assertSame(this.requestsVerySimple, TestUtils.getPropertyValue(this.simpleGateway, "requestChannel")); - assertSame(this.customErrorChannel, TestUtils.getPropertyValue(this.simpleGateway, "errorChannel")); - assertFalse(TestUtils.getPropertyValue(this.simpleGateway, "autoStartup", Boolean.class)); - assertEquals(101, TestUtils.getPropertyValue(this.simpleGateway, "phase")); + public void simpleGatewayProperties() { + assertSame(this.requestsVerySimple, this.simpleGateway.getRequestChannel()); + assertSame(this.customErrorChannel, this.simpleGateway.getErrorChannel()); + assertFalse(this.simpleGateway.isAutoStartup()); + assertEquals(101, this.simpleGateway.getPhase()); } //extractPayload = false @@ -112,36 +111,23 @@ public class WebServiceInboundGatewayParserTests { SimpleWebServiceInboundGateway payloadExtractingGateway; @Test - public void extractPayloadSet() throws Exception { + public void extractPayloadSet() { DirectFieldAccessor accessor = new DirectFieldAccessor( payloadExtractingGateway); assertThat((Boolean) accessor.getPropertyValue("extractPayload"), is(false)); } - //marshalling - @Autowired - @Qualifier("marshalling") - MarshallingWebServiceInboundGateway marshallingGateway; - - @Autowired - AbstractMarshaller marshaller; - @Test - public void marshallersSet() throws Exception { + public void marshallersSet() { DirectFieldAccessor accessor = new DirectFieldAccessor(marshallingGateway); - AbstractMarshaller retrievedMarshaller = (AbstractMarshaller) accessor.getPropertyValue("marshaller"); - assertThat(retrievedMarshaller, is(marshaller)); + assertThat(accessor.getPropertyValue("marshaller"), is(marshaller)); + assertThat(accessor.getPropertyValue("unmarshaller"), is(marshaller)); - AbstractMarshaller retrievedUnMarshaller = (AbstractMarshaller) accessor.getPropertyValue("unmarshaller"); - assertThat(retrievedUnMarshaller, is(marshaller)); + assertTrue("messaging gateway is not running", this.marshallingGateway.isRunning()); - assertTrue("messaging gateway is not running", marshallingGateway.isRunning()); - - assertThat( - (MessageChannel) accessor.getPropertyValue("errorChannel"), - is(customErrorChannel)); + assertSame(this.customErrorChannel, this.marshallingGateway.getErrorChannel()); AbstractHeaderMapper.HeaderMatcher requestHeaderMatcher = TestUtils.getPropertyValue(marshallingGateway, "headerMapper.requestHeaderMatcher", AbstractHeaderMapper.HeaderMatcher.class); @@ -158,7 +144,7 @@ public class WebServiceInboundGatewayParserTests { public void testMessageHistoryWithMarshallingGateway() throws Exception { MessageContext context = new DefaultMessageContext(new StubMessageFactory()); Unmarshaller unmarshaller = mock(Unmarshaller.class); - when(unmarshaller.unmarshal((Source) Mockito.any())).thenReturn("hello"); + when(unmarshaller.unmarshal(Mockito.any())).thenReturn("hello"); marshallingGateway.setUnmarshaller(unmarshaller); marshallingGateway.invoke(context); Message message = requestsMarshalling.receive(100); @@ -188,7 +174,7 @@ public class WebServiceInboundGatewayParserTests { private SoapHeaderMapper testHeaderMapper; @Test - public void testHeaderMapperReference() throws Exception { + public void testHeaderMapperReference() { DirectFieldAccessor accessor = new DirectFieldAccessor(headerMappingGateway); Object headerMapper = accessor.getPropertyValue("headerMapper"); assertEquals(testHeaderMapper, headerMapper); @@ -199,7 +185,7 @@ public class WebServiceInboundGatewayParserTests { private SimpleWebServiceInboundGateway replyTimeoutGateway; @Test - public void testReplyTimeout() throws Exception { + public void testReplyTimeout() { DirectFieldAccessor accessor = new DirectFieldAccessor(replyTimeoutGateway); Object replyTimeout = accessor.getPropertyValue("replyTimeout"); assertEquals(1234L, replyTimeout); @@ -227,6 +213,7 @@ public class WebServiceInboundGatewayParserTests { public Map toHeadersFromReply(SoapMessage source) { return Collections.emptyMap(); } + } }