camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dylansd <dylan.scott-dawk...@igindex.co.uk>
Subject Re: Unable to catch exception from Camel.
Date Mon, 27 Jun 2011 12:31:28 GMT
And here is the source code... Notice the excessive error handling
attempts...
The cause of the error is intentional (I am trying to send to a non-existant
queue :)

package spikes.camel;

import javax.jms.JMSException;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.DefaultErrorHandlerBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.component.jms.JmsConfiguration;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.BasicConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.connection.JmsTransactionManager102;
import
org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;

import com.ibm.mq.jms.MQQueueConnectionFactory;

public class CamelMQSpike {
   
   private static final Logger LOGGER =
LoggerFactory.getLogger(CamelMQSpike.class);
   
   public static void main(String[] args) throws Exception {
      try{
      BasicConfigurator.configure();
      UserCredentialsConnectionFactoryAdapter ucf = new
UserCredentialsConnectionFactoryAdapter();      
      MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
      
      cf.setHostName("host");
      try {
         cf.setPort(1415);         
         cf.setQueueManager("QM");
         cf.setChannel("CHANNEL");
         cf.setTransportType(1);         
         cf.setClientID("id");         
      } catch (JMSException e) {
         // TODO Auto-generated catch block         
         e.printStackTrace();
      }
      ucf.setTargetConnectionFactory(cf);
      ucf.setUsername("username");
      JmsConfiguration jc = new JmsConfiguration(ucf);
      jc.setExceptionListener(new MyExceptionListener());
      JmsTransactionManager102 jtm = new JmsTransactionManager102(cf,false);
      JmsComponent ibmmq = new JmsComponent(jc);
      ibmmq.setExceptionListener(new MyExceptionListener());
      ibmmq.setAcknowledgementModeName("AUTO_ACKNOWLEDGE");      
      CamelContext camel = new DefaultCamelContext();
      camel.addComponent("ibmmq", ibmmq);
      try {
         camel.addRoutes(new RouteBuilder() {
            public void configure() {           
               //errorHandler(deadLetterChannel("seda:dead"));
               //errorHandler(loggingErrorHandler(LOGGER));
               //onException(Exception.class).process(new
MyFuncFailureHandler());
               /*onException(Exception.class)
               .process(new Processor() {
                    public void process(Exchange exchange) throws Exception
{
                          Exception exception = (Exception)
exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
                          
                          System.out.println("Found a error");
                    }
               });*/
               from("ibmmq:B2B.B2B.Q.1")               
                  .recipientList().method(MessageRouter.class,
"routeTo").onException(Exception.class).process(new MyFuncFailureHandler());
               
            }
        });
         //TODO try error handler Builder
         //TODO look at unit tests (camel source code)
         camel.setErrorHandlerBuilder(new MyErrHandlerBuilder());
         
         camel.start();         
      } catch (Exception e) {
         System.out.println("Found an error");
         e.printStackTrace();
      } 
      
      ProducerTemplate template = camel.createProducerTemplate();
      for (int i = 1; i < 22; i++) {
         System.out.println("Sending: ");
         template.sendBody("ibmmq:B2B.B2B.Q.1", "Test Message: " + i);
      }
      
      try {
         Thread.sleep(100000);
      } catch (InterruptedException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

      //ConfigurableApplicationContext context = new
FileSystemXmlApplicationContext("c:/spring.xml");
      //context.start();      
      }catch(Exception ep) {
         System.out.println("please catch");
      }
   }
}


--
View this message in context: http://camel.465427.n5.nabble.com/Unable-to-catch-exception-from-Camel-tp4528048p4528137.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message