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