RmiTargetAdapter is now RmiHandler, and HttpInvokerTargetAdapter is now HttpInvokerHandler since they both enable request-reply behavior. In the spring-integration-adapters namespace, the corresponding XML elements have changed from "rmi-target" and "httpinvoker-target" to "rmi-handler" and "httpinvoker-handler". Rather than creating HandlerEndpoint instances, their parsers now create just the MessageHandler instances. Therefore, the results should be wired as references (via the "handler" attribute) within <handler-endpoint/> elements.

This commit is contained in:
Mark Fisher
2008-05-28 00:03:13 +00:00
parent 8d2368e6a3
commit ccc3e06928
20 changed files with 189 additions and 164 deletions

View File

@@ -26,12 +26,12 @@ import org.springframework.integration.message.Message;
*
* @author Mark Fisher
*/
public abstract class AbstractGatewayAdapter extends SimpleMessagingGateway implements MessageHandler {
public abstract class AbstractRemotingGateway extends SimpleMessagingGateway implements MessageHandler {
private volatile boolean expectReply = true;
public AbstractGatewayAdapter(MessageChannel requestChannel) {
public AbstractRemotingGateway(MessageChannel requestChannel) {
super(requestChannel);
}

View File

@@ -24,16 +24,16 @@ import org.springframework.integration.message.MessageHandlingException;
import org.springframework.remoting.RemoteAccessException;
/**
* A base class for remoting target adapters.
* A base class for remoting {@link MessageHandler} adapters.
*
* @author Mark Fisher
*/
public abstract class AbstractRemotingTargetAdapter implements MessageHandler {
public abstract class AbstractRemotingHandler implements MessageHandler {
private final MessageHandler handlerProxy;
public AbstractRemotingTargetAdapter(String url) {
public AbstractRemotingHandler(String url) {
this.handlerProxy = this.createHandlerProxy(url);
}

View File

@@ -27,14 +27,15 @@ import org.springframework.integration.ConfigurationException;
import org.springframework.util.StringUtils;
/**
* Base class for gateway parsers.
* Base class for remoting gateway parsers.
*
* @author Mark Fisher
*/
public abstract class AbstractGatewayParser extends AbstractSimpleBeanDefinitionParser {
public abstract class AbstractRemotingGatewayParser extends AbstractSimpleBeanDefinitionParser {
protected abstract Class<?> getBeanClass(Element element);
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {

View File

@@ -0,0 +1,60 @@
/*
* 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.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.
*
* @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;
}
@Override
protected boolean isEligibleAttribute(String attributeName) {
return !attributeName.equals("url") && super.isEligibleAttribute(attributeName);
}
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
String url = element.getAttribute("url");
if (!StringUtils.hasText(url)) {
throw new ConfigurationException("The 'url' attribute is required.");
}
builder.addConstructorArgValue(url);
}
}

View File

@@ -170,17 +170,16 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="rmi-target">
<xsd:element name="rmi-handler">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines an rmi-based target channel adapter.
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="local-channel" type="xsd:string" use="required"/>
<xsd:attribute name="remote-channel" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
@@ -188,20 +187,19 @@
<xsd:element name="httpinvoker-gateway" type="gatewayType">
<xsd:annotation>
<xsd:documentation>
Defines an httpinvoker-based gateway adapter.
Defines an HttpInvoker-based gateway adapter.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="httpinvoker-target">
<xsd:element name="httpinvoker-handler">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines an httpinvoker-based target channel adapter.
Defines an HttpInvoker-based MessageHandler adapter.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="channel" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:ID"/>
<xsd:attribute name="url" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>

View File

@@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.adapter.AbstractGatewayAdapter;
import org.springframework.integration.adapter.AbstractRemotingGateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.MessagingException;
@@ -60,7 +60,7 @@ import org.springframework.web.HttpRequestHandler;
*
* @author Mark Fisher
*/
public class HttpInvokerGateway extends AbstractGatewayAdapter implements HttpRequestHandler, InitializingBean {
public class HttpInvokerGateway extends AbstractRemotingGateway implements HttpRequestHandler, InitializingBean {
private volatile HttpInvokerServiceExporter exporter;

View File

@@ -16,18 +16,18 @@
package org.springframework.integration.adapter.httpinvoker;
import org.springframework.integration.adapter.AbstractRemotingTargetAdapter;
import org.springframework.integration.adapter.AbstractRemotingHandler;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
/**
* A target channel adapter for HttpInvoker-based remoting.
* A MessageHandler adapter for HttpInvoker-based remoting.
*
* @author Mark Fisher
*/
public class HttpInvokerTargetAdapter extends AbstractRemotingTargetAdapter {
public class HttpInvokerHandler extends AbstractRemotingHandler {
public HttpInvokerTargetAdapter(String url) {
public HttpInvokerHandler(String url) {
super(url);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.integration.adapter.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.integration.adapter.config.AbstractGatewayParser;
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway;
/**
@@ -26,7 +26,7 @@ import org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway;
*
* @author Mark Fisher
*/
public class HttpInvokerGatewayParser extends AbstractGatewayParser {
public class HttpInvokerGatewayParser extends AbstractRemotingGatewayParser {
@Override
protected Class<?> getBeanClass(Element element) {

View File

@@ -0,0 +1,36 @@
/*
* 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.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.integration.adapter.config.AbstractRemotingHandlerParser;
import org.springframework.integration.adapter.httpinvoker.HttpInvokerHandler;
/**
* Parser for the &lt;httpinvoker-handler/&gt; element.
*
* @author Mark Fisher
*/
public class HttpInvokerHandlerParser extends AbstractRemotingHandlerParser {
@Override
protected Class<?> getBeanClass(Element element) {
return HttpInvokerHandler.class;
}
}

View File

@@ -1,69 +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.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
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.httpinvoker.HttpInvokerTargetAdapter;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.scheduling.Subscription;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;httpinvoker-target/&gt; element.
*
* @author Mark Fisher
*/
public class HttpInvokerTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
protected Class<?> getBeanClass(Element element) {
return HandlerEndpoint.class;
}
protected boolean shouldGenerateId() {
return false;
}
protected boolean shouldGenerateIdAsFallback() {
return true;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
RootBeanDefinition adapterDef = new RootBeanDefinition(HttpInvokerTargetAdapter.class);
String channel = element.getAttribute("channel");
String url = element.getAttribute("url");
if (!StringUtils.hasText(channel)) {
throw new ConfigurationException("The 'channel' attribute is required.");
}
if (!StringUtils.hasText(url)) {
throw new ConfigurationException("The 'url' attribute is required.");
}
adapterDef.getConstructorArgumentValues().addGenericArgumentValue(url);
String adapterBeanName = parserContext.getReaderContext().generateBeanName(adapterDef);
parserContext.registerBeanComponent(new BeanComponentDefinition(adapterDef, adapterBeanName));
builder.addConstructorArgReference(adapterBeanName);
Subscription subscription = new Subscription(channel);
builder.addPropertyValue("subscription", subscription);
}
}

View File

@@ -20,7 +20,7 @@ import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.adapter.AbstractGatewayAdapter;
import org.springframework.integration.adapter.AbstractRemotingGateway;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.rmi.RmiServiceExporter;
@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class RmiGateway extends AbstractGatewayAdapter implements InitializingBean, MessageHandler {
public class RmiGateway extends AbstractRemotingGateway implements InitializingBean, MessageHandler {
public static final String SERVICE_NAME_PREFIX = "org.springframewok.integration.rmiGateway.";

View File

@@ -16,19 +16,18 @@
package org.springframework.integration.adapter.rmi;
import org.springframework.integration.adapter.AbstractRemotingTargetAdapter;
import org.springframework.integration.adapter.AbstractRemotingHandler;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
/**
* A target channel adapter for RMI-based remoting.
* A MessageHandler adapter for RMI-based remoting.
*
* @author Mark Fisher
*/
public class RmiTargetAdapter extends AbstractRemotingTargetAdapter {
public class RmiHandler extends AbstractRemotingHandler {
public RmiTargetAdapter(String url) {
public RmiHandler(String url) {
super(url);
}

View File

@@ -19,7 +19,7 @@ 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.AbstractGatewayParser;
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
import org.springframework.integration.adapter.rmi.RmiGateway;
import org.springframework.util.StringUtils;
@@ -28,7 +28,7 @@ import org.springframework.util.StringUtils;
*
* @author Mark Fisher
*/
public class RmiGatewayParser extends AbstractGatewayParser {
public class RmiGatewayParser extends AbstractRemotingGatewayParser {
private static final String REMOTE_INVOCATION_EXECUTOR_ATTRIBUTE = "remote-invocation-executor";

View File

@@ -16,57 +16,50 @@
package org.springframework.integration.adapter.rmi.config;
import java.rmi.registry.Registry;
import org.w3c.dom.Element;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
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.RmiGateway;
import org.springframework.integration.adapter.rmi.RmiTargetAdapter;
import org.springframework.integration.endpoint.HandlerEndpoint;
import org.springframework.integration.scheduling.Subscription;
import org.springframework.integration.adapter.rmi.RmiHandler;
import org.springframework.util.StringUtils;
/**
* Parser for the &lt;rmi-target/&gt; element.
* Parser for the &lt;rmi-handler/&gt; element.
*
* @author Mark Fisher
*/
public class RmiTargetAdapterParser extends AbstractSingleBeanDefinitionParser {
public class RmiHandlerParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return HandlerEndpoint.class;
return RmiHandler.class;
}
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
RootBeanDefinition adapterDef = new RootBeanDefinition(RmiTargetAdapter.class);
@Override
protected void doParse(Element element, BeanDefinitionBuilder builder) {
String host = element.getAttribute("host");
String localChannel = element.getAttribute("local-channel");
String remoteChannel = element.getAttribute("remote-channel");
if (!(StringUtils.hasText(host) && StringUtils.hasText(localChannel) && StringUtils.hasText(remoteChannel))) {
throw new ConfigurationException(
"The 'host', 'local-channel', and 'remote-channel' attributes are all required");
if (!(StringUtils.hasText(host) && StringUtils.hasText(remoteChannel))) {
throw new ConfigurationException("The 'host' and 'remote-channel' attributes are both required");
}
String portAttribute = element.getAttribute("port");
String port = StringUtils.hasText(portAttribute) ? portAttribute : "1099";
String port = StringUtils.hasText(portAttribute) ? portAttribute : "" + Registry.REGISTRY_PORT;
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));
builder.addConstructorArgReference(adapterBeanName);
Subscription subscription = new Subscription(localChannel);
builder.addPropertyValue("subscription", subscription);
builder.addConstructorArgValue(url);
}
}

View File

@@ -4,10 +4,10 @@ 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-target=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerTargetAdapterParser
httpinvoker-handler=org.springframework.integration.adapter.httpinvoker.config.HttpInvokerHandlerParser
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-gateway=org.springframework.integration.adapter.rmi.config.RmiGatewayParser
rmi-target=org.springframework.integration.adapter.rmi.config.RmiTargetAdapterParser
rmi-handler=org.springframework.integration.adapter.rmi.config.RmiHandlerParser