diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/AbstractGatewayAdapter.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/AbstractGatewayAdapter.java new file mode 100644 index 0000000000..22d4e07e78 --- /dev/null +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/AbstractGatewayAdapter.java @@ -0,0 +1,55 @@ +/* + * 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; + +import org.springframework.integration.channel.MessageChannel; +import org.springframework.integration.gateway.SimpleMessagingGateway; +import org.springframework.integration.handler.MessageHandler; +import org.springframework.integration.message.Message; + +/** + * Base class for gateway adapters. + * + * @author Mark Fisher + */ +public abstract class AbstractGatewayAdapter extends SimpleMessagingGateway implements MessageHandler { + + private volatile boolean expectReply = true; + + + public AbstractGatewayAdapter(MessageChannel requestChannel) { + super(requestChannel); + } + + + /** + * Specify whether the gateway should be expected to return a reply. + * The default is 'true'. + */ + public void setExpectReply(boolean expectReply) { + this.expectReply = expectReply; + } + + public Message handle(Message message) { + if (this.expectReply) { + return this.sendAndReceiveMessage(message); + } + this.send(message); + return null; + } + +} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/MessageHandlingSourceAdapter.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/MessageHandlingSourceAdapter.java deleted file mode 100644 index 168adfd500..0000000000 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/MessageHandlingSourceAdapter.java +++ /dev/null @@ -1,119 +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; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.springframework.beans.factory.InitializingBean; -import org.springframework.integration.ConfigurationException; -import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.gateway.RequestReplyTemplate; -import org.springframework.integration.handler.MessageHandler; -import org.springframework.integration.message.Message; -import org.springframework.util.Assert; - -/** - * A source adapter that implements the {@link MessageHandler} interface. It may - * be used as a base class for source adapters with request-reply behavior. - * - * @author Mark Fisher - */ -public class MessageHandlingSourceAdapter implements MessageHandler, InitializingBean { - - private final Log logger = LogFactory.getLog(this.getClass()); - - private final MessageChannel requestChannel; - - private final RequestReplyTemplate requestReplyTemplate = new RequestReplyTemplate(); - - private volatile boolean expectReply = true; - - protected final Object lifecycleMonitor = new Object(); - - private volatile boolean initialized; - - - /** - * Create an adapter that sends to the provided channel. - * - * @param requestChannel the channel where messages will be sent, must not be - * null. - */ - public MessageHandlingSourceAdapter(MessageChannel requestChannel) { - Assert.notNull(requestChannel, "request channel must not be null"); - this.requestChannel = requestChannel; - this.requestReplyTemplate.setRequestChannel(requestChannel); - } - - - /** - * Specify whether the handle method should be expected to return a reply. - * The default is 'true'. - */ - public void setExpectReply(boolean expectReply) { - this.expectReply = expectReply; - } - - public void setRequestTimeout(long requestTimeout) { - this.requestReplyTemplate.setRequestTimeout(requestTimeout); - } - - public void setReplyTimeout(long replyTimeout) { - this.requestReplyTemplate.setReplyTimeout(replyTimeout); - } - - protected MessageChannel getChannel() { - return this.requestChannel; - } - - public final void afterPropertiesSet() throws Exception { - synchronized (this.lifecycleMonitor) { - if (this.initialized) { - return; - } - } - this.initialize(); - this.initialized = true; - } - - /** - * Subclasses may override this method for initialization. - */ - protected void initialize() throws Exception { - } - - public final Message handle(Message message) { - if (!this.initialized) { - try { - this.afterPropertiesSet(); - } - catch (Exception e) { - throw new ConfigurationException("unable to initialize " + this.getClass().getName(), e); - } - } - if (!this.expectReply) { - boolean sent = this.requestReplyTemplate.send(message); - if (!sent && logger.isWarnEnabled()) { - logger.warn("failed to send message to channel within timeout"); - } - return null; - } - return this.requestReplyTemplate.request(message); - } - -} diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/AbstractRequestReplySourceAdapterParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/AbstractGatewayParser.java similarity index 72% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/AbstractRequestReplySourceAdapterParser.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/AbstractGatewayParser.java index df122c7437..5960c65304 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/AbstractRequestReplySourceAdapterParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/AbstractGatewayParser.java @@ -27,11 +27,11 @@ import org.springframework.integration.ConfigurationException; import org.springframework.util.StringUtils; /** - * Base class for request-reply source adapter parsers. + * Base class for gateway parsers. * * @author Mark Fisher */ -public abstract class AbstractRequestReplySourceAdapterParser extends AbstractSimpleBeanDefinitionParser { +public abstract class AbstractGatewayParser extends AbstractSimpleBeanDefinitionParser { protected abstract Class getBeanClass(Element element); @@ -50,24 +50,20 @@ public abstract class AbstractRequestReplySourceAdapterParser extends AbstractSi @Override protected boolean isEligibleAttribute(String attributeName) { - return !attributeName.equals("name") && !attributeName.equals("request-channel") && super.isEligibleAttribute(attributeName); + return !attributeName.equals("name") && !attributeName.equals("request-channel") + && !attributeName.equals("reply-channel") && super.isEligibleAttribute(attributeName); } @Override protected void postProcess(BeanDefinitionBuilder builder, Element element) { - String channelRef = element.getAttribute("request-channel"); - if (!StringUtils.hasText(channelRef)) { + String requestChannelRef = element.getAttribute("request-channel"); + if (!StringUtils.hasText(requestChannelRef)) { throw new ConfigurationException("a 'request-channel' reference is required"); } - builder.addConstructorArgReference(channelRef); - builder.addPropertyValue("expectReply", element.getAttribute("expect-reply").equals("true")); - String requestTimeout = element.getAttribute("request-timeout"); - if (StringUtils.hasText(requestTimeout)) { - builder.addPropertyValue("requestTimeout", Long.parseLong(requestTimeout)); - } - String replyTimeout = element.getAttribute("reply-timeout"); - if (StringUtils.hasText(replyTimeout)) { - builder.addPropertyValue("replyTimeout", Long.parseLong(replyTimeout)); + builder.addConstructorArgReference(requestChannelRef); + String replyChannel = element.getAttribute("reply-channel"); + if (StringUtils.hasText(replyChannel)) { + builder.addPropertyReference("replyChannel", replyChannel); } this.doPostProcess(builder, element); } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd index f1e7b8ab7b..2376d965f4 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/config/spring-integration-adapters-1.0.xsd @@ -153,11 +153,11 @@ - + - Defines an rmi-based source channel adapter. + Defines an RMI-based gateway adapter. @@ -185,10 +185,10 @@ - + - Defines an httpinvoker-based source channel adapter. + Defines an httpinvoker-based gateway adapter. diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerSourceAdapter.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerGateway.java similarity index 72% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerSourceAdapter.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerGateway.java index 6f9ee8bbf4..13928d97e1 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerSourceAdapter.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerGateway.java @@ -22,7 +22,8 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.springframework.integration.adapter.MessageHandlingSourceAdapter; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.integration.adapter.AbstractGatewayAdapter; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.handler.MessageHandler; import org.springframework.integration.message.MessagingException; @@ -30,46 +31,46 @@ import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter; import org.springframework.web.HttpRequestHandler; /** - * A source channel adapter for HttpInvoker-based remoting. Since this class implements + * A gateway adapter for HttpInvoker-based remoting. Since this class implements * {@link HttpRequestHandler}, it can be configured with a delegating Servlet where the * servlet-name matches this adapter's bean name. For example, the following servlet can * be defined in web.xml: * *
  * <servlet>
- *     <servlet-name>httpInvokerSourceAdapter</servlet-name>
+ *     <servlet-name>httpInvokerGateway</servlet-name>
  *     <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
  * </servlet>
  * 
* * And, this would match the following bean definition in the application context loaded - * by a {@link org.springframework.web.contextContextLoaderListener}: + * by a {@link org.springframework.web.context.ContextLoaderListener}: * *
- * <bean id="httpInvokerSourceAdapter" class="org.springframework.integration.adapter.httpinvoker.HttpInvokerSourceAdapter">
- *     <constructor-arg ref="exampleChannel"/>
+ * <bean id="httpInvokerGateway" class="org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway">
+ *     <constructor-arg ref="requestChannel"/>
  * </bean>
  * 
* *

* Alternatively, in a Spring MVC application, the DispatcherServlet can delegate to the - * "httpInvokerSourceAdapter" bean based on a handler mapping configuration. In that case, + * "httpInvokerGateway" bean based on a handler mapping configuration. In that case, * the HttpRequestHandlerServlet would not be necessary. *

* * @author Mark Fisher */ -public class HttpInvokerSourceAdapter extends MessageHandlingSourceAdapter implements HttpRequestHandler { +public class HttpInvokerGateway extends AbstractGatewayAdapter implements HttpRequestHandler, InitializingBean { private volatile HttpInvokerServiceExporter exporter; - public HttpInvokerSourceAdapter(MessageChannel channel) { - super(channel); + public HttpInvokerGateway(MessageChannel requestChannel) { + super(requestChannel); } - public void initialize() { + public void afterPropertiesSet() { HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter(); exporter.setService(this); exporter.setServiceInterface(MessageHandler.class); @@ -77,8 +78,7 @@ public class HttpInvokerSourceAdapter extends MessageHandlingSourceAdapter imple this.exporter = exporter; } - public void handleRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (this.exporter == null) { throw new MessagingException("adapter has not been initialized"); } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerSourceAdapterParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerGatewayParser.java similarity index 74% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerSourceAdapterParser.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerGatewayParser.java index 5455ee2d7f..bbb8ba945b 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerSourceAdapterParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerGatewayParser.java @@ -18,19 +18,19 @@ package org.springframework.integration.adapter.httpinvoker.config; import org.w3c.dom.Element; -import org.springframework.integration.adapter.config.AbstractRequestReplySourceAdapterParser; -import org.springframework.integration.adapter.httpinvoker.HttpInvokerSourceAdapter; +import org.springframework.integration.adapter.config.AbstractGatewayParser; +import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway; /** - * Parser for the <httpinvoker-source/> element. + * Parser for the <httpinvoker-gateway/> element. * * @author Mark Fisher */ -public class HttpInvokerSourceAdapterParser extends AbstractRequestReplySourceAdapterParser { +public class HttpInvokerGatewayParser extends AbstractGatewayParser { @Override protected Class getBeanClass(Element element) { - return HttpInvokerSourceAdapter.class; + return HttpInvokerGateway.class; } } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/RmiSourceAdapter.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/RmiGateway.java similarity index 65% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/RmiSourceAdapter.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/RmiGateway.java index a80da96682..3dd77d6002 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/RmiSourceAdapter.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/RmiGateway.java @@ -19,23 +19,27 @@ package org.springframework.integration.adapter.rmi; import java.rmi.RemoteException; import java.rmi.registry.Registry; -import org.springframework.integration.ConfigurationException; -import org.springframework.integration.adapter.MessageHandlingSourceAdapter; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.integration.adapter.AbstractGatewayAdapter; import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.handler.MessageHandler; import org.springframework.remoting.rmi.RmiServiceExporter; import org.springframework.remoting.support.RemoteInvocationExecutor; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** - * A source channel adapter for RMI-based remoting. + * A gateway adapter for RMI-based remoting. * * @author Mark Fisher */ -public class RmiSourceAdapter extends MessageHandlingSourceAdapter { +public class RmiGateway extends AbstractGatewayAdapter implements InitializingBean, MessageHandler { - public static final String SERVICE_NAME_PREFIX = "internal.rmiSourceAdapter."; + public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway."; + private final String requestChannelName; + private volatile String registryHost; private volatile int registryPort = Registry.REGISTRY_PORT; @@ -43,8 +47,16 @@ public class RmiSourceAdapter extends MessageHandlingSourceAdapter { private volatile RemoteInvocationExecutor remoteInvocationExecutor; - public RmiSourceAdapter(MessageChannel channel) { - super(channel); + /** + * Create an RmiGateway that sends to the provided request channel. + * + * @param requestChannel the channel where messages will be sent, must not be + * null. + */ + public RmiGateway(MessageChannel requestChannel) { + super(requestChannel); + this.requestChannelName = requestChannel.getName(); + Assert.isTrue(StringUtils.hasText(this.requestChannelName), "RmiGateway's request channel must have a name."); } @@ -60,11 +72,7 @@ public class RmiSourceAdapter extends MessageHandlingSourceAdapter { this.remoteInvocationExecutor = remoteInvocationExecutor; } - public void initialize() throws RemoteException { - String channelName = this.getChannel().getName(); - if (channelName == null) { - throw new ConfigurationException("RmiSourceAdapter's MessageChannel must have a 'name'"); - } + public void afterPropertiesSet() throws RemoteException { RmiServiceExporter exporter = new RmiServiceExporter(); if (this.registryHost != null) { exporter.setRegistryHost(this.registryHost); @@ -75,7 +83,7 @@ public class RmiSourceAdapter extends MessageHandlingSourceAdapter { } exporter.setService(this); exporter.setServiceInterface(MessageHandler.class); - exporter.setServiceName(SERVICE_NAME_PREFIX + channelName); + exporter.setServiceName(SERVICE_NAME_PREFIX + this.requestChannelName); exporter.afterPropertiesSet(); } diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiGatewayParser.java similarity index 82% rename from org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java rename to org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiGatewayParser.java index fc59f283fc..e8dddb34b2 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiGatewayParser.java @@ -19,23 +19,23 @@ 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.AbstractRequestReplySourceAdapterParser; -import org.springframework.integration.adapter.rmi.RmiSourceAdapter; +import org.springframework.integration.adapter.config.AbstractGatewayParser; +import org.springframework.integration.adapter.rmi.RmiGateway; import org.springframework.util.StringUtils; /** - * Parser for the <rmi-source/> element. + * Parser for the <rmi-gateway/> element. * * @author Mark Fisher */ -public class RmiSourceAdapterParser extends AbstractRequestReplySourceAdapterParser { +public class RmiGatewayParser extends AbstractGatewayParser { private static final String REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE = "remote-invocation-executor"; @Override protected Class getBeanClass(Element element) { - return RmiSourceAdapter.class; + return RmiGateway.class; } @Override diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParser.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParser.java index 829c068e11..b6ea596f55 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParser.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParser.java @@ -24,7 +24,7 @@ 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.RmiSourceAdapter; +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; @@ -60,7 +60,7 @@ public class RmiTargetAdapterParser extends AbstractSingleBeanDefinitionParser { } String portAttribute = element.getAttribute("port"); String port = StringUtils.hasText(portAttribute) ? portAttribute : "1099"; - String url = "rmi://" + host + ":" + port + "/" + RmiSourceAdapter.SERVICE_NAME_PREFIX + remoteChannel; + 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)); diff --git a/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers b/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers index 5074158088..2429ef39fe 100644 --- a/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers +++ b/org.springframework.integration.adapter/src/main/resources/META-INF/spring-integration.parsers @@ -3,11 +3,11 @@ console-target=org.springframework.integration.adapter.stream.config.ConsoleTarg 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-source=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerSourceAdapterParser +httpinvoker-gateway=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerGatewayParser httpinvoker-target=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerTargetAdapterParser 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-source=org.springframework.integration.adapter.rmi.config.RmiSourceAdapterParser +rmi-gateway=org.springframework.integration.adapter.rmi.config.RmiGatewayParser rmi-target=org.springframework.integration.adapter.rmi.config.RmiTargetAdapterParser \ No newline at end of file diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerSourceAdapterTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerGatewayTests.java similarity index 88% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerSourceAdapterTests.java rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerGatewayTests.java index 84b6d4c8b2..d0b0b1e5df 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerSourceAdapterTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/HttpInvokerGatewayTests.java @@ -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()); } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerSourceAdapterParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerGatewayParserTests.java similarity index 75% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerSourceAdapterParserTests.java rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerGatewayParserTests.java index 6ba862fdd7..7e01c59c5e 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerSourceAdapterParserTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/HttpInvokerGatewayParserTests.java @@ -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")); } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/httpInvokerSourceAdapterParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/httpInvokerGatewayParserTests.xml similarity index 77% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/httpInvokerSourceAdapterParserTests.xml rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/httpInvokerGatewayParserTests.xml index 8b6234a560..e30478d248 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/httpInvokerSourceAdapterParserTests.xml +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/httpinvoker/config/httpInvokerGatewayParserTests.xml @@ -11,11 +11,11 @@ - + - + - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiGatewayParserTests.java similarity index 69% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiGatewayParserTests.java index b516079218..d54db91e74 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiSourceAdapterParserTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiGatewayParserTests.java @@ -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()); diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java index 7cd7aa27f0..33b43af377 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/RmiTargetAdapterParserTests.java @@ -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 diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/rmiGatewayParserTests.xml similarity index 62% rename from org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml rename to org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/rmiGatewayParserTests.xml index 9e52cc2d9b..cdb9308f7b 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/rmiSourceAdapterParserTests.xml +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/rmi/config/rmiGatewayParserTests.xml @@ -11,16 +11,16 @@ - + - - + - + - +