-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INT-1626 the JMS 'message-driven-channel-adapter' element now accepts…
… the 'error-channel' attribute
- Loading branch information
1 parent
6b8a0da
commit ed9a8d9
Showing
4 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
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" | ||
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"> | ||
|
||
<int-jms:message-driven-channel-adapter channel="jmsInputChannel" container="container"/> | ||
|
||
<int-jms:message-driven-channel-adapter channel="jmsInputChannel" destination="queueB" error-channel="testErrorChannel"/> | ||
|
||
<int:service-activator input-channel="jmsInputChannel"> | ||
<bean id="testService" class="org.springframework.integration.jms.config.InboundOneWayErrorTests$TestService"/> | ||
</int:service-activator> | ||
|
||
<int:channel id="testErrorChannel"> | ||
<int:queue/> | ||
</int:channel> | ||
|
||
<bean id="queueA" class="org.apache.activemq.command.ActiveMQQueue"> | ||
<constructor-arg value="oneway.a"/> | ||
</bean> | ||
|
||
<bean id="queueB" class="org.apache.activemq.command.ActiveMQQueue"> | ||
<constructor-arg value="oneway.b"/> | ||
</bean> | ||
|
||
<bean id="container" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> | ||
<property name="connectionFactory" ref="connectionFactory"/> | ||
<property name="destination" ref="queueA"/> | ||
<property name="errorHandler" ref="testErrorHandler"/> | ||
</bean> | ||
|
||
<bean id="testErrorHandler" class="org.springframework.integration.jms.config.InboundOneWayErrorTests$TestErrorHandler"/> | ||
|
||
<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> |
118 changes: 118 additions & 0 deletions
118
...jms/src/test/java/org/springframework/integration/jms/config/InboundOneWayErrorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* 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 static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.jms.ConnectionFactory; | ||
import javax.jms.Destination; | ||
import javax.jms.JMSException; | ||
import javax.jms.Session; | ||
|
||
import org.junit.Test; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
import org.springframework.integration.Message; | ||
import org.springframework.integration.MessageHandlingException; | ||
import org.springframework.integration.core.PollableChannel; | ||
import org.springframework.jms.core.JmsTemplate; | ||
import org.springframework.jms.core.MessageCreator; | ||
import org.springframework.util.ErrorHandler; | ||
|
||
/** | ||
* @author Mark Fisher | ||
*/ | ||
public class InboundOneWayErrorTests { | ||
|
||
@Test | ||
public void noErrorChannel() throws Exception { | ||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("InboundOneWayErrorTests-context.xml", getClass()); | ||
JmsTemplate jmsTemplate = new JmsTemplate(context.getBean("connectionFactory", ConnectionFactory.class)); | ||
Destination queue = context.getBean("queueA", Destination.class); | ||
jmsTemplate.send(queue, new MessageCreator() { | ||
public javax.jms.Message createMessage(Session session) throws JMSException { | ||
return session.createTextMessage("test-A"); | ||
} | ||
}); | ||
TestErrorHandler errorHandler = context.getBean("testErrorHandler", TestErrorHandler.class); | ||
errorHandler.latch.await(3000, TimeUnit.MILLISECONDS); | ||
assertNotNull(errorHandler.lastError); | ||
assertNotNull(errorHandler.lastError.getCause()); | ||
assertEquals("failed to process: test-A", errorHandler.lastError.getCause().getMessage()); | ||
PollableChannel testErrorChannel = context.getBean("testErrorChannel", PollableChannel.class); | ||
assertNull(testErrorChannel.receive(0)); | ||
context.close(); | ||
} | ||
|
||
@Test | ||
public void errorChannel() throws Exception { | ||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("InboundOneWayErrorTests-context.xml", getClass()); | ||
JmsTemplate jmsTemplate = new JmsTemplate(context.getBean("connectionFactory", ConnectionFactory.class)); | ||
Destination queue = context.getBean("queueB", Destination.class); | ||
jmsTemplate.send(queue, new MessageCreator() { | ||
public javax.jms.Message createMessage(Session session) throws JMSException { | ||
return session.createTextMessage("test-B"); | ||
} | ||
}); | ||
PollableChannel errorChannel = context.getBean("testErrorChannel", PollableChannel.class); | ||
Message<?> errorMessage = errorChannel.receive(3000); | ||
assertNotNull(errorMessage); | ||
assertEquals(MessageHandlingException.class, errorMessage.getPayload().getClass()); | ||
MessageHandlingException exception = (MessageHandlingException) errorMessage.getPayload(); | ||
assertNotNull(exception.getCause()); | ||
assertEquals(TestException.class, exception.getCause().getClass()); | ||
assertEquals("failed to process: test-B", exception.getCause().getMessage()); | ||
TestErrorHandler errorHandler = context.getBean("testErrorHandler", TestErrorHandler.class); | ||
assertNull(errorHandler.lastError); | ||
context.close(); | ||
} | ||
|
||
|
||
public static class TestService { | ||
public void process(Object o) { | ||
throw new TestException("failed to process: " + o); | ||
} | ||
} | ||
|
||
|
||
@SuppressWarnings("serial") | ||
private static class TestException extends RuntimeException { | ||
public TestException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
|
||
@SuppressWarnings("unused") | ||
private static class TestErrorHandler implements ErrorHandler { | ||
|
||
private final CountDownLatch latch = new CountDownLatch(1); | ||
|
||
private volatile Throwable lastError; | ||
|
||
public void handleError(Throwable t) { | ||
this.lastError = t; | ||
this.latch.countDown(); | ||
} | ||
} | ||
|
||
} |