camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hendrik S." <hendr...@spohr.vol.at>
Subject Camel 1.2 - CatchProcessor not working?
Date Thu, 25 Oct 2007 12:09:05 GMT

Hi,

We have used camel 1.1 for our project and wanted to upgrade to 1.2 (We were
missing the @Headers Tag in 1.1).

But we found a bug in the try - catch handler: I the catch block is a
pipline, the pipline (in the catch block) detects that the exchange has
failed and aborts the catch handler. :(

I've worte a simple unit test to demonstrate this:

public class TestTryCatch {

  public class MyBean {
  
    public void process( Object obj ) {
      if( obj instanceof Integer )
        Logger.getLogger( TestTryCatch.MyBean.class ).info( "processing
Integer: " + obj );
      else
        throw new IllegalArgumentException( "Need an Integer, please!" );
    }
    
  }
  
  public class MyOtherBean {
    
    public void process( Object obj ) {
      Logger.getLogger( TestTryCatch.MyBean.class ).info( "processing: " +
obj );
    }
    
  }
  
  @Test
  public void test() throws Exception {
    Registry registry = new Registry() {

      public Object lookup( String name ) {
        return null;
      }

      public <T> T lookup( String name, Class<T> type ) {
        return null;
      }
      
    };

    CamelContext cc = new DefaultCamelContext( registry );
    
    
    @SuppressWarnings("unchecked")
    final Endpoint<Exchange> in = cc.getEndpoint( "direct:in" );
    @SuppressWarnings("unchecked")
    final Endpoint<Exchange> out = cc.getEndpoint( "log:out" );
    @SuppressWarnings("unchecked")
    final Endpoint<Exchange> error = cc.getEndpoint( "log:error" );
    
    final MyBean myBean = new MyBean();
    final MyOtherBean otherBean = new MyOtherBean();
    
    cc.addRoutes( new RouteBuilder() {

      @Override
      public void configure() throws Exception {
        RouteType s = from(in);
        
        TryType t = s.tryBlock();
        t.bean( myBean ).to( out );
        t.handle( java.lang.Exception.class ).bean( otherBean ).to( error );
      }
      
    } );

    cc.start();
    
    CamelTemplate<Exchange> t = new CamelTemplate<Exchange>(cc);
    t.sendBody( in, Integer.valueOf( 10 ) );
    
    t.sendBody( in, "This will fail..." ); // the catch handler will not
process this correctly!
    
    Thread.sleep( 1000 );
    
  }
  
}

-- 
View this message in context: http://www.nabble.com/Camel-1.2---CatchProcessor-not-working--tf4690438s22882.html#a13405439
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message