RmiSourceAdapter is now RmiGateway, and HttpInvokerSourceAdapter is now HttpInvokerGateway. Also, in the spring-integration-adapters namespace, the XML elements have changed from "rmi-source" and "httpinvoker-source" to "rmi-gateway" and "httpinvoker-gateway".

This commit is contained in:
Mark Fisher
2008-05-27 22:22:53 +00:00
parent 506a8d4f0d
commit 3c5d8f561e
16 changed files with 173 additions and 233 deletions

View File

@@ -41,25 +41,25 @@ import org.springframework.remoting.support.RemoteInvocationResult;
/**
* @author Mark Fisher
*/
public class HttpInvokerSourceAdapterTests {
public class HttpInvokerGatewayTests {
@Test
public void testRequestOnly() throws Exception {
MessageChannel channel = new QueueChannel();
HttpInvokerSourceAdapter adapter = new HttpInvokerSourceAdapter(channel);
adapter.setExpectReply(false);
adapter.afterPropertiesSet();
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
gateway.setExpectReply(false);
gateway.afterPropertiesSet();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setContent(createRequestContent(new StringMessage("test")));
adapter.handleRequest(request, response);
gateway.handleRequest(request, response);
Message<?> message = channel.receive(500);
assertNotNull(message);
assertEquals("test", message.getPayload());
}
@Test
public void testRequestExpectingReply() throws Exception {
public void testRequestReply() throws Exception {
final MessageChannel channel = new QueueChannel();
Executors.newSingleThreadExecutor().execute(new Runnable() {
public void run() {
@@ -68,13 +68,13 @@ public class HttpInvokerSourceAdapterTests {
replyChannel.send(new StringMessage(message.getPayload().toString().toUpperCase()));
}
});
HttpInvokerSourceAdapter adapter = new HttpInvokerSourceAdapter(channel);
adapter.setExpectReply(true);
adapter.afterPropertiesSet();
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
gateway.setExpectReply(true);
gateway.afterPropertiesSet();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setContent(createRequestContent(new StringMessage("test")));
adapter.handleRequest(request, response);
gateway.handleRequest(request, response);
Message<?> reply = extractMessageFromResponse(response);
assertEquals("TEST", reply.getPayload());
}

View File

@@ -23,27 +23,27 @@ 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.httpinvoker.HttpInvokerSourceAdapter;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.gateway.RequestReplyTemplate;
/**
* @author Mark Fisher
*/
public class HttpInvokerSourceAdapterParserTests {
public class HttpInvokerGatewayParserTests {
@Test
public void testAdapterWithDefaults() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"httpInvokerSourceAdapterParserTests.xml", this.getClass());
"httpInvokerGatewayParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
HttpInvokerSourceAdapter adapter = (HttpInvokerSourceAdapter) context.getBean("adapterWithDefaults");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("gatewayWithDefaults");
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
assertEquals(true, accessor.getPropertyValue("expectReply"));
RequestReplyTemplate template = (RequestReplyTemplate)
accessor.getPropertyValue("requestReplyTemplate");
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
assertEquals(channel, templateAccessor.getPropertyValue("requestChannel"));
assertEquals(-1L, templateAccessor.getPropertyValue("requestTimeout"));
assertEquals(-1L, templateAccessor.getPropertyValue("replyTimeout"));
}
@@ -51,15 +51,15 @@ public class HttpInvokerSourceAdapterParserTests {
@Test
public void testAdapterWithName() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"httpInvokerSourceAdapterParserTests.xml", this.getClass());
"httpInvokerGatewayParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
HttpInvokerSourceAdapter adapter = (HttpInvokerSourceAdapter) context.getBean("/adapter/with/name");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("/gateway/with/name");
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
assertEquals(true, accessor.getPropertyValue("expectReply"));
RequestReplyTemplate template = (RequestReplyTemplate)
accessor.getPropertyValue("requestReplyTemplate");
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
assertEquals(channel, templateAccessor.getPropertyValue("requestChannel"));
assertEquals(-1L, templateAccessor.getPropertyValue("requestTimeout"));
assertEquals(-1L, templateAccessor.getPropertyValue("replyTimeout"));
}
@@ -67,15 +67,15 @@ public class HttpInvokerSourceAdapterParserTests {
@Test
public void testAdapterWithCustomProperties() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"httpInvokerSourceAdapterParserTests.xml", this.getClass());
"httpInvokerGatewayParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
HttpInvokerSourceAdapter adapter = (HttpInvokerSourceAdapter) context.getBean("adapterWithCustomProperties");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("gatewayWithCustomProperties");
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
assertEquals(false, accessor.getPropertyValue("expectReply"));
RequestReplyTemplate template = (RequestReplyTemplate)
accessor.getPropertyValue("requestReplyTemplate");
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
assertEquals(channel, templateAccessor.getPropertyValue("requestChannel"));
assertEquals(123L, templateAccessor.getPropertyValue("requestTimeout"));
assertEquals(456L, templateAccessor.getPropertyValue("replyTimeout"));
}

View File

@@ -11,11 +11,11 @@
<channel id="testChannel"/>
<httpinvoker-source id="adapterWithDefaults" request-channel="testChannel"/>
<httpinvoker-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
<httpinvoker-source name="/adapter/with/name" request-channel="testChannel"/>
<httpinvoker-gateway name="/gateway/with/name" request-channel="testChannel"/>
<httpinvoker-source id="adapterWithCustomProperties"
<httpinvoker-gateway id="gatewayWithCustomProperties"
request-channel="testChannel" request-timeout="123"
expect-reply="false" reply-timeout="456"/>

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.
@@ -24,27 +24,27 @@ 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.RmiSourceAdapter;
import org.springframework.integration.adapter.rmi.RmiGateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.gateway.RequestReplyTemplate;
/**
* @author Mark Fisher
*/
public class RmiSourceAdapterParserTests {
public class RmiGatewayParserTests {
@Test
public void testAdapterWithDefaults() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"rmiSourceAdapterParserTests.xml", this.getClass());
"rmiGatewayParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithDefaults");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithDefaults");
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
assertEquals(true, accessor.getPropertyValue("expectReply"));
RequestReplyTemplate template = (RequestReplyTemplate)
accessor.getPropertyValue("requestReplyTemplate");
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
assertEquals(channel, templateAccessor.getPropertyValue("requestChannel"));
assertEquals(-1L, templateAccessor.getPropertyValue("requestTimeout"));
assertEquals(-1L, templateAccessor.getPropertyValue("replyTimeout"));
}
@@ -52,15 +52,15 @@ public class RmiSourceAdapterParserTests {
@Test
public void testAdapterWithCustomProperties() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"rmiSourceAdapterParserTests.xml", this.getClass());
"rmiGatewayParserTests.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithCustomProperties");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
RmiGateway gateway = (RmiGateway) context.getBean("gatewayWithCustomProperties");
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
assertEquals(false, accessor.getPropertyValue("expectReply"));
RequestReplyTemplate template = (RequestReplyTemplate)
accessor.getPropertyValue("requestReplyTemplate");
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
assertEquals(channel, templateAccessor.getPropertyValue("requestChannel"));
assertEquals(123L, templateAccessor.getPropertyValue("requestTimeout"));
assertEquals(456L, templateAccessor.getPropertyValue("replyTimeout"));
}
@@ -68,27 +68,27 @@ public class RmiSourceAdapterParserTests {
@Test
public void testAdapterWithHost() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"rmiSourceAdapterParserTests.xml", this.getClass());
RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithHost");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
"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(
"rmiSourceAdapterParserTests.xml", this.getClass());
RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithPort");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
"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(
"rmiSourceAdapterParserTests.xml", this.getClass());
RmiSourceAdapter adapter = (RmiSourceAdapter) context.getBean("adapterWithExecutorRef");
DirectFieldAccessor accessor = new DirectFieldAccessor(adapter);
"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());

View File

@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.adapter.rmi.RmiSourceAdapter;
import org.springframework.integration.adapter.rmi.RmiGateway;
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.HandlerEndpoint;
@@ -41,9 +41,9 @@ public class RmiTargetAdapterParserTests {
@Before
public void exportRemoteHandler() throws Exception {
testChannel.setBeanName("testChannel");
RmiSourceAdapter sourceAdapter = new RmiSourceAdapter(testChannel);
sourceAdapter.setExpectReply(false);
sourceAdapter.afterPropertiesSet();
RmiGateway gateway = new RmiGateway(testChannel);
gateway.setExpectReply(false);
gateway.afterPropertiesSet();
}
@Test

View File

@@ -11,16 +11,16 @@
<channel id="testChannel"/>
<rmi-source id="adapterWithDefaults" request-channel="testChannel"/>
<rmi-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
<rmi-source id="adapterWithCustomProperties" request-channel="testChannel"
<rmi-gateway id="gatewayWithCustomProperties" request-channel="testChannel"
expect-reply="false" request-timeout="123" reply-timeout="456"/>
<rmi-source id="adapterWithHost" request-channel="testChannel" registry-host="localhost"/>
<rmi-gateway id="gatewayWithHost" request-channel="testChannel" registry-host="localhost"/>
<rmi-source id="adapterWithPort" request-channel="testChannel" registry-port="1234"/>
<rmi-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234"/>
<rmi-source id="adapterWithExecutorRef" request-channel="testChannel" remote-invocation-executor="invocationExecutor"/>
<rmi-gateway id="gatewayWithExecutorRef" request-channel="testChannel" remote-invocation-executor="invocationExecutor"/>
<beans:bean id="invocationExecutor" class="org.springframework.integration.adapter.rmi.config.StubRemoteInvocationExecutor"/>