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

@@ -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.
*/

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,88 +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;
import java.io.IOException;
import javax.servlet.ServletException;
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.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
* {@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">
* &lt;servlet&gt;
* &lt;servlet-name&gt;httpInvokerGateway&lt;/servlet-name&gt;
* &lt;servlet-class&gt;org.springframework.web.context.support.HttpRequestHandlerServlet&lt;/servlet-class&gt;
* &lt;/servlet&gt;
* </pre>
*
* And, this would match the following bean definition in the application context loaded
* by a {@link org.springframework.web.context.ContextLoaderListener}:
*
* <pre class="code">
* &lt;bean id="httpInvokerGateway" class="org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway"&gt;
* &lt;constructor-arg ref="requestChannel"/&gt;
* &lt;/bean&gt;
* </pre>
*
* <p>
* Alternatively, in a Spring MVC application, the DispatcherServlet can delegate to the
* "httpInvokerGateway" bean based on a handler mapping configuration. In that case,
* the HttpRequestHandlerServlet would not be necessary.
* </p>
*
* @author Mark Fisher
*/
public class HttpInvokerGateway extends AbstractRemotingGateway implements HttpRequestHandler, InitializingBean {
private volatile HttpInvokerServiceExporter exporter;
public HttpInvokerGateway(MessageChannel requestChannel) {
super(requestChannel);
}
public void afterPropertiesSet() {
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
exporter.setService(this);
exporter.setServiceInterface(MessageHandler.class);
exporter.afterPropertiesSet();
this.exporter = exporter;
}
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (this.exporter == null) {
throw new MessagingException("adapter has not been initialized");
}
this.exporter.handleRequest(request, response);
}
}

View File

@@ -1,44 +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;
import org.springframework.integration.adapter.AbstractRemotingHandler;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
/**
* A MessageHandler adapter for HttpInvoker-based remoting.
*
* @author Mark Fisher
*/
public class HttpInvokerHandler extends AbstractRemotingHandler {
public HttpInvokerHandler(String url) {
super(url);
}
@Override
protected MessageHandler createHandlerProxy(String url) {
HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
proxyFactory.setServiceInterface(MessageHandler.class);
proxyFactory.setServiceUrl(url);
proxyFactory.afterPropertiesSet();
return (MessageHandler) proxyFactory.getObject();
}
}

View File

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

View File

@@ -1,36 +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.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,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