Added namespace support for GatewayProxyFactoryBean with the new <gateway/> element (INT-226).
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.gateway.TestService;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class GatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testOneWay() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass());
|
||||
TestService service = (TestService) context.getBean("oneWay");
|
||||
service.oneWay("foo");
|
||||
MessageChannel channel = (MessageChannel) context.getBean("requestChannel");
|
||||
Message<?> result = channel.receive(1000);
|
||||
assertEquals("foo", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSolicitResponse() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("replyChannel");
|
||||
channel.send(new StringMessage("foo"));
|
||||
TestService service = (TestService) context.getBean("solicitResponse");
|
||||
String result = service.solicitResponse();
|
||||
assertEquals("foo", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestReply() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass());
|
||||
MessageChannel requestChannel = (MessageChannel) context.getBean("requestChannel");
|
||||
MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
|
||||
this.startResponder(requestChannel, replyChannel);
|
||||
TestService service = (TestService) context.getBean("requestReply");
|
||||
String result = service.requestReply("foo");
|
||||
assertEquals("foobar", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestReplyWithMessageMapper() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass());
|
||||
MessageChannel requestChannel = (MessageChannel) 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("foobar.mapped", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestReplyWithMessageCreator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("gatewayParserTests.xml", this.getClass());
|
||||
MessageChannel requestChannel = (MessageChannel) context.getBean("requestChannel");
|
||||
MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
|
||||
this.startResponder(requestChannel, replyChannel);
|
||||
TestService service = (TestService) context.getBean("requestReplyWithMessageCreator");
|
||||
String result = service.requestReply("foo");
|
||||
assertEquals("created.foobar", result);
|
||||
}
|
||||
|
||||
|
||||
private void startResponder(final MessageChannel requestChannel, final MessageChannel replyChannel) {
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
public void run() {
|
||||
Message<?> request = requestChannel.receive();
|
||||
Message<?> reply = new StringMessage(request.getPayload() + "bar");
|
||||
reply.getHeader().setCorrelationId(request.getId());
|
||||
replyChannel.send(reply);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.MessageCreator;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestMessageCreator implements MessageCreator<String, String> {
|
||||
|
||||
public Message<String> createMessage(String s) {
|
||||
return new StringMessage("created." + s);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestMessageMapper implements MessageMapper<String, String> {
|
||||
|
||||
public String mapMessage(Message<String> message) {
|
||||
return message.getPayload() + ".mapped";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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-core-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="requestChannel"/>
|
||||
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<gateway id="oneWay"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
request-channel="requestChannel"/>
|
||||
|
||||
<gateway id="solicitResponse"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
reply-channel="replyChannel"
|
||||
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"/>
|
||||
|
||||
<gateway id="requestReplyWithMessageCreator"
|
||||
service-interface="org.springframework.integration.gateway.TestService"
|
||||
request-channel="requestChannel"
|
||||
reply-channel="replyChannel"
|
||||
message-creator="creator"/>
|
||||
|
||||
<beans:bean id="mapper" class="org.springframework.integration.gateway.config.TestMessageMapper"/>
|
||||
|
||||
<beans:bean id="creator" class="org.springframework.integration.gateway.config.TestMessageCreator"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user