Migrated HttpInvoker adapter and parser code from "org.springframework.integration.adapter" to the new "org.springframework.integration.httpinvoker" module, and added a dedicated spring-integration-httpinvoker-1.0.xsd schema and HttpInvokerNamespaceHandler. Also refactored base and support classes for remoting-based Messaging Gateways (including both HttpInvoker and RMI adapters).
This commit is contained in:
@@ -18,26 +18,36 @@ package org.springframework.integration.adapter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractMessageHandlingEndpoint;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
|
||||
/**
|
||||
* A base class for remoting {@link MessageHandler} adapters.
|
||||
* A base class for outbound Messaging Gateways that use url-based remoting.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRemotingHandler implements MessageHandler {
|
||||
public abstract class AbstractRemotingOutboundGateway extends AbstractMessageHandlingEndpoint {
|
||||
|
||||
private final MessageHandler handlerProxy;
|
||||
|
||||
|
||||
public AbstractRemotingHandler(String url) {
|
||||
public AbstractRemotingOutboundGateway(String url) {
|
||||
this.handlerProxy = this.createHandlerProxy(url);
|
||||
}
|
||||
|
||||
|
||||
public void setRequestChannel(MessageChannel requestChannel) {
|
||||
this.setInputChannel(requestChannel);
|
||||
}
|
||||
|
||||
public void setReplyChannel(MessageChannel replyChannel) {
|
||||
this.setOutputChannel(replyChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must implement this method. It will be invoked from the constructor.
|
||||
*/
|
||||
@@ -16,26 +16,20 @@
|
||||
|
||||
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.
|
||||
* Support class for inbound Messaging Gateways.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRemotingGateway extends SimpleMessagingGateway implements MessageHandler {
|
||||
public abstract class RemotingInboundGatewaySupport extends SimpleMessagingGateway implements MessageHandler {
|
||||
|
||||
private volatile boolean expectReply = true;
|
||||
|
||||
|
||||
public AbstractRemotingGateway(MessageChannel requestChannel) {
|
||||
super(requestChannel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify whether the gateway should be expected to return a reply.
|
||||
* The default is '<code>true</code>'.
|
||||
@@ -56,12 +56,12 @@ public abstract class AbstractRemotingGatewayParser extends AbstractSimpleBeanDe
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
protected final void postProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
String requestChannelRef = element.getAttribute("request-channel");
|
||||
if (!StringUtils.hasText(requestChannelRef)) {
|
||||
throw new ConfigurationException("a 'request-channel' reference is required");
|
||||
}
|
||||
builder.addConstructorArgReference(requestChannelRef);
|
||||
builder.addPropertyReference("requestChannel", requestChannelRef);
|
||||
String replyChannel = element.getAttribute("reply-channel");
|
||||
if (StringUtils.hasText(replyChannel)) {
|
||||
builder.addPropertyReference("replyChannel", replyChannel);
|
||||
|
||||
@@ -19,29 +19,15 @@ package org.springframework.integration.adapter.config;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Base class for remoting MessageHandler parsers.
|
||||
* Base class for url-based remoting outbound gateway parsers.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public abstract class AbstractRemotingHandlerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
protected abstract Class<?> getBeanClass(Element element);
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
public abstract class AbstractRemotingOutboundGatewayParser extends AbstractRemotingGatewayParser {
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
@@ -49,7 +35,7 @@ public abstract class AbstractRemotingHandlerParser extends AbstractSimpleBeanDe
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
protected void doPostProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
String url = element.getAttribute("url");
|
||||
if (!StringUtils.hasText(url)) {
|
||||
throw new ConfigurationException("The 'url' attribute is required.");
|
||||
@@ -65,57 +65,6 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="rmi-gateway">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an RMI-based gateway adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:attribute name="registry-host" type="xsd:string"/>
|
||||
<xsd:attribute name="registry-port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-invocation-executor" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="rmi-handler">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an RMI-based MessageHandler adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="host" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-channel" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="httpinvoker-gateway" type="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an HttpInvoker-based gateway adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="httpinvoker-handler">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an HttpInvoker-based MessageHandler adapter.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="url" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="mail-target">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
@@ -159,21 +108,6 @@
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines common configuration for gateway adapters.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="expect-reply" type="xsd:boolean" default="true"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:simpleType name="fileSourceType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="text"/>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
file-source=org.springframework.integration.adapter.file.config.FileSourceParser
|
||||
file-target=org.springframework.integration.adapter.file.config.FileTargetParser
|
||||
ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
|
||||
httpinvoker-gateway=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerGatewayParser
|
||||
httpinvoker-handler=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerHandlerParser
|
||||
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
|
||||
polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser
|
||||
imap-idle-mail-source=org.springframework.integration.adapter.mail.config.SubscribableImapIdleMailSourceParser
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<httpinvoker-handler id="handler" url="http://localhost:8080/test"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker;
|
||||
package org.springframework.integration.httpinvoker;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -23,15 +23,14 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.adapter.AbstractRemotingGateway;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.adapter.RemotingInboundGatewaySupport;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
|
||||
import org.springframework.web.HttpRequestHandler;
|
||||
|
||||
/**
|
||||
* A gateway adapter for HttpInvoker-based remoting. Since this class implements
|
||||
* An inbound 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:
|
||||
@@ -60,16 +59,11 @@ import org.springframework.web.HttpRequestHandler;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGateway extends AbstractRemotingGateway implements HttpRequestHandler, InitializingBean {
|
||||
public class HttpInvokerInboundGateway extends RemotingInboundGatewaySupport implements HttpRequestHandler, InitializingBean {
|
||||
|
||||
private volatile HttpInvokerServiceExporter exporter;
|
||||
|
||||
|
||||
public HttpInvokerGateway(MessageChannel requestChannel) {
|
||||
super(requestChannel);
|
||||
}
|
||||
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
|
||||
exporter.setService(this);
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker;
|
||||
package org.springframework.integration.httpinvoker;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractRemotingHandler;
|
||||
import org.springframework.integration.adapter.AbstractRemotingOutboundGateway;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
|
||||
|
||||
@@ -25,9 +25,9 @@ import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerHandler extends AbstractRemotingHandler {
|
||||
public class HttpInvokerOutboundGateway extends AbstractRemotingOutboundGateway {
|
||||
|
||||
public HttpInvokerHandler(String url) {
|
||||
public HttpInvokerOutboundGateway(String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@@ -14,23 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker.config;
|
||||
package org.springframework.integration.httpinvoker.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway;
|
||||
import org.springframework.integration.httpinvoker.HttpInvokerInboundGateway;
|
||||
|
||||
/**
|
||||
* Parser for the <httpinvoker-gateway/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGatewayParser extends AbstractRemotingGatewayParser {
|
||||
public class HttpInvokerInboundGatewayParser extends AbstractRemotingGatewayParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HttpInvokerGateway.class;
|
||||
return HttpInvokerInboundGateway.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.httpinvoker.config;
|
||||
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
/**
|
||||
* Namespace handler for Spring Integration's <em>httpinvoker</em> namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
this.registerBeanDefinitionParser("inbound-gateway", new HttpInvokerInboundGatewayParser());
|
||||
this.registerBeanDefinitionParser("outbound-gateway", new HttpInvokerOutboundGatewayParser());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,23 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker.config;
|
||||
package org.springframework.integration.httpinvoker.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingHandlerParser;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerHandler;
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
|
||||
import org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway;
|
||||
|
||||
/**
|
||||
* Parser for the <httpinvoker-handler/> element.
|
||||
* Parser for the <outbound-gateway/> element of the 'httpinvoker' namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerHandlerParser extends AbstractRemotingHandlerParser {
|
||||
public class HttpInvokerOutboundGatewayParser extends AbstractRemotingOutboundGatewayParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HttpInvokerHandler.class;
|
||||
return HttpInvokerOutboundGateway.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/integration/httpinvoker"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
targetNamespace="http://www.springframework.org/schema/integration/httpinvoker"
|
||||
elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines the configuration elements for Spring Integration's HttpInvoker adapters.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="inbound-gateway">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an HttpInvoker-based inbound Messaging Gateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:attribute name="expect-reply" type="xsd:boolean" default="true"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="outbound-gateway">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an HttpInvoker-based outbound Messaging Gateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:attribute name="url" type="xsd:string" use="required"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines common configuration for gateway adapters.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
</xsd:complexType>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -0,0 +1 @@
|
||||
http\://www.springframework.org/schema/integration/httpinvoker=org.springframework.integration.httpinvoker.config.HttpInvokerNamespaceHandler
|
||||
@@ -0,0 +1 @@
|
||||
http\://www.springframework.org/schema/integration/httpinvoker/spring-integration-httpinvoker-1.0.xsd=org/springframework/integration/httpinvoker/config/spring-integration-httpinvoker-1.0.xsd
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker;
|
||||
package org.springframework.integration.httpinvoker;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -31,6 +31,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.httpinvoker.HttpInvokerInboundGateway;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -41,12 +42,13 @@ import org.springframework.remoting.support.RemoteInvocationResult;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGatewayTests {
|
||||
public class HttpInvokerInboundGatewayTests {
|
||||
|
||||
@Test
|
||||
public void testRequestOnly() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
|
||||
HttpInvokerInboundGateway gateway = new HttpInvokerInboundGateway();
|
||||
gateway.setRequestChannel(channel);
|
||||
gateway.setExpectReply(false);
|
||||
gateway.afterPropertiesSet();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -68,7 +70,8 @@ public class HttpInvokerGatewayTests {
|
||||
replyChannel.send(new StringMessage(message.getPayload().toString().toUpperCase()));
|
||||
}
|
||||
});
|
||||
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
|
||||
HttpInvokerInboundGateway gateway = new HttpInvokerInboundGateway();
|
||||
gateway.setRequestChannel(channel);
|
||||
gateway.setExpectReply(true);
|
||||
gateway.afterPropertiesSet();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker.config;
|
||||
package org.springframework.integration.httpinvoker.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -23,21 +23,21 @@ 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.HttpInvokerGateway;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.httpinvoker.HttpInvokerInboundGateway;
|
||||
import org.springframework.integration.message.MessageChannelTemplate;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGatewayParserTests {
|
||||
public class HttpInvokerInboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithDefaults() {
|
||||
public void gatewayWithDefaults() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerGatewayParserTests.xml", this.getClass());
|
||||
"httpInvokerInboundGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("gatewayWithDefaults");
|
||||
HttpInvokerInboundGateway gateway = (HttpInvokerInboundGateway) context.getBean("gatewayWithDefaults");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
@@ -49,11 +49,11 @@ public class HttpInvokerGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithName() {
|
||||
public void gatewayWithName() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerGatewayParserTests.xml", this.getClass());
|
||||
"httpInvokerInboundGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("/gateway/with/name");
|
||||
HttpInvokerInboundGateway gateway = (HttpInvokerInboundGateway) context.getBean("/gateway/with/name");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
@@ -65,11 +65,11 @@ public class HttpInvokerGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithCustomProperties() {
|
||||
public void gatewayWithCustomProperties() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerGatewayParserTests.xml", this.getClass());
|
||||
"httpInvokerInboundGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("gatewayWithCustomProperties");
|
||||
HttpInvokerInboundGateway gateway = (HttpInvokerInboundGateway) context.getBean("gatewayWithCustomProperties");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(false, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.httpinvoker.config;
|
||||
package org.springframework.integration.httpinvoker.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -22,19 +22,19 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.httpinvoker.HttpInvokerHandler;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerHandlerParserTests {
|
||||
public class HttpInvokerOutboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testHttpInvokerHandlerParser() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("httpInvokerHandlerParserTests.xml", this.getClass());
|
||||
MessageHandler handler = (MessageHandler) context.getBean("handler");
|
||||
assertEquals(HttpInvokerHandler.class, handler.getClass());
|
||||
public void testHttpInvokerOutboundGatewayParser() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerOutboundGatewayParserTests.xml", this.getClass());
|
||||
Object gateway = context.getBean("gateway");
|
||||
assertEquals(HttpInvokerOutboundGateway.class, gateway.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:httpinvoker="http://www.springframework.org/schema/integration/httpinvoker"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/httpinvoker
|
||||
http://www.springframework.org/schema/integration/httpinvoker/spring-integration-httpinvoker-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<httpinvoker:inbound-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
|
||||
<httpinvoker:inbound-gateway name="/gateway/with/name" request-channel="testChannel"/>
|
||||
|
||||
<httpinvoker:inbound-gateway id="gatewayWithCustomProperties"
|
||||
request-channel="testChannel"
|
||||
request-timeout="123"
|
||||
expect-reply="false"
|
||||
reply-timeout="456"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -2,21 +2,18 @@
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:httpinvoker="http://www.springframework.org/schema/integration/httpinvoker"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
|
||||
http://www.springframework.org/schema/integration/httpinvoker
|
||||
http://www.springframework.org/schema/integration/httpinvoker/spring-integration-httpinvoker-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<httpinvoker-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
|
||||
<httpinvoker-gateway name="/gateway/with/name" request-channel="testChannel"/>
|
||||
|
||||
<httpinvoker-gateway id="gatewayWithCustomProperties"
|
||||
request-channel="testChannel" request-timeout="123"
|
||||
expect-reply="false" reply-timeout="456"/>
|
||||
<httpinvoker:outbound-gateway id="gateway" url="http://localhost:8080/test" request-channel="testChannel"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -19,8 +19,7 @@ package org.springframework.integration.rmi;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.adapter.AbstractRemotingGateway;
|
||||
import org.springframework.integration.adapter.RemotingInboundGatewaySupport;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
@@ -33,12 +32,12 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiGateway extends AbstractRemotingGateway implements InitializingBean, MessageHandler {
|
||||
public class RmiGateway extends RemotingInboundGatewaySupport implements MessageHandler {
|
||||
|
||||
public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway.";
|
||||
|
||||
|
||||
private final String requestChannelName;
|
||||
private volatile String requestChannelName;
|
||||
|
||||
private volatile String registryHost;
|
||||
|
||||
@@ -48,15 +47,15 @@ public class RmiGateway extends AbstractRemotingGateway implements InitializingB
|
||||
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
* Specify the request channel where messages will be sent.
|
||||
* It must not be <code>null</code>, and it must have a name.
|
||||
*/
|
||||
public RmiGateway(MessageChannel requestChannel) {
|
||||
super(requestChannel);
|
||||
@Override
|
||||
public void setRequestChannel(MessageChannel requestChannel) {
|
||||
Assert.notNull(requestChannel, "requestChannel must not be null");
|
||||
Assert.isTrue(StringUtils.hasText(requestChannel.getName()), "RmiGateway's request channel must have a name.");
|
||||
this.requestChannelName = requestChannel.getName();
|
||||
Assert.isTrue(StringUtils.hasText(this.requestChannelName), "RmiGateway's request channel must have a name.");
|
||||
super.setRequestChannel(requestChannel);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +71,7 @@ public class RmiGateway extends AbstractRemotingGateway implements InitializingB
|
||||
this.remoteInvocationExecutor = remoteInvocationExecutor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws RemoteException {
|
||||
RmiServiceExporter exporter = new RmiServiceExporter();
|
||||
if (this.registryHost != null) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.rmi;
|
||||
|
||||
import org.springframework.integration.adapter.AbstractRemotingHandler;
|
||||
import org.springframework.integration.adapter.AbstractRemotingOutboundGateway;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.remoting.rmi.RmiProxyFactoryBean;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandler extends AbstractRemotingHandler {
|
||||
public class RmiHandler extends AbstractRemotingOutboundGateway {
|
||||
|
||||
public RmiHandler(String url) {
|
||||
super(url);
|
||||
|
||||
@@ -21,18 +21,18 @@ import java.rmi.registry.Registry;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
|
||||
import org.springframework.integration.rmi.RmiGateway;
|
||||
import org.springframework.integration.rmi.RmiHandler;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <rmi-handler/> element.
|
||||
* Parser for the <outbound-gateway/> element of the 'rmi' namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RmiHandlerParser extends AbstractSingleBeanDefinitionParser {
|
||||
public class RmiHandlerParser extends AbstractRemotingOutboundGatewayParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
@@ -40,17 +40,15 @@ public class RmiHandlerParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !"host".equals(attributeName)
|
||||
&& !"port".equals(attributeName)
|
||||
&& !"remote-channel".equals(attributeName)
|
||||
&& super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
protected void doPostProcess(BeanDefinitionBuilder builder, Element element) {
|
||||
String host = element.getAttribute("host");
|
||||
String remoteChannel = element.getAttribute("remote-channel");
|
||||
if (!(StringUtils.hasText(host) && StringUtils.hasText(remoteChannel))) {
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
public class RmiNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
public void init() {
|
||||
this.registerBeanDefinitionParser("rmi-gateway", new RmiGatewayParser());
|
||||
this.registerBeanDefinitionParser("rmi-handler", new RmiHandlerParser());
|
||||
this.registerBeanDefinitionParser("inbound-gateway", new RmiGatewayParser());
|
||||
this.registerBeanDefinitionParser("outbound-gateway", new RmiHandlerParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,38 +16,53 @@
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="rmi-gateway">
|
||||
<xsd:element name="inbound-gateway">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an RMI-based gateway adapter.
|
||||
Defines an RMI-based inbound MessagingGateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="expect-reply" type="xsd:boolean" default="true"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="registry-host" type="xsd:string"/>
|
||||
<xsd:attribute name="registry-port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-invocation-executor" type="xsd:string"/>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:attribute name="expect-reply" type="xsd:boolean" default="true"/>
|
||||
<xsd:attribute name="registry-host" type="xsd:string"/>
|
||||
<xsd:attribute name="registry-port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-invocation-executor" type="xsd:string"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="rmi-handler">
|
||||
<xsd:element name="outbound-gateway">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines an RMI-based MessageHandler adapter.
|
||||
Defines an RMI-based outbound Messaging Gateway.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="host" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-channel" type="xsd:string" use="required"/>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="gatewayType">
|
||||
<xsd:attribute name="host" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="port" type="xsd:integer"/>
|
||||
<xsd:attribute name="remote-channel" type="xsd:string" use="required"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="gatewayType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines common configuration for gateway adapters.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="id" type="xsd:ID"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="request-channel" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="reply-channel" type="xsd:string"/>
|
||||
<xsd:attribute name="request-timeout" type="xsd:long"/>
|
||||
<xsd:attribute name="reply-timeout" type="xsd:long"/>
|
||||
</xsd:complexType>
|
||||
|
||||
</xsd:schema>
|
||||
@@ -42,7 +42,8 @@ public class RmiHandlerParserTests {
|
||||
@Before
|
||||
public void exportRemoteHandler() throws Exception {
|
||||
testChannel.setBeanName("testChannel");
|
||||
RmiGateway gateway = new RmiGateway(testChannel);
|
||||
RmiGateway gateway = new RmiGateway();
|
||||
gateway.setRequestChannel(testChannel);
|
||||
gateway.setExpectReply(false);
|
||||
gateway.afterPropertiesSet();
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class RmiHandlerParserTests {
|
||||
@Test
|
||||
public void testRmiHandlerDirectly() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("rmiHandlerParserTests.xml", this.getClass());
|
||||
RmiHandler handler = (RmiHandler) context.getBean("handler");
|
||||
RmiHandler handler = (RmiHandler) context.getBean("gateway");
|
||||
handler.handle(new StringMessage("test"));
|
||||
Message<?> result = testChannel.receive(1000);
|
||||
assertNotNull(result);
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<rmi:rmi-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
<rmi:inbound-gateway id="gatewayWithDefaults" request-channel="testChannel"/>
|
||||
|
||||
<rmi:rmi-gateway id="gatewayWithCustomProperties" request-channel="testChannel"
|
||||
<rmi:inbound-gateway id="gatewayWithCustomProperties" request-channel="testChannel"
|
||||
expect-reply="false" request-timeout="123" reply-timeout="456"/>
|
||||
|
||||
<rmi:rmi-gateway id="gatewayWithHost" request-channel="testChannel" registry-host="localhost"/>
|
||||
<rmi:inbound-gateway id="gatewayWithHost" request-channel="testChannel" registry-host="localhost"/>
|
||||
|
||||
<rmi:rmi-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234"/>
|
||||
<rmi:inbound-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234"/>
|
||||
|
||||
<rmi:rmi-gateway id="gatewayWithExecutorRef" request-channel="testChannel" remote-invocation-executor="invocationExecutor"/>
|
||||
<rmi:inbound-gateway id="gatewayWithExecutorRef" request-channel="testChannel" remote-invocation-executor="invocationExecutor"/>
|
||||
|
||||
<beans:bean id="invocationExecutor" class="org.springframework.integration.rmi.config.StubRemoteInvocationExecutor"/>
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
<channel id="localChannel"/>
|
||||
|
||||
<service-activator input-channel="localChannel" ref="handler"/>
|
||||
|
||||
<rmi:rmi-handler id="handler" remote-channel="testChannel" host="localhost"/>
|
||||
<rmi:outbound-gateway id="gateway" request-channel="localChannel" remote-channel="testChannel" host="localhost"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user