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

@@ -0,0 +1,82 @@
/*
* 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;
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.RemotingInboundGatewaySupport;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.message.MessagingException;
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
import org.springframework.web.HttpRequestHandler;
/**
* 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:
*
* <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 HttpInvokerInboundGateway extends RemotingInboundGatewaySupport implements HttpRequestHandler, InitializingBean {
private volatile HttpInvokerServiceExporter exporter;
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

@@ -0,0 +1,44 @@
/*
* 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;
import org.springframework.integration.adapter.AbstractRemotingOutboundGateway;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
/**
* A MessageHandler adapter for HttpInvoker-based remoting.
*
* @author Mark Fisher
*/
public class HttpInvokerOutboundGateway extends AbstractRemotingOutboundGateway {
public HttpInvokerOutboundGateway(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

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

View File

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

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.httpinvoker.config;
import org.w3c.dom.Element;
import org.springframework.integration.adapter.config.AbstractRemotingOutboundGatewayParser;
import org.springframework.integration.httpinvoker.HttpInvokerOutboundGateway;
/**
* Parser for the &lt;outbound-gateway/&gt; element of the 'httpinvoker' namespace.
*
* @author Mark Fisher
*/
public class HttpInvokerOutboundGatewayParser extends AbstractRemotingOutboundGatewayParser {
@Override
protected Class<?> getBeanClass(Element element) {
return HttpInvokerOutboundGateway.class;
}
}

View File

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

View File

@@ -0,0 +1 @@
http\://www.springframework.org/schema/integration/httpinvoker=org.springframework.integration.httpinvoker.config.HttpInvokerNamespaceHandler

View File

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