camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hendrik S." <hendr...@spohr.vol.at>
Subject Re: Camel 1.2 - CatchProcessor not working? (New Bug!)
Date Sat, 27 Oct 2007 10:02:53 GMT

The patch is working, but I found another bug: assume the following route:

try
  dosomething
  try
    dosomethingBAD
    catch
      processInnercatch
  dosomethingmore
  catch
    processOutterCatch

When "dosomethingBAD" throws an exception the exception is handled by
"processInnercatch" and "processOuttercatch" as well. :(

Again, I've written an unit test for this (this time I'm using mock endpoint
;) )

public class TestNestedTryCatch {

  static public class MyBean {
  
    public void process( Object obj ) {
      if( obj instanceof Integer )
        Logger.getLogger( TestNestedTryCatch.MyBean.class ).info(
"processing Integer: " + obj );
      else
        throw new IllegalArgumentException( "Need an Integer, please!" );
    }
    
  }
  
  static public class MyOtherBean {
    
    public void process( Object obj ) {
      Logger.getLogger( TestNestedTryCatch.MyBean.class ).info( "processing:
" + obj );
    }
    
  }

  private CamelContext context;

  private MockEndpoint out;
  private MockEndpoint beforeInnerTry;
  private MockEndpoint afterInnerTry;
  private MockEndpoint errorInner;
  private MockEndpoint errorOutter;

  private Endpoint<Exchange> in;
  
  @Before
  @SuppressWarnings("unchecked")
  public void setUp() throws Exception {
    Registry registry = new Registry() {

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

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

    context = new DefaultCamelContext( registry );
    
    in = context.getEndpoint( "direct:in" );
    
    out = context.getEndpoint( "mock:out", MockEndpoint.class );
    beforeInnerTry = context.getEndpoint( "mock:before_inner_try",
MockEndpoint.class );
    afterInnerTry = context.getEndpoint( "mock:after_inner_try",
MockEndpoint.class );
    errorInner = context.getEndpoint( "mock:error_inner", MockEndpoint.class
);
    errorOutter = context.getEndpoint( "mock:error_outter",
MockEndpoint.class );

    final MyBean myBean = new MyBean();
    final MyOtherBean otherBean = new MyOtherBean();
    
    context.addRoutes( new RouteBuilder() {

      @Override
      public void configure() throws Exception {
        RouteType s = from(in);
        
        TryType try1 = s.tryBlock();
        TryType try2 = try1.to(beforeInnerTry).tryBlock();
        try2.bean( myBean ).to( out );
        try2.handle( java.lang.Exception.class ).bean( otherBean ).to(
errorInner );
        try1.to( afterInnerTry );
        try1.handle( java.lang.Exception.class ).bean( otherBean ).to(
errorOutter );
      }
      
    } );

    context.start();
  }
  
  @Test
  public void testNoException() throws Exception {
    
    CamelTemplate<Exchange> t = new CamelTemplate<Exchange>(context);
    
    out.expectedMessageCount( 1 );
    beforeInnerTry.expectedMessageCount( 1 );
    afterInnerTry.expectedMessageCount( 1 );
    errorOutter.expectedMessageCount( 0 );
    errorInner.expectedMessageCount( 0 );
    
    t.sendBody( in, Integer.valueOf( 10 ) );
    
    out.assertIsSatisfied();
    beforeInnerTry.assertIsSatisfied();
    afterInnerTry.assertIsSatisfied();
    errorOutter.assertIsSatisfied();
    errorInner.assertIsSatisfied();
    
  }

  @Test
  public void testExceptionThrown() throws Exception {
    
    CamelTemplate<Exchange> t = new CamelTemplate<Exchange>(context);
    
    out.expectedMessageCount( 0 );
    beforeInnerTry.expectedMessageCount( 1 );
    afterInnerTry.expectedMessageCount( 1 );
    errorOutter.expectedMessageCount( 0 );
    errorInner.expectedMessageCount( 1 );
    
    t.sendBody( in, "This will fail..." );
    
    out.assertIsSatisfied();
    beforeInnerTry.assertIsSatisfied();
    errorInner.assertIsSatisfied();
    errorOutter.assertIsSatisfied(); // fails
    afterInnerTry.assertIsSatisfied(); // fails
    
  }
}

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


Mime
View raw message