INT-904, INT-907 added exception mapper support to AbstractMessagingGateway, Changed ChannelPublishingMessageListener to extend form AbstractMesagingGateway, added namespace support, tests, etc...
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?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
|
||||
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
|
||||
xmlns:jms="http://www.springframework.org/schema/jms"
|
||||
xmlns:task="http://www.springframework.org/schema/task">
|
||||
|
||||
<int:gateway id="sampleGateway"
|
||||
service-interface="org.springframework.integration.jms.config.ExceptionHandlingSiConsumerTests$SampleGateway"
|
||||
default-request-channel="outbound-channel">
|
||||
</int:gateway>
|
||||
|
||||
<int:channel id="outbound-channel"/>
|
||||
|
||||
<int-jms:outbound-gateway request-channel="outbound-channel" request-destination="requestQueue"/>
|
||||
|
||||
|
||||
<int-jms:inbound-gateway request-destination="requestQueue"
|
||||
request-channel="jmsinputchannel"
|
||||
exception-mapper="errorMessageMapper"/>
|
||||
|
||||
<bean id="errorMessageMapper" class="org.springframework.integration.jms.config.ExceptionHandlingSiConsumerTests$SampleErrorMessageMapper"/>
|
||||
<int:channel id="jmsinputchannel"/>
|
||||
|
||||
<int:router input-channel="jmsinputchannel" expression="payload"/>
|
||||
|
||||
|
||||
|
||||
<int:service-activator input-channel="echoWithExceptionChannel" method="echoWithException">
|
||||
<bean class="org.springframework.integration.jms.config.ExceptionHandlingSiConsumerTests$SampleService"/>
|
||||
</int:service-activator>
|
||||
|
||||
|
||||
<int:service-activator input-channel="echoChannel" method="echo">
|
||||
<bean class="org.springframework.integration.jms.config.ExceptionHandlingSiConsumerTests$SampleService"/>
|
||||
</int:service-activator>
|
||||
|
||||
<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="replyTopic" class="org.apache.activemq.command.ActiveMQTopic">
|
||||
<constructor-arg value="reply.topic"/>
|
||||
</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>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.message.InboundMessageMapper;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.MessageCreator;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class ExceptionHandlingSiConsumerTests {
|
||||
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withReturn() throws Exception {
|
||||
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);
|
||||
final Destination reply = applicationContext.getBean("replyQueue", Destination.class);
|
||||
jmsTemplate.send(request, new MessageCreator() {
|
||||
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
TextMessage message = session.createTextMessage();
|
||||
message.setText("echoChannel");
|
||||
message.setJMSReplyTo(reply);
|
||||
return message;
|
||||
}
|
||||
});
|
||||
Message message = jmsTemplate.receive(reply);
|
||||
Assert.assertNotNull(message);
|
||||
applicationContext.close();
|
||||
}
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withReturnNoException() throws Exception {
|
||||
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);
|
||||
final Destination reply = applicationContext.getBean("replyQueue", Destination.class);
|
||||
jmsTemplate.send(request, new MessageCreator() {
|
||||
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
TextMessage message = session.createTextMessage();
|
||||
message.setText("echoWithExceptionChannel");
|
||||
message.setJMSReplyTo(reply);
|
||||
return message;
|
||||
}
|
||||
});
|
||||
Message message = jmsTemplate.receive(reply);
|
||||
Assert.assertNotNull(message);
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonSiProducer_siConsumer_sync_withOutboundGateway() throws Exception{
|
||||
final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class);
|
||||
SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class);
|
||||
String reply = gateway.echo("echoWithExceptionChannel");
|
||||
System.out.println("Reply: " + reply);
|
||||
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");
|
||||
}
|
||||
public String echo(String value){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class SampleException extends RuntimeException{
|
||||
public SampleException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static interface SampleGateway{
|
||||
public String echo(String value);
|
||||
}
|
||||
|
||||
public static class SampleErrorMessageMapper implements InboundMessageMapper<Throwable>{
|
||||
public org.springframework.integration.core.Message<?> toMessage(
|
||||
Throwable t) throws Exception {
|
||||
return MessageBuilder.withPayload(t.getCause().getMessage()).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user