Renamed RmiHandler to RmiOutboundGateway and RmiGateway to RmiInboundGateway.
This commit is contained in:
@@ -28,11 +28,11 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A gateway adapter for RMI-based remoting.
|
||||
* An inbound Messaging Gateway for RMI-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGateway extends RemotingInboundGatewaySupport implements MessageHandler {
|
||||
public class RmiInboundGateway extends RemotingInboundGatewaySupport {
|
||||
|
||||
public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway.";
|
||||
|
||||
@@ -21,13 +21,13 @@ import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
|
||||
|
||||
/**
|
||||
* A MessageHandler adapter for RMI-based remoting.
|
||||
* An outbound Messaging Gateway for RMI-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandler extends AbstractRemotingOutboundGateway {
|
||||
public class RmiOutboundGateway extends AbstractRemotingOutboundGateway {
|
||||
|
||||
public RmiHandler(String url) {
|
||||
public RmiOutboundGateway(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@@ -20,22 +20,22 @@ import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
|
||||
import org.springframework.integration.rmi.RmiGateway;
|
||||
import org.springframework.integration.rmi.RmiInboundGateway;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <rmi-gateway/> element.
|
||||
* Parser for the <inbound-gateway/> element of the 'rmi' namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGatewayParser extends AbstractRemotingGatewayParser {
|
||||
public class RmiInboundGatewayParser extends AbstractRemotingGatewayParser {
|
||||
|
||||
private static final String REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE = "remote-invocation-executor";
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return RmiGateway.class;
|
||||
return RmiInboundGateway.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,8 +26,8 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
public class RmiNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
this.registerBeanDefinitionParser("inbound-gateway", new RmiGatewayParser());
|
||||
this.registerBeanDefinitionParser("outbound-gateway", new RmiHandlerParser());
|
||||
this.registerBeanDefinitionParser("inbound-gateway", new RmiInboundGatewayParser());
|
||||
this.registerBeanDefinitionParser("outbound-gateway", new RmiOutboundGatewayParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.w3c.dom.Element;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
|
||||
import org.springframework.integration.rmi.RmiGateway;
|
||||
import org.springframework.integration.rmi.RmiHandler;
|
||||
import org.springframework.integration.rmi.RmiInboundGateway;
|
||||
import org.springframework.integration.rmi.RmiOutboundGateway;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -32,11 +32,11 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerParser extends AbstractRemotingOutboundGatewayParser {
|
||||
public class RmiOutboundGatewayParser extends AbstractRemotingOutboundGatewayParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return RmiHandler.class;
|
||||
return RmiOutboundGateway.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,7 +56,7 @@ public class RmiHandlerParser extends AbstractRemotingOutboundGatewayParser {
|
||||
}
|
||||
String portAttribute = element.getAttribute("port");
|
||||
String port = StringUtils.hasText(portAttribute) ? portAttribute : "" + Registry.REGISTRY_PORT;
|
||||
String url = "rmi://" + host + ":" + port + "/" + RmiGateway.SERVICE_NAME_PREFIX + remoteChannel;
|
||||
String url = "rmi://" + host + ":" + port + "/" + RmiInboundGateway.SERVICE_NAME_PREFIX + remoteChannel;
|
||||
builder.addConstructorArgValue(url);
|
||||
}
|
||||
|
||||
@@ -31,16 +31,16 @@ import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.rmi.RmiHandler;
|
||||
import org.springframework.integration.rmi.RmiOutboundGateway;
|
||||
import org.springframework.remoting.RemoteLookupFailureException;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerTests {
|
||||
public class RmiOutboundGatewayTests {
|
||||
|
||||
private final RmiHandler handler = new RmiHandler("rmi://localhost:1099/testRemoteHandler");
|
||||
private final RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/testRemoteHandler");
|
||||
|
||||
|
||||
@Before
|
||||
@@ -54,41 +54,41 @@ public class RmiHandlerTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerializablePayload() throws RemoteException {
|
||||
Message<?> replyMessage = handler.handle(new StringMessage("test"));
|
||||
public void serializablePayload() throws RemoteException {
|
||||
Message<?> replyMessage = gateway.handle(new StringMessage("test"));
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals("TEST", replyMessage.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializableAttribute() throws RemoteException {
|
||||
public void serializableAttribute() throws RemoteException {
|
||||
Message<String> requestMessage = MessageBuilder.withPayload("test")
|
||||
.setHeader("testAttribute", "foo").build();
|
||||
Message<?> replyMessage = handler.handle(requestMessage);
|
||||
Message<?> replyMessage = gateway.handle(requestMessage);
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals("foo", replyMessage.getHeaders().get("testAttribute"));
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void testNonSerializablePayload() throws RemoteException {
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void nonSerializablePayload() throws RemoteException {
|
||||
NonSerializableTestObject payload = new NonSerializableTestObject();
|
||||
Message<?> requestMessage = new GenericMessage<NonSerializableTestObject>(payload);
|
||||
handler.handle(requestMessage);
|
||||
gateway.handle(requestMessage);
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void testNonSerializableAttribute() throws RemoteException {
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void nonSerializableAttribute() throws RemoteException {
|
||||
Message<String> requestMessage = MessageBuilder.withPayload("test")
|
||||
.setHeader("testAttribute", new NonSerializableTestObject()).build();
|
||||
handler.handle(requestMessage);
|
||||
gateway.handle(requestMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidServiceName() throws RemoteException {
|
||||
RmiHandler handler = new RmiHandler("rmi://localhost:1099/noSuchService");
|
||||
public void invalidServiceName() throws RemoteException {
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/noSuchService");
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
handler.handle(new StringMessage("test"));
|
||||
gateway.handle(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
|
||||
@@ -98,11 +98,11 @@ public class RmiHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidHost() {
|
||||
RmiHandler handler = new RmiHandler("rmi://noSuchHost:1099/testRemoteHandler");
|
||||
public void invalidHost() {
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://noSuchHost:1099/testRemoteHandler");
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
handler.handle(new StringMessage("test"));
|
||||
gateway.handle(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
|
||||
@@ -112,11 +112,11 @@ public class RmiHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidUrl() throws RemoteException {
|
||||
RmiHandler handler = new RmiHandler("invalid");
|
||||
public void invalidUrl() throws RemoteException {
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("invalid");
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
handler.handle(new StringMessage("test"));
|
||||
gateway.handle(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
|
||||
@@ -26,19 +26,19 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.MessageChannelTemplate;
|
||||
import org.springframework.integration.rmi.RmiGateway;
|
||||
import org.springframework.integration.rmi.RmiInboundGateway;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGatewayParserTests {
|
||||
public class RmiInboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithDefaults() {
|
||||
public void gatewayWithDefaults() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
"rmiInboundGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithDefaults");
|
||||
RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithDefaults");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
@@ -50,11 +50,11 @@ public class RmiGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithCustomProperties() {
|
||||
public void gatewayWithCustomProperties() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
"rmiInboundGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithCustomProperties");
|
||||
RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithCustomProperties");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(false, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
@@ -66,28 +66,28 @@ public class RmiGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithHost() {
|
||||
public void gatewayWithHost() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithHost");
|
||||
"rmiInboundGatewayParserTests.xml", this.getClass());
|
||||
RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithHost");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals("localhost", accessor.getPropertyValue("registryHost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithPort() {
|
||||
public void gatewayWithPort() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithPort");
|
||||
"rmiInboundGatewayParserTests.xml", this.getClass());
|
||||
RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithPort");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(1234, accessor.getPropertyValue("registryPort"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithRemoteInvocationExecutorReference() {
|
||||
public void gatewayWithRemoteInvocationExecutorReference() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithExecutorRef");
|
||||
"rmiInboundGatewayParserTests.xml", this.getClass());
|
||||
RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithExecutorRef");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
Object remoteInvocationExecutor = accessor.getPropertyValue("remoteInvocationExecutor");
|
||||
assertNotNull(remoteInvocationExecutor);
|
||||
@@ -28,39 +28,42 @@ import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.rmi.RmiGateway;
|
||||
import org.springframework.integration.rmi.RmiHandler;
|
||||
import org.springframework.integration.rmi.RmiInboundGateway;
|
||||
import org.springframework.integration.rmi.RmiOutboundGateway;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerParserTests {
|
||||
public class RmiOutboundGatewayParserTests {
|
||||
|
||||
private final QueueChannel testChannel = new QueueChannel();
|
||||
|
||||
|
||||
@Before
|
||||
public void exportRemoteHandler() throws Exception {
|
||||
public void setupTestInboundGateway() throws Exception {
|
||||
testChannel.setBeanName("testChannel");
|
||||
RmiGateway gateway = new RmiGateway();
|
||||
RmiInboundGateway gateway = new RmiInboundGateway();
|
||||
gateway.setRequestChannel(testChannel);
|
||||
gateway.setExpectReply(false);
|
||||
gateway.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRmiHandlerDirectly() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("rmiHandlerParserTests.xml", this.getClass());
|
||||
RmiHandler handler = (RmiHandler) context.getBean("gateway");
|
||||
handler.handle(new StringMessage("test"));
|
||||
public void directInvocation() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiOutboundGatewayParserTests.xml", this.getClass());
|
||||
RmiOutboundGateway gateway = (RmiOutboundGateway) context.getBean("gateway");
|
||||
gateway.handle(new StringMessage("test"));
|
||||
Message<?> result = testChannel.receive(1000);
|
||||
assertNotNull(result);
|
||||
assertEquals("test", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRmiHandlerWithEndpoint() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("rmiHandlerParserTests.xml", this.getClass());
|
||||
public void endpointInvocation() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiOutboundGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel localChannel = (MessageChannel) context.getBean("localChannel");
|
||||
localChannel.send(new StringMessage("test"));
|
||||
Message<?> result = testChannel.receive(1000);
|
||||
Reference in New Issue
Block a user