RmiTargetAdapter is now RmiHandler, and HttpInvokerTargetAdapter is now HttpInvokerHandler since they both enable request-reply behavior. In the spring-integration-adapters namespace, the corresponding XML elements have changed from "rmi-target" and "httpinvoker-target" to "rmi-handler" and "httpinvoker-handler". Rather than creating HandlerEndpoint instances, their parsers now create just the MessageHandler instances. Therefore, the results should be wired as references (via the "handler" attribute) within <handler-endpoint/> elements.

This commit is contained in:
Mark Fisher
2008-05-28 00:03:13 +00:00
parent 8d2368e6a3
commit ccc3e06928
20 changed files with 189 additions and 164 deletions

View File

@@ -17,28 +17,24 @@
package org.springframework.integration.adapter.httpinvoker.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerHandler;
import org.springframework.integration.handler.MessageHandler;
/**
* @author Mark Fisher
*/
public class HttpInvokerTargetAdapterParserTests {
public class HttpInvokerHandlerParserTests {
@Test
public void testHttpInvokerTargetAdapter() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"httpInvokerTargetAdapterParserTests.xml", this.getClass());
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("adapter");
assertNotNull(endpoint);
assertEquals(HttpInvokerTargetAdapter.class, endpoint.getHandler().getClass());
assertEquals("testChannel", endpoint.getSubscription().getChannelName());
public void testHttpInvokerHandlerParser() {
ApplicationContext context = new ClassPathXmlApplicationContext("httpInvokerHandlerParserTests.xml", this.getClass());
MessageHandler handler = (MessageHandler) context.getBean("handler");
assertEquals(HttpInvokerHandler.class, handler.getClass());
}
}

View File

@@ -11,6 +11,6 @@
<channel id="testChannel"/>
<httpinvoker-target id="adapter" channel="testChannel" url="http://localhost:8080/test"/>
<httpinvoker-handler id="handler" url="http://localhost:8080/test"/>
</beans:beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* 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.
@@ -36,9 +36,9 @@ import org.springframework.remoting.rmi.RmiServiceExporter;
/**
* @author Mark Fisher
*/
public class RmiTargetAdapterTests {
public class RmiHandlerTests {
private final RmiTargetAdapter adapter = new RmiTargetAdapter("rmi://localhost:1099/testRemoteHandler");
private final RmiHandler handler = new RmiHandler("rmi://localhost:1099/testRemoteHandler");
@Before
@@ -52,7 +52,7 @@ public class RmiTargetAdapterTests {
@Test
public void testSerializablePayload() throws RemoteException {
Message<?> replyMessage = adapter.handle(new StringMessage("test"));
Message<?> replyMessage = handler.handle(new StringMessage("test"));
assertNotNull(replyMessage);
assertEquals("TEST", replyMessage.getPayload());
}
@@ -61,7 +61,7 @@ public class RmiTargetAdapterTests {
public void testSerializableAttribute() throws RemoteException {
Message<?> requestMessage = new StringMessage("test");
requestMessage.getHeader().setAttribute("testAttribute", "foo");
Message<?> replyMessage = adapter.handle(requestMessage);
Message<?> replyMessage = handler.handle(requestMessage);
assertNotNull(replyMessage);
assertEquals("foo", replyMessage.getHeader().getAttribute("testAttribute"));
}
@@ -70,7 +70,7 @@ public class RmiTargetAdapterTests {
public void testProperty() throws RemoteException {
Message<?> requestMessage = new StringMessage("test");
requestMessage.getHeader().setProperty("testProperty", "bar");
Message<?> replyMessage = adapter.handle(requestMessage);
Message<?> replyMessage = handler.handle(requestMessage);
assertNotNull(replyMessage);
assertEquals("bar", replyMessage.getHeader().getProperty("testProperty"));
}
@@ -79,22 +79,22 @@ public class RmiTargetAdapterTests {
public void testNonSerializablePayload() throws RemoteException {
NonSerializableTestObject payload = new NonSerializableTestObject();
Message<?> requestMessage = new GenericMessage<NonSerializableTestObject>(payload);
adapter.handle(requestMessage);
handler.handle(requestMessage);
}
@Test(expected=MessageHandlingException.class)
public void testNonSerializableAttribute() throws RemoteException {
Message<?> requestMessage = new StringMessage("test");
requestMessage.getHeader().setAttribute("testAttribute", new NonSerializableTestObject());
adapter.handle(requestMessage);
handler.handle(requestMessage);
}
@Test
public void testInvalidServiceName() throws RemoteException {
RmiTargetAdapter adapter = new RmiTargetAdapter("rmi://localhost:1099/noSuchService");
RmiHandler handler = new RmiHandler("rmi://localhost:1099/noSuchService");
boolean exceptionThrown = false;
try {
adapter.handle(new StringMessage("test"));
handler.handle(new StringMessage("test"));
}
catch (MessageHandlingException e) {
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
@@ -105,10 +105,10 @@ public class RmiTargetAdapterTests {
@Test
public void testInvalidHost() {
RmiTargetAdapter adapter = new RmiTargetAdapter("rmi://noSuchHost:1099/testRemoteHandler");
RmiHandler handler = new RmiHandler("rmi://noSuchHost:1099/testRemoteHandler");
boolean exceptionThrown = false;
try {
adapter.handle(new StringMessage("test"));
handler.handle(new StringMessage("test"));
}
catch (MessageHandlingException e) {
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
@@ -119,10 +119,10 @@ public class RmiTargetAdapterTests {
@Test
public void testInvalidUrl() throws RemoteException {
RmiTargetAdapter adapter = new RmiTargetAdapter("invalid");
RmiHandler handler = new RmiHandler("invalid");
boolean exceptionThrown = false;
try {
adapter.handle(new StringMessage("test"));
handler.handle(new StringMessage("test"));
}
catch (MessageHandlingException e) {
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());

View File

@@ -25,15 +25,16 @@ 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.RmiTargetAdapter;
import org.springframework.integration.adapter.rmi.RmiHandler;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
public class RmiTargetAdapterParserTests {
public class RmiHandlerParserTests {
private final QueueChannel testChannel = new QueueChannel();
@@ -47,15 +48,23 @@ public class RmiTargetAdapterParserTests {
}
@Test
public void testRmiTargetAdapter() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"rmiTargetAdapterParserTests.xml", this.getClass());
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("adapter");
assertNotNull(endpoint);
assertEquals(RmiTargetAdapter.class, endpoint.getHandler().getClass());
RmiTargetAdapter adapter = (RmiTargetAdapter) endpoint.getHandler();
adapter.handle(new StringMessage("test"));
assertNotNull(testChannel.receive(500));
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());
}
}

View File

@@ -11,6 +11,8 @@
<channel id="localChannel"/>
<rmi-target id="adapter" local-channel="localChannel" remote-channel="testChannel" host="localhost"/>
<handler-endpoint input-channel="localChannel" handler="handler"/>
<rmi-handler id="handler" remote-channel="testChannel" host="localhost"/>
</beans:beans>