GatewayProxyFactoryBean now creates a Map of gateways (per-Method). This will enable support for @Gateway annotations (coming soon). Also, the @Header and @Headers annotations are now supported for gateway method parameters. The 'request-channel' and 'reply-channel' attributes of the <gateway/> element have been changed to 'default-request-channel' and 'default-reply-channel' since the request/reply channels will be configurable on a method-by-method basis with annotations (the same applies to 'request-timeout' and 'reply-timeout'). The MessageMapper interface has been split into InboundMessageMapper (with 'toMessage') and OutboundMessageMapper (with 'fromMessage') since the behavior is not always symmetrical For example, the gateway uses MethodParameterMessageMapper for creating a Message *from* the args array but it uses SimpleMessageMapper (the new name for DefaultMessageMapper) to create a Message whose payload is the method's return value.
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -44,7 +45,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
QueueChannel requestChannel = new QueueChannel();
|
||||
startResponder(requestChannel);
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setRequestChannel(requestChannel);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
@@ -57,7 +58,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
final QueueChannel requestChannel = new QueueChannel();
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setRequestChannel(requestChannel);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
service.oneWay("test");
|
||||
@@ -72,7 +73,8 @@ public class GatewayProxyFactoryBeanTests {
|
||||
replyChannel.send(new StringMessage("foo"));
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setReplyChannel(replyChannel);
|
||||
proxyFactory.setDefaultRequestChannel(new DirectChannel());
|
||||
proxyFactory.setDefaultReplyChannel(replyChannel);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
String result = service.solicitResponse();
|
||||
@@ -92,7 +94,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
}).start();
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setRequestChannel(requestChannel);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
Integer result = service.requestReplyWithIntegers(123);
|
||||
@@ -160,7 +162,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
startResponder(requestChannel);
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setRequestChannel(requestChannel);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
String result = service.requestReplyWithMessageParameter(new StringMessage("foo"));
|
||||
@@ -179,7 +181,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
}).start();
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.setRequestChannel(requestChannel);
|
||||
proxyFactory.setDefaultRequestChannel(requestChannel);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
TestService service = (TestService) proxyFactory.getObject();
|
||||
Message<?> result = service.requestReplyWithMessageReturnValue("foo");
|
||||
@@ -205,6 +207,7 @@ public class GatewayProxyFactoryBeanTests {
|
||||
@Test
|
||||
public void testProxiedToStringMethod() throws Exception {
|
||||
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
|
||||
proxyFactory.setDefaultRequestChannel(new DirectChannel());
|
||||
proxyFactory.setServiceInterface(TestService.class);
|
||||
proxyFactory.afterPropertiesSet();
|
||||
Object proxy = proxyFactory.getObject();
|
||||
|
||||
@@ -67,17 +67,6 @@ public class GatewayParserTests {
|
||||
assertEquals("foo", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestReplyWithMessageMapper() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass());
|
||||
PollableChannel requestChannel = (PollableChannel) context.getBean("requestChannel");
|
||||
MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
|
||||
this.startResponder(requestChannel, replyChannel);
|
||||
TestService service = (TestService) context.getBean("requestReplyWithMessageMapper");
|
||||
String result = service.requestReply("foo");
|
||||
assertEquals("pre.foo.post", result);
|
||||
}
|
||||
|
||||
|
||||
private void startResponder(final PollableChannel requestChannel, final MessageChannel replyChannel) {
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
|
||||
@@ -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.gateway.config;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestMessageMapper implements MessageMapper<String> {
|
||||
|
||||
public Message<?> toMessage(String object) {
|
||||
return new StringMessage("pre." + object);
|
||||
}
|
||||
|
||||
public String fromMessage(Message<?> message) {
|
||||
return message.getPayload().toString() + ".post";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,24 +19,16 @@
|
||||
|
||||
<gateway id="oneWay"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
request-channel="requestChannel"/>
|
||||
default-request-channel="requestChannel"/>
|
||||
|
||||
<gateway id="solicitResponse"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
reply-channel="replyChannel"
|
||||
reply-timeout="3000"/>
|
||||
default-reply-channel="replyChannel"
|
||||
default-reply-timeout="3000"/>
|
||||
|
||||
<gateway id="requestReply"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
request-channel="requestChannel"
|
||||
reply-channel="replyChannel"/>
|
||||
|
||||
<gateway id="requestReplyWithMessageMapper"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
request-channel="requestChannel"
|
||||
reply-channel="replyChannel"
|
||||
message-mapper="mapper"/>
|
||||
|
||||
<beans:bean id="mapper" class="org.springframework.integration.gateway.config.TestMessageMapper"/>
|
||||
default-request-channel="requestChannel"
|
||||
default-reply-channel="replyChannel"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<beans:bean id="proxy" class="org.springframework.integration.gateway.GatewayProxyFactoryBean">
|
||||
<beans:property name="serviceInterface" value="org.springframework.integration.gateway.TestService"/>
|
||||
<beans:property name="requestChannel" ref="requestChannel"/>
|
||||
<beans:property name="defaultRequestChannel" ref="requestChannel"/>
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="testHandler" class="org.springframework.integration.gateway.TestHandler"/>
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
<beans:bean id="proxy" class="org.springframework.integration.gateway.GatewayProxyFactoryBean">
|
||||
<beans:property name="serviceInterface" value="org.springframework.integration.gateway.TestService"/>
|
||||
<beans:property name="requestChannel" ref="requestChannel"/>
|
||||
<beans:property name="replyChannel" ref="replyChannel"/>
|
||||
<beans:property name="defaultRequestChannel" ref="requestChannel"/>
|
||||
<beans:property name="defaultReplyChannel" ref="replyChannel"/>
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="handler" class="org.springframework.integration.gateway.TestHandler"/>
|
||||
|
||||
Reference in New Issue
Block a user