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,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">
|
||||
* <servlet>
|
||||
* <servlet-name>httpInvokerGateway</servlet-name>
|
||||
* <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
|
||||
* </servlet>
|
||||
* </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">
|
||||
* <bean id="httpInvokerGateway" class="org.springframework.integration.adapter.httpinvoker.HttpInvokerGateway">
|
||||
* <constructor-arg ref="requestChannel"/>
|
||||
* </bean>
|
||||
* </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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <httpinvoker-gateway/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGatewayParser extends AbstractRemotingGatewayParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HttpInvokerGateway.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <httpinvoker-handler/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerHandlerParser extends AbstractRemotingHandlerParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return HttpInvokerHandler.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,108 +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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.remoting.support.RemoteInvocation;
|
||||
import org.springframework.remoting.support.RemoteInvocationResult;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGatewayTests {
|
||||
|
||||
@Test
|
||||
public void testRequestOnly() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
|
||||
gateway.setExpectReply(false);
|
||||
gateway.afterPropertiesSet();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
request.setContent(createRequestContent(new StringMessage("test")));
|
||||
gateway.handleRequest(request, response);
|
||||
Message<?> message = channel.receive(500);
|
||||
assertNotNull(message);
|
||||
assertEquals("test", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestReply() throws Exception {
|
||||
final QueueChannel channel = new QueueChannel();
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
public void run() {
|
||||
Message<?> message = channel.receive();
|
||||
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReturnAddress();
|
||||
replyChannel.send(new StringMessage(message.getPayload().toString().toUpperCase()));
|
||||
}
|
||||
});
|
||||
HttpInvokerGateway gateway = new HttpInvokerGateway(channel);
|
||||
gateway.setExpectReply(true);
|
||||
gateway.afterPropertiesSet();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
request.setContent(createRequestContent(new StringMessage("test")));
|
||||
gateway.handleRequest(request, response);
|
||||
Message<?> reply = extractMessageFromResponse(response);
|
||||
assertEquals("TEST", reply.getPayload());
|
||||
}
|
||||
|
||||
|
||||
private static byte[] createRequestContent(Message<?> message) throws IOException {
|
||||
RemoteInvocation invocation = new RemoteInvocation(
|
||||
"handle", new Class[] { Message.class }, new Object[] { message });
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
try {
|
||||
oos.writeObject(invocation);
|
||||
oos.flush();
|
||||
}
|
||||
finally {
|
||||
oos.close();
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
private static Message<?> extractMessageFromResponse(MockHttpServletResponse response) throws IOException, ClassNotFoundException {
|
||||
byte[] responseContent = response.getContentAsByteArray();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(responseContent);
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
RemoteInvocationResult remoteResult = (RemoteInvocationResult) ois.readObject();
|
||||
Object resultValue = remoteResult.getValue();
|
||||
assertTrue(resultValue instanceof Message);
|
||||
return (Message<?>) resultValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +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 static org.junit.Assert.assertEquals;
|
||||
|
||||
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.message.MessageChannelTemplate;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testAdapterWithDefaults() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("gatewayWithDefaults");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
MessageChannelTemplate template = (MessageChannelTemplate)
|
||||
accessor.getPropertyValue("channelTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("sendTimeout"));
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("receiveTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithName() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("/gateway/with/name");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(true, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
MessageChannelTemplate template = (MessageChannelTemplate)
|
||||
accessor.getPropertyValue("channelTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("sendTimeout"));
|
||||
assertEquals(-1L, templateAccessor.getPropertyValue("receiveTimeout"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithCustomProperties() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"httpInvokerGatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("testChannel");
|
||||
HttpInvokerGateway gateway = (HttpInvokerGateway) context.getBean("gatewayWithCustomProperties");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
|
||||
assertEquals(false, accessor.getPropertyValue("expectReply"));
|
||||
assertEquals(channel, accessor.getPropertyValue("requestChannel"));
|
||||
MessageChannelTemplate template = (MessageChannelTemplate)
|
||||
accessor.getPropertyValue("channelTemplate");
|
||||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template);
|
||||
assertEquals(123L, templateAccessor.getPropertyValue("sendTimeout"));
|
||||
assertEquals(456L, templateAccessor.getPropertyValue("receiveTimeout"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +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 static org.junit.Assert.assertEquals;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class HttpInvokerHandlerParserTests {
|
||||
|
||||
@Test
|
||||
public void testHttpInvokerHandlerParser() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("httpInvokerHandlerParserTests.xml", this.getClass());
|
||||
MessageHandler handler = (MessageHandler) context.getBean("handler");
|
||||
assertEquals(HttpInvokerHandler.class, handler.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +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-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"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user