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:
Mark Fisher
2008-09-20 19:32:56 +00:00
parent 870ab7b9f4
commit 890d7b227a
28 changed files with 261 additions and 224 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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 &lt;rmi-handler/&gt; element.
* Parser for the &lt;outbound-gateway/&gt; 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))) {

View File

@@ -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());
}
}

View File

@@ -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>

View File

@@ -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);

View File

@@ -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"/>

View File

@@ -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>