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

@@ -26,12 +26,12 @@ import org.springframework.integration.message.Message;
*
* @author Mark Fisher
*/
public abstract class AbstractGatewayAdapter extends SimpleMessagingGateway implements MessageHandler {
public abstract class AbstractRemotingGateway extends SimpleMessagingGateway implements MessageHandler {
private volatile boolean expectReply = true;
public AbstractGatewayAdapter(MessageChannel requestChannel) {
public AbstractRemotingGateway(MessageChannel requestChannel) {
super(requestChannel);
}

View File

@@ -24,16 +24,16 @@ import org.springframework.integration.message.MessageHandlingException;
import org.springframework.remoting.RemoteAccessException;
/**
* A base class for remoting target adapters.
* A base class for remoting {@link MessageHandler} adapters.
*
* @author Mark Fisher
*/
public abstract class AbstractRemotingTargetAdapter implements MessageHandler {
public abstract class AbstractRemotingHandler implements MessageHandler {
private final MessageHandler handlerProxy;
public AbstractRemotingTargetAdapter(String url) {
public AbstractRemotingHandler(String url) {
this.handlerProxy = this.createHandlerProxy(url);
}

View File

@@ -27,14 +27,15 @@ import org.springframework.integration.ConfigurationException;
import org.springframework.util.StringUtils;
/**
* Base class for gateway parsers.
* Base class for remoting gateway parsers.
*
* @author Mark Fisher
*/
public abstract class AbstractGatewayParser extends AbstractSimpleBeanDefinitionParser {
public abstract class AbstractRemotingGatewayParser extends AbstractSimpleBeanDefinitionParser {
protected abstract Class<?> getBeanClass(Element element);
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {

View File

@@ -0,0 +1,60 @@
/*
* 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.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.integration.ConfigurationException;
import org.springframework.util.StringUtils;
/**
* Base class for remoting MessageHandler parsers.
*
* @author Mark Fisher
*/
public abstract class AbstractRemotingHandlerParser extends AbstractSimpleBeanDefinitionParser {
protected abstract Class<?> getBeanClass(Element element);
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !attributeName.equals("url") && super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
String url = element.getAttribute("url");
if (!StringUtils.hasText(url)) {
throw new ConfigurationException("The 'url' attribute is required.");
}
builder.addConstructorArgValue(url);
}
}

View File

@@ -170,17 +170,16 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="rmi-target">
<xsd:element name="rmi-handler">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines an rmi-based target channel adapter.
Defines an RMI-based MessageHandler adapter.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="host" type="xsd:string" use="required"/>
<xsd:attribute name="port" type="xsd:integer"/>
<xsd:attribute name="local-channel" type="xsd:string" use="required"/>
<xsd:attribute name="remote-channel" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
@@ -188,20 +187,19 @@
<xsd:element name="httpinvoker-gateway" type="gatewayType">
<xsd:annotation>
<xsd:documentation>
Defines an httpinvoker-based gateway adapter.
Defines an HttpInvoker-based gateway adapter.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="httpinvoker-target">
<xsd:element name="httpinvoker-handler">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines an httpinvoker-based target channel adapter.
Defines an HttpInvoker-based MessageHandler adapter.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="channel" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:ID"/>
<xsd:attribute name="url" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>

View File

@@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.adapter.AbstractGatewayAdapter;
import org.springframework.integration.adapter.AbstractRemotingGateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.MessagingException;
@@ -60,7 +60,7 @@ import org.springframework.web.HttpRequestHandler;
*
* @author Mark Fisher
*/
public class HttpInvokerGateway extends AbstractGatewayAdapter implements HttpRequestHandler, InitializingBean {
public class HttpInvokerGateway extends AbstractRemotingGateway implements HttpRequestHandler, InitializingBean {
private volatile HttpInvokerServiceExporter exporter;

View File

@@ -16,18 +16,18 @@
package org.springframework.integration.adapter.httpinvoker;
import org.springframework.integration.adapter.AbstractRemotingTargetAdapter;
import org.springframework.integration.adapter.AbstractRemotingHandler;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
/**
* A target channel adapter for HttpInvoker-based remoting.
* A MessageHandler adapter for HttpInvoker-based remoting.
*
* @author Mark Fisher
*/
public class HttpInvokerTargetAdapter extends AbstractRemotingTargetAdapter {
public class HttpInvokerHandler extends AbstractRemotingHandler {
public HttpInvokerTargetAdapter(String url) {
public HttpInvokerHandler(String url) {
super(url);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.integration.adapter.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.integration.adapter.config.AbstractGatewayParser;
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway;
/**
@@ -26,7 +26,7 @@ import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway;
*
* @author Mark Fisher
*/
public class HttpInvokerGatewayParser extends AbstractGatewayParser {
public class HttpInvokerGatewayParser extends AbstractRemotingGatewayParser {
@Override
protected Class<?> getBeanClass(Element element) {

View File

@@ -0,0 +1,36 @@
/*
* 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.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.integration.adapter.config.AbstractRemotingHandlerParser;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerHandler;
/**
* Parser for the &lt;httpinvoker-handler/&gt; element.
*
* @author Mark Fisher
*/
public class HttpInvokerHandlerParser extends AbstractRemotingHandlerParser {
@Override
protected Class<?> getBeanClass(Element element) {
return HttpInvokerHandler.class;
}
}

View File

@@ -1,69 +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.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerTargetAdapter;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.scheduling.Subscription;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;httpinvoker-target/&gt; element.
*
* @author Mark Fisher
*/
public class HttpInvokerTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
protected Class<?> getBeanClass(Element element) {
return HandlerEndpoint.class;
}
protected boolean shouldGenerateId() {
return false;
}
protected boolean shouldGenerateIdAsFallback() {
return true;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
RootBeanDefinition adapterDef = new RootBeanDefinition(HttpInvokerTargetAdapter.class);
String channel = element.getAttribute("channel");
String url = element.getAttribute("url");
if (!StringUtils.hasText(channel)) {
throw new ConfigurationException("The 'channel' attribute is required.");
}
if (!StringUtils.hasText(url)) {
throw new ConfigurationException("The 'url' attribute is required.");
}
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(url);
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
builder.addConstructorArgReference(adapterBeanName);
Subscription subscription = new Subscription(channel);
builder.addPropertyValue("subscription", subscription);
}
}

View File

@@ -20,7 +20,7 @@ import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.adapter.AbstractGatewayAdapter;
import org.springframework.integration.adapter.AbstractRemotingGateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.rmi.RmiServiceExporter;
@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class RmiGateway extends AbstractGatewayAdapter implements InitializingBean, MessageHandler {
public class RmiGateway extends AbstractRemotingGateway implements InitializingBean, MessageHandler {
public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway.";

View File

@@ -16,19 +16,18 @@
package org.springframework.integration.adapter.rmi;
import org.springframework.integration.adapter.AbstractRemotingTargetAdapter;
import org.springframework.integration.adapter.AbstractRemotingHandler;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
/**
* A target channel adapter for RMI-based remoting.
* A MessageHandler adapter for RMI-based remoting.
*
* @author Mark Fisher
*/
public class RmiTargetAdapter extends AbstractRemotingTargetAdapter {
public class RmiHandler extends AbstractRemotingHandler {
public RmiTargetAdapter(String url) {
public RmiHandler(String url) {
super(url);
}

View File

@@ -19,7 +19,7 @@ package org.springframework.integration.adapter.rmi.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.integration.adapter.config.AbstractGatewayParser;
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
import org.springframework.integration.adapter.rmi.RmiGateway;
import org.springframework.util.StringUtils;
@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class RmiGatewayParser extends AbstractGatewayParser {
public class RmiGatewayParser extends AbstractRemotingGatewayParser {
private static final String REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE = "remote-invocation-executor";

View File

@@ -16,57 +16,50 @@
package org.springframework.integration.adapter.rmi.config;
import java.rmi.registry.Registry;
import org.w3c.dom.Element;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.adapter.rmi.RmiGateway;
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.scheduling.Subscription;
import org.springframework.integration.adapter.rmi.RmiHandler;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;rmi-target/&gt; element.
* Parser for the &lt;rmi-handler/&gt; element.
*
* @author Mark Fisher
*/
public class RmiTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
public class RmiHandlerParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return HandlerEndpoint.class;
return RmiHandler.class;
}
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
RootBeanDefinition adapterDef = new RootBeanDefinition(RmiTargetAdapter.class);
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
String host = element.getAttribute("host");
String localChannel = element.getAttribute("local-channel");
String remoteChannel = element.getAttribute("remote-channel");
if (!(StringUtils.hasText(host) && StringUtils.hasText(localChannel) && StringUtils.hasText(remoteChannel))) {
throw new ConfigurationException(
"The 'host', 'local-channel', and 'remote-channel' attributes are all required");
if (!(StringUtils.hasText(host) && StringUtils.hasText(remoteChannel))) {
throw new ConfigurationException("The 'host' and 'remote-channel' attributes are both required");
}
String portAttribute = element.getAttribute("port");
String port = StringUtils.hasText(portAttribute) ? portAttribute : "1099";
String port = StringUtils.hasText(portAttribute) ? portAttribute : "" + Registry.REGISTRY_PORT;
String url = "rmi://" + host + ":" + port + "/" + RmiGateway.SERVICE_NAME_PREFIX + remoteChannel;
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(url);
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
builder.addConstructorArgReference(adapterBeanName);
Subscription subscription = new Subscription(localChannel);
builder.addPropertyValue("subscription", subscription);
builder.addConstructorArgValue(url);
}
}

View File

@@ -4,10 +4,10 @@ file-source=org.springframework.integration.adapter.file.config.FileSourceParser
file-target=org.springframework.integration.adapter.file.config.FileTargetParser
ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
httpinvoker-gateway=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerGatewayParser
httpinvoker-target=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerTargetAdapterParser
httpinvoker-handler=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerHandlerParser
jms-gateway=org.springframework.integration.adapter.jms.config.JmsGatewayParser
jms-source=org.springframework.integration.adapter.jms.config.JmsSourceParser
jms-target=org.springframework.integration.adapter.jms.config.JmsTargetParser
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
rmi-gateway=org.springframework.integration.adapter.rmi.config.RmiGatewayParser
rmi-target=org.springframework.integration.adapter.rmi.config.RmiTargetAdapterParser
rmi-handler=org.springframework.integration.adapter.rmi.config.RmiHandlerParser

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>