Migrated RMI adapter and parser code from "org.springframework.integration.adapter" to the new "org.springframework.integration.rmi" module, and added a dedicated spring-integration-rmi-1.0.xsd schema and RmiNamespaceHandler.
This commit is contained in:
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.adapter.rmi;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
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.remoting.RemoteLookupFailureException;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerTests {
|
||||
|
||||
private final RmiHandler handler = new RmiHandler("rmi://localhost:1099/testRemoteHandler");
|
||||
|
||||
|
||||
@Before
|
||||
public void createExporter() throws RemoteException {
|
||||
RmiServiceExporter exporter = new RmiServiceExporter();
|
||||
exporter.setService(new TestHandler());
|
||||
exporter.setServiceInterface(MessageHandler.class);
|
||||
exporter.setServiceName("testRemoteHandler");
|
||||
exporter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerializablePayload() throws RemoteException {
|
||||
Message<?> replyMessage = handler.handle(new StringMessage("test"));
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals("TEST", replyMessage.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializableAttribute() throws RemoteException {
|
||||
Message<String> requestMessage = MessageBuilder.withPayload("test")
|
||||
.setHeader("testAttribute", "foo").build();
|
||||
Message<?> replyMessage = handler.handle(requestMessage);
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals("foo", replyMessage.getHeaders().get("testAttribute"));
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void testNonSerializablePayload() throws RemoteException {
|
||||
NonSerializableTestObject payload = new NonSerializableTestObject();
|
||||
Message<?> requestMessage = new GenericMessage<NonSerializableTestObject>(payload);
|
||||
handler.handle(requestMessage);
|
||||
}
|
||||
|
||||
@Test(expected=MessageHandlingException.class)
|
||||
public void testNonSerializableAttribute() throws RemoteException {
|
||||
Message<String> requestMessage = MessageBuilder.withPayload("test")
|
||||
.setHeader("testAttribute", new NonSerializableTestObject()).build();
|
||||
handler.handle(requestMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidServiceName() throws RemoteException {
|
||||
RmiHandler handler = new RmiHandler("rmi://localhost:1099/noSuchService");
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
handler.handle(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assertTrue(exceptionThrown);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidHost() {
|
||||
RmiHandler handler = new RmiHandler("rmi://noSuchHost:1099/testRemoteHandler");
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
handler.handle(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assertTrue(exceptionThrown);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidUrl() throws RemoteException {
|
||||
RmiHandler handler = new RmiHandler("invalid");
|
||||
boolean exceptionThrown = false;
|
||||
try {
|
||||
handler.handle(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
|
||||
exceptionThrown = true;
|
||||
}
|
||||
assertTrue(exceptionThrown);
|
||||
}
|
||||
|
||||
|
||||
private static class TestHandler implements MessageHandler {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
return new GenericMessage<String>(message.getPayload().toString().toUpperCase(), message.getHeaders());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class NonSerializableTestObject {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.adapter.rmi.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.rmi.RmiGateway;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.MessageChannelTemplate;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithDefaults() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithDefaults");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
MessageChannelTemplate template = (MessageChannelTemplate)
|
||||
accessor.getPropertyValue("channelTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("sendTimeout"));
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("receiveTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithCustomProperties() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithCustomProperties");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(false, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
MessageChannelTemplate template = (MessageChannelTemplate)
|
||||
accessor.getPropertyValue("channelTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(123L, templateAccessor.getPropertyValue("sendTimeout"));
|
||||
assertEquals(456L, templateAccessor.getPropertyValue("receiveTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithHost() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithHost");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals("localhost", accessor.getPropertyValue("registryHost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithPort() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithPort");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(1234, accessor.getPropertyValue("registryPort"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithRemoteInvocationExecutorReference() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"rmiGatewayParserTests.xml", this.getClass());
|
||||
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithExecutorRef");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
Object remoteInvocationExecutor = accessor.getPropertyValue("remoteInvocationExecutor");
|
||||
assertNotNull(remoteInvocationExecutor);
|
||||
assertEquals(StubRemoteInvocationExecutor.class, remoteInvocationExecutor.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.adapter.rmi.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.rmi.RmiGateway;
|
||||
import org.springframework.integration.adapter.rmi.RmiHandler;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerParserTests {
|
||||
|
||||
private final QueueChannel testChannel = new QueueChannel();
|
||||
|
||||
|
||||
@Before
|
||||
public void exportRemoteHandler() throws Exception {
|
||||
testChannel.setBeanName("testChannel");
|
||||
RmiGateway gateway = new RmiGateway(testChannel);
|
||||
gateway.setExpectReply(false);
|
||||
gateway.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRmiHandlerDirectly() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("rmiHandlerParserTests.xml", this.getClass());
|
||||
RmiHandler handler = (RmiHandler) context.getBean("handler");
|
||||
handler.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());
|
||||
MessageChannel localChannel = (MessageChannel) context.getBean("localChannel");
|
||||
localChannel.send(new StringMessage("test"));
|
||||
Message<?> result = testChannel.receive(1000);
|
||||
assertNotNull(result);
|
||||
assertEquals("test", result.getPayload());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.adapter.rmi.config;
|
||||
|
||||
import org.springframework.remoting.support.DefaultRemoteInvocationExecutor;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class StubRemoteInvocationExecutor extends DefaultRemoteInvocationExecutor {
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<rmi-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
|
||||
<rmi-gateway id="gatewayWithCustomProperties" request-channel="testChannel"
|
||||
expect-reply="false" request-timeout="123" reply-timeout="456"/>
|
||||
|
||||
<rmi-gateway id="gatewayWithHost" request-channel="testChannel" registry-host="localhost"/>
|
||||
|
||||
<rmi-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234"/>
|
||||
|
||||
<rmi-gateway id="gatewayWithExecutorRef" request-channel="testChannel" remote-invocation-executor="invocationExecutor"/>
|
||||
|
||||
<beans:bean id="invocationExecutor" class="org.springframework.integration.adapter.rmi.config.StubRemoteInvocationExecutor"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="localChannel"/>
|
||||
|
||||
<service-activator input-channel="localChannel" ref="handler"/>
|
||||
|
||||
<rmi-handler id="handler" remote-channel="testChannel" host="localhost"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user