INT-911, Created MessageHandling infrastructure around Gateway so it could be included in the <chain>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
|
||||
xmlns:si="http://www.springframework.org/schema/integration">
|
||||
|
||||
<si:gateway id="simpleGateway"
|
||||
default-request-channel="inputA"
|
||||
default-reply-channel="inputB"
|
||||
service-interface="org.springframework.integration.gateway.GatewayInvokingMessaheHandlerTests$SimpleGateway"/>
|
||||
|
||||
<si:publish-subscribe-channel id="inputA" />
|
||||
<si:publish-subscribe-channel id="inputB" />
|
||||
<si:publish-subscribe-channel id="inputC" />
|
||||
|
||||
<si:chain input-channel="inputA" output-channel="inputB">
|
||||
<si:header-enricher>
|
||||
<si:header name="foo" value="foo" />
|
||||
</si:header-enricher>
|
||||
<si:service-activator>
|
||||
<bean class="org.springframework.integration.gateway.GatewayInvokingMessaheHandlerTests$SimpleService" />
|
||||
</si:service-activator>
|
||||
<si:gateway default-request-channel="inputC"/>
|
||||
</si:chain>
|
||||
|
||||
|
||||
|
||||
<si:chain input-channel="inputC">
|
||||
<si:header-enricher>
|
||||
<si:header name="name" value="oleg" />
|
||||
</si:header-enricher>
|
||||
<si:service-activator>
|
||||
<bean class="org.springframework.integration.gateway.GatewayInvokingMessaheHandlerTests$SimpleService" />
|
||||
</si:service-activator>
|
||||
</si:chain>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.channel.SubscribableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* TODO - insert COMMENT
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class GatewayInvokingMessaheHandlerTests {
|
||||
@Autowired
|
||||
@Qualifier("inputA")
|
||||
SubscribableChannel channel;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("simpleGateway")
|
||||
SimpleGateway gateway;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inputB")
|
||||
SubscribableChannel output;
|
||||
|
||||
@Test
|
||||
public void validateGatewayInTheChainViaChannel(){
|
||||
output.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message)
|
||||
throws MessageRejectedException, MessageHandlingException,
|
||||
MessageDeliveryException {
|
||||
Assert.assertEquals("echo:echo:hello", message.getPayload());
|
||||
Assert.assertEquals("foo", message.getHeaders().get("foo"));
|
||||
Assert.assertEquals("oleg", message.getHeaders().get("name"));
|
||||
}
|
||||
});
|
||||
channel.send(new StringMessage("hello"));
|
||||
}
|
||||
@Test
|
||||
public void validateGatewayInTheChainViaAnotherGateway(){
|
||||
output.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message)
|
||||
throws MessageRejectedException, MessageHandlingException,
|
||||
MessageDeliveryException {
|
||||
Assert.assertEquals("echo:echo:hello", message.getPayload());
|
||||
Assert.assertEquals("foo", message.getHeaders().get("foo"));
|
||||
Assert.assertEquals("oleg", message.getHeaders().get("name"));
|
||||
}
|
||||
});
|
||||
String result = gateway.sendRecieve("hello");
|
||||
Assert.assertEquals("echo:echo:hello", result);
|
||||
}
|
||||
|
||||
public static interface SimpleGateway{
|
||||
public String sendRecieve(String str);
|
||||
}
|
||||
|
||||
public static class SimpleService {
|
||||
public String echo(String str){
|
||||
return "echo:" + str;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user