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:
@@ -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 '<code>true</code>'.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
* <code>null</code>.
|
||||
*/
|
||||
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 '<code>true</code>'.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -153,11 +153,11 @@
|
||||
<xsd:attribute name="destination-name" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="rmi-source">
|
||||
<xsd:element name="rmi-gateway">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an rmi-based source channel adapter.
|
||||
Defines an RMI-based gateway adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
@@ -185,10 +185,10 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="httpinvoker-source" type="gatewayType">
|
||||
<xsd:element name="httpinvoker-gateway" type="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an httpinvoker-based source channel adapter.
|
||||
Defines an httpinvoker-based gateway adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
@@ -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:
|
||||
*
|
||||
* <pre class="code">
|
||||
* <servlet>
|
||||
* <servlet-name>httpInvokerSourceAdapter</servlet-name>
|
||||
* <servlet-name>httpInvokerGateway</servlet-name>
|
||||
* <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
|
||||
* </servlet>
|
||||
* </pre>
|
||||
*
|
||||
* 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}:
|
||||
*
|
||||
* <pre class="code">
|
||||
* <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>
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*
|
||||
* @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");
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
* <code>null</code>.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
@@ -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"/>
|
||||
|
||||
@@ -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());
|
||||
@@ -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
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user