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
This commit is contained in:
committed by
Gary Russell
parent
ad4dc11758
commit
5a362b62ff
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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 '<code>true</code>'.
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</int:channel>
|
||||
|
||||
<bean id="port" class="java.lang.Integer">
|
||||
<constructor-arg value="#{T(org.springframework.integration.test.util.SocketUtils).findAvailableServerSocket(11099)}" />
|
||||
<constructor-arg value="#{T(org.springframework.integration.test.util.SocketUtils).findAvailableServerSocket()}" />
|
||||
</bean>
|
||||
|
||||
<!-- Bad -->
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:rmi="http://www.springframework.org/schema/integration/rmi"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:rmi="http://www.springframework.org/schema/integration/rmi"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
@@ -16,18 +16,22 @@
|
||||
|
||||
<channel id="testErrorChannel"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
<rmi:inbound-gateway id="gatewayWithDefaults" request-channel="testChannel" auto-startup="false"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithCustomProperties" request-channel="testChannel"
|
||||
expect-reply="false" request-timeout="123" reply-timeout="456"/>
|
||||
expect-reply="false" request-timeout="123" reply-timeout="456" auto-startup="false"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithHostAndErrorChannel" request-channel="testChannel" registry-host="localhost"
|
||||
error-channel="testErrorChannel"/>
|
||||
error-channel="testErrorChannel" auto-startup="false"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234"/>
|
||||
<rmi:inbound-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234" auto-startup="false"/>
|
||||
|
||||
<rmi:inbound-gateway id="gatewayWithExecutorRef" request-channel="testChannel" remote-invocation-executor="invocationExecutor"/>
|
||||
<rmi:inbound-gateway id="gatewayWithExecutorRef"
|
||||
request-channel="testChannel"
|
||||
remote-invocation-executor="invocationExecutor"
|
||||
auto-startup="false"/>
|
||||
|
||||
<beans:bean id="invocationExecutor" class="org.springframework.integration.rmi.config.StubRemoteInvocationExecutor"/>
|
||||
<beans:bean id="invocationExecutor"
|
||||
class="org.springframework.integration.rmi.config.StubRemoteInvocationExecutor"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"/>
|
||||
|
||||
<channel id="advisedChannel"/>
|
||||
|
||||
@@ -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}">
|
||||
<rmi:request-handler-advice-chain>
|
||||
<beans:ref bean="advice" />
|
||||
<beans:ref bean="advice"/>
|
||||
</rmi:request-handler-advice-chain>
|
||||
</rmi:outbound-gateway>
|
||||
|
||||
<beans:bean id="configurer" class="org.mockito.Mockito" factory-method="mock">
|
||||
<beans:constructor-arg
|
||||
value="org.springframework.integration.rmi.RmiOutboundGateway$RmiProxyFactoryBeanConfigurer" />
|
||||
value="org.springframework.integration.rmi.RmiOutboundGateway$RmiProxyFactoryBeanConfigurer"/>
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="advice"
|
||||
class="org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests$FooAdvice" />
|
||||
class="org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests$FooAdvice"/>
|
||||
|
||||
<chain input-channel="rmiOutboundGatewayInsideChain">
|
||||
<rmi:outbound-gateway remote-channel="testChannel" host="localhost" requires-reply="false"/>
|
||||
<rmi:outbound-gateway remote-channel="testChannel"
|
||||
host="localhost"
|
||||
port="#{T(org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests).port}"
|
||||
requires-reply="false"/>
|
||||
</chain>
|
||||
|
||||
|
||||
<channel id="remoteChannel"/>
|
||||
|
||||
<rmi:inbound-gateway request-channel="remoteChannel"/>
|
||||
<rmi:inbound-gateway request-channel="remoteChannel"
|
||||
registry-port="#{T(org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests).port}"/>
|
||||
|
||||
<service-activator input-channel="remoteChannel" expression="payload.toUpperCase()"/>
|
||||
|
||||
@@ -56,7 +62,9 @@
|
||||
</channel>
|
||||
|
||||
<chain input-channel="requestReplyRmiWithChainChannel" output-channel="replyChannel">
|
||||
<rmi:outbound-gateway remote-channel="remoteChannel" host="localhost"/>
|
||||
<rmi:outbound-gateway remote-channel="remoteChannel"
|
||||
host="localhost"
|
||||
port="#{T(org.springframework.integration.rmi.config.RmiOutboundGatewayParserTests).port}"/>
|
||||
</chain>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -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<String>("test"));
|
||||
advisedChannel.send(new GenericMessage<>("test"));
|
||||
Message<?> result = testChannel.receive(1000);
|
||||
assertNotNull(result);
|
||||
assertEquals("test", result.getPayload());
|
||||
|
||||
@@ -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<String, Object> toHeadersFromReply(SoapMessage source) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user