INT-1223, INT-1226. The fix is temporary as we are considering refactoring of ARPMH and supporting classes (see INT-1227), however test cases are now in place to aid in refactoring efforts
This commit is contained in:
@@ -19,6 +19,7 @@ package org.springframework.integration.filter;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
* provided, the rejected Messages will be sent to that channel.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class MessageFilter extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
@@ -115,4 +117,11 @@ public class MessageFilter extends AbstractReplyProducingMessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void handleResult(Object replyMessage, MessageHeaders requestHeaders, MessageChannel replyChannel) {
|
||||
if (!this.sendReplyMessage((Message<?>) replyMessage, replyChannel)) {
|
||||
throw new MessageDeliveryException((Message<?>) replyMessage,
|
||||
"failed to send reply Message to channel '" + replyChannel + "'. Consider increasing the " +
|
||||
"send timeout of this endpoint.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public abstract class AbstractReplyProducingMessageHandler extends AbstractMessageHandler
|
||||
implements MessageProducer {
|
||||
@@ -116,7 +117,7 @@ public abstract class AbstractReplyProducingMessageHandler extends AbstractMessa
|
||||
@SuppressWarnings("unchecked")
|
||||
private Message<?> createReplyMessage(Object reply, MessageHeaders requestHeaders) {
|
||||
if (reply instanceof Message) {
|
||||
return (Message<?>) reply;
|
||||
return MessageBuilder.fromMessage((Message<?>) reply).copyHeadersIfAbsent(requestHeaders).build();
|
||||
}
|
||||
MessageBuilder<?> builder = (reply instanceof MessageBuilder)
|
||||
? (MessageBuilder<?>) reply : MessageBuilder.withPayload(reply);
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.springframework.integration.transformer;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -29,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
* and sends the result to its output channel.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class MessageTransformingHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
@@ -69,5 +72,12 @@ public class MessageTransformingHandler extends AbstractReplyProducingMessageHan
|
||||
throw new MessageTransformationException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void handleResult(Object replyMessage, MessageHeaders requestHeaders, MessageChannel replyChannel) {
|
||||
if (!this.sendReplyMessage((Message<?>) replyMessage, replyChannel)) {
|
||||
throw new MessageDeliveryException((Message<?>) replyMessage,
|
||||
"failed to send reply Message to channel '" + replyChannel + "'. Consider increasing the " +
|
||||
"send timeout of this endpoint.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration">
|
||||
|
||||
|
||||
<int:gateway id="gatewayA"
|
||||
service-interface="org.springframework.integration.gateway.MultipleEndpointGatewayTests$SampleGateway"
|
||||
default-request-channel="routingChannel"/>
|
||||
|
||||
<int:gateway id="gatewayB"
|
||||
service-interface="org.springframework.integration.gateway.MultipleEndpointGatewayTests$SampleGateway"
|
||||
default-request-channel="routingChannel"
|
||||
default-reply-channel="outputChannel"/>
|
||||
|
||||
<int:publish-subscribe-channel id="outputChannel"/>
|
||||
|
||||
<int:router input-channel="routingChannel" expression="payload"/>
|
||||
|
||||
<!-- gatewayNoDefaultReplyChannel -->
|
||||
<int:service-activator input-channel="echoAsMessageChannel" output-channel="echoAsMessageChannelA" ref="service" method="echoAsMessage"/>
|
||||
<int:service-activator input-channel="echoAsMessageChannelA" ref="service" method="echoAsMessage"/>
|
||||
<!-- gatewayWithDefaultReplyChannel -->
|
||||
<int:service-activator input-channel="echoAsMessageChannelIgnoreDefOutChannel" output-channel="echoAsMessageChannelIgnoreDefOutChannelB" ref="service" method="echoAsMessage"/>
|
||||
<int:service-activator input-channel="echoAsMessageChannelIgnoreDefOutChannelB" ref="service" method="echoAsMessage"/>
|
||||
<!-- gatewayWithReplySentBackToDefaultReplyChannel -->
|
||||
<int:service-activator input-channel="echoAsMessageChannelDefaultOutputChannel" output-channel="echoAsMessageChannelDefaultOutputChannelB" ref="service" method="echoAsMessage"/>
|
||||
<int:service-activator input-channel="echoAsMessageChannelDefaultOutputChannelB" output-channel="outputChannel" ref="service" method="echoAsMessage"/>
|
||||
|
||||
|
||||
<bean id="service" class="org.springframework.integration.gateway.MultipleEndpointGatewayTests$SampleEchoService"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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 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.core.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class MultipleEndpointGatewayTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("gatewayA")
|
||||
private SampleGateway gatewayA;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("gatewayB")
|
||||
private SampleGateway gatewayB;
|
||||
|
||||
@Test
|
||||
public void gatewayNoDefaultReplyChannel(){
|
||||
gatewayA.echo("echoAsMessageChannel");
|
||||
// there is nothing to assert. Successful execution of the above is all we care in this test
|
||||
}
|
||||
@Test
|
||||
public void gatewayWithDefaultReplyChannel(){
|
||||
gatewayB.echo("echoAsMessageChannelIgnoreDefOutChannel");
|
||||
// there is nothing to assert. Successful execution of the above is all we care in this test
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gatewayWithReplySentBackToDefaultReplyChannel(){
|
||||
gatewayB.echo("echoAsMessageChannelDefaultOutputChannel");
|
||||
// there is nothing to assert. Successful execution of the above is all we care in this test
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
public Object echo(Object value);
|
||||
}
|
||||
|
||||
public static class SampleEchoService {
|
||||
public Object echo(Object value){
|
||||
return "R:" + value;
|
||||
}
|
||||
public Message echoAsMessage(Object value){
|
||||
return MessageBuilder.withPayload("R:" + value).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.jms.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class ActiveMqTestUtils {
|
||||
|
||||
@Before
|
||||
public static void prepare() {
|
||||
System.out.println("####### Refreshing ActiveMq ########");
|
||||
File activeMqTempDir = new File("activemq-data");
|
||||
deleteDir(activeMqTempDir);
|
||||
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private static void deleteDir(File directory){
|
||||
if (directory.exists()){
|
||||
String[] children = directory.list();
|
||||
if (children != null){
|
||||
for (int i=0; i < children.length; i++) {
|
||||
deleteDir(new File(directory, children[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
directory.delete();
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withReturn() throws Exception {
|
||||
ActiveMqTestUtils.prepare();
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
|
||||
JmsTemplate jmsTemplate = new JmsTemplate(applicationContext.getBean("connectionFactory", ConnectionFactory.class));
|
||||
Destination request = applicationContext.getBean("requestQueue", Destination.class);
|
||||
@@ -61,6 +62,7 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
}
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withReturnNoException() throws Exception {
|
||||
ActiveMqTestUtils.prepare();
|
||||
ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
|
||||
JmsTemplate jmsTemplate = new JmsTemplate(applicationContext.getBean("connectionFactory", ConnectionFactory.class));
|
||||
Destination request = applicationContext.getBean("requestQueue", Destination.class);
|
||||
@@ -81,6 +83,7 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withOutboundGateway() throws Exception{
|
||||
ActiveMqTestUtils.prepare();
|
||||
final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
|
||||
SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class);
|
||||
String reply = gateway.echo("echoWithExceptionChannel");
|
||||
@@ -88,30 +91,6 @@ public class ExceptionHandlingSiConsumerTests {
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void prepare() throws Exception {
|
||||
System.out.println("####### Refreshing ActiveMq ########");
|
||||
File activeMqTempDir = new File("activemq-data");
|
||||
this.deleteDir(activeMqTempDir);
|
||||
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
private void deleteDir(File directory){
|
||||
if (directory.exists()){
|
||||
String[] children = directory.list();
|
||||
if (children != null){
|
||||
for (int i=0; i < children.length; i++) {
|
||||
deleteDir(new File(directory, children[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
directory.delete();
|
||||
}
|
||||
|
||||
public static class SampleService{
|
||||
public String echoWithException(String value){
|
||||
throw new SampleException("echoWithException");
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.jms.support.converter.MessageConverter;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class JmsOutboundGatewayParserTests {
|
||||
|
||||
@@ -54,5 +55,25 @@ public class JmsOutboundGatewayParserTests {
|
||||
Object order = accessor.getPropertyValue("order");
|
||||
assertEquals(99, order);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void gatewayMaintainsReplyChannel() {
|
||||
ActiveMqTestUtils.prepare();
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"gatewayMaintainsReplyChannel.xml", this.getClass());
|
||||
SampleGateway gateway = context.getBean("gateway", SampleGateway.class);
|
||||
String result = gateway.echo("hello");
|
||||
assertEquals("HELLO", result);
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
public String echo(String value);
|
||||
}
|
||||
|
||||
public static class SampleService{
|
||||
public String echo(String value){
|
||||
return value.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?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-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jms="http://www.springframework.org/schema/integration/jms">
|
||||
|
||||
<int:gateway id="gateway"
|
||||
service-interface="org.springframework.integration.jms.config.JmsOutboundGatewayParserTests$SampleGateway"
|
||||
default-request-channel="requests">
|
||||
<int:method name="echo">
|
||||
<int:header name="foo" value="bar"/>
|
||||
</int:method>
|
||||
</int:gateway>
|
||||
|
||||
<int:chain input-channel="requests">
|
||||
<int-jms:outbound-gateway request-destination="requestQueue"
|
||||
reply-destination="replyQueue"
|
||||
connection-factory="connectionFactory"/>
|
||||
</int:chain>
|
||||
|
||||
|
||||
|
||||
<bean id="requestQueue" class="org.apache.activemq.command.ActiveMQQueue">
|
||||
<constructor-arg value="request.queue"/>
|
||||
</bean>
|
||||
|
||||
<bean id="replyQueue" class="org.apache.activemq.command.ActiveMQQueue">
|
||||
<constructor-arg value="reply.queue"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL" value="vm://localhost"/>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="sessionCacheSize" value="10"/>
|
||||
<property name="cacheProducers" value="false"/>
|
||||
</bean>
|
||||
|
||||
<int-jms:inbound-gateway request-channel="jmsInput" request-destination="requestQueue"/>
|
||||
|
||||
<int:channel id="jmsInput"/>
|
||||
|
||||
<int:service-activator input-channel="jmsInput">
|
||||
<bean class="org.springframework.integration.jms.config.JmsOutboundGatewayParserTests$SampleService"/>
|
||||
</int:service-activator>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user