Announcement Announcement Module
No announcement yet.
Exception handling Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception handling

    Hi guys,

    I'm a newbie to spring integration. Been using spring itself for sometime. I have a situation where I'm reading of a jms queue. I have read:
    where it talks about things being within the same thread etc. I think I've understood this. I believe that for the current situation I'm doing everything within one thread.

    I am throwing an exception in the service-activator. I want that exception to cause a rollback onto the queue. This isn't happening and I"m not sure why. I hope someone can help me.

    NOTE: the unit test is feeding object properties, so the TestService class WILL throw the exception that is caught, in turn throwing the MessageHandlingException. I have tried throwing JmsException and other types of exception. All do the same thing, which is stop the flow, but the transaction is still commited.

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns=""
        <beans:bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
            <beans:property name="targetConnectionFactory">
                <beans:bean class="org.apache.activemq.ActiveMQConnectionFactory">
                    <beans:property name="brokerURL" value="vm://localhost"/>     
            <beans:property name="sessionCacheSize" value="10"/>
            <beans:property name="cacheProducers" value="false"/>
        <poller id="poller" default="true">
            <interval-trigger interval="1000"/>
        <!-- The error-channel only comes into play if there is an asynchronous boundary - if the task is submitted 
             to a TaskExecutor along the way (e.g. when a channel with a 'queue' is used). However, that would also 
             break the transactional boundary that starts with the JMS message being received. 
        <channel id="errorChannel">
    	    <queue capacity="500"/>
        <stream:stderr-channel-adapter id="stdoutError" channel="errorChannel" append-newline="true" />
        <!-- INBOUND QUEUE HANDLER -->
        <channel id="requests"/>
            connection-factory="connectionFactory" destination-name="Q.TEST1" channel="requests" 
            message-converter="messageConverter" transaction-manager="transactionManager" />
        <stream:stdout-channel-adapter id="stdout" channel="requests" append-newline="true"/>
        <!-- TransactionManager -->
        <!-- beans:bean id="jbossTransactionManager" class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple">
        <beans:bean id="jbossUserTransaction" class="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple"/>
        <beans:bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
            <beans:property name="userTransaction" ref="jbossUserTransaction" />
            <beans:property name="transactionManager" ref="jbossTransactionManager" />
        </beans:bean -->
        <beans:bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager102">
            <beans:property name="connectionFactory" ref="connectionFactory" />
        <!-- NOTE NOTE NOTE -->
        <!-- technically do not need to have a message converter, as by default it will convert to 
             org.springframework.integration.message.GenericMessage -->
        <beans:bean id="messageConverter" class="" />
        <!-- TEST SERVICE - Print info about message -->
        <beans:bean id="TestService" class="com.hyro.springintegrationtest.testclasses.jmsrouter.TestService">
        <service-activator input-channel="requests" output-channel="processedRequests" ref="TestService" method="printInfo" />
        <channel id="processedRequests" />
        <!-- OUTPUT TO QUEUE -->
        <!-- right, so we got it (it will have printed the body to the console - now put it into the other queue -->
            connection-factory="connectionFactory" destination-name="Q.TEST2" channel="processedRequests">
    The service class as it currently stands:
    package com.hyro.springintegrationtest.testclasses.jmsrouter;
    import java.util.Iterator;
    import java.util.Set;
    import javax.jms.JMSException;
    import org.springframework.integration.core.Message;
    import org.springframework.integration.core.MessageHeaders;
    import org.springframework.integration.message.MessageHandlingException;
     * Creation Details:
     * @author pedwards
     * Created: 23/02/2010
     * Time: 10:36:24 AM
    public class TestService {
         * Print whatever info we can find about the received message
         * @param info
         * @return
        public Message<?> printInfo(Message<?> info) throws Exception {
            try {
                System.out.println("*** TestService PrintInfo ***");
                System.out.println("info class type: " + info.getClass().getName());
                MessageHeaders headers = info.getHeaders();
                Set<String>keySet = headers.keySet();
                for(Iterator<String>i=keySet.iterator(); i.hasNext();) {
                    String headerKey =;
                    //Object headerValue = headers.get(headerKey);
                    String headerValue = (String)headers.get(headerKey);
                    System.out.println("Header: '" + headerKey + "' value: '" + headerValue + "'");
                System.out.println("Contents: '" + info.getPayload() + "'");
            catch(Exception e) {
                //System.out.println("Exception thrown during PrintInfo: " + e.getMessage());
                //lets kill the process
                throw new MessageHandlingException(info, "Exception thrown during PrintInfo: " + e.getMessage());
            return info;