Camel
  1. Camel
  2. CAMEL-5156

simple language is not working in onException policy (for example retryWhile clause).

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Not a Problem
    • Affects Version/s: 2.9.1
    • Fix Version/s: 2.10.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      The bug was checked against 2.9.1 version of Camel.

      The simple language expressions are not calculated properly within onException clause.

      The route below only works as expected because I copy the the exchange and remove information about the exception. If the original exchange with exception information is used with simple language then the exception will be rethrown during (at the end?) the calculation of simple expression.
      If I copy the exchange and remove the exception information then the unit tests are passing nicely and the file with proper content is created, so simple language expression can be calculated properly for the object being routed.

      from("direct:toPropertyFileAvoidFixingUnfixable")
                  .onException(NullPointerException.class)
                  .onRedelivery(new NullRegistrationDateProcessor())
                  .handled(true)
                  .retryWhile(new Predicate() {
                      public boolean matches(Exchange exchange) {
      
                          Predicate composite = PredicateBuilder.and(PredicateBuilder.isNull(simple("${body?.getRegistrationDate}")),
                                  PredicateBuilder.isNotNull(simple("${body?.getBirthdate}")));
      
                          // Exchange with exception will make computation of simple predicate fail.
                          Exchange local = exchange.copy();
                          local.setException(null);
      
                          boolean result = composite.matches(local);
      
                          return result;
      
                      }
                  })
                  .end()
                  .setHeader(Exchange.FILE_NAME, simple("${body.firstname}.${body.surname}"))
                  .bean(RegistrationToPropertiesBean.class, "convert")
                  .to("file://" + outFolder);
      

      It is related to the issue https://issues.apache.org/jira/browse/CAMEL-4513. My guess is that the problem is present for many other places where simple language can be used within onException part of the route definition. Not just retryWhile and custom predicate used within retryWhile.

        Issue Links

          Activity

          Claus Ibsen made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.10.0 [ 12317612 ]
          Resolution Not A Problem [ 8 ]
          Hide
          Claus Ibsen added a comment -

          This works as designed. When you work with a predicate with the Exchange you get the raw details. And some people want to access the exception using getException etc.

          Show
          Claus Ibsen added a comment - This works as designed. When you work with a predicate with the Exchange you get the raw details. And some people want to access the exception using getException etc.
          Hide
          Claus Ibsen added a comment -

          What do you do in your processor: NullRegistrationDateProcessor

          Show
          Claus Ibsen added a comment - What do you do in your processor: NullRegistrationDateProcessor
          Hide
          Radoslaw Szymanek added a comment -

          It may be that at multiple places within onException part of the route definition that using simple language is affected by this bug.

          Show
          Radoslaw Szymanek added a comment - It may be that at multiple places within onException part of the route definition that using simple language is affected by this bug.
          Radoslaw Szymanek made changes -
          Link This issue is related to CAMEL-4513 [ CAMEL-4513 ]
          Radoslaw Szymanek made changes -
          Fix Version/s 2.9.0 [ 12316374 ]
          Fix Version/s 2.8.3 [ 12318649 ]
          Affects Version/s 2.9.1 [ 12319191 ]
          Priority Minor [ 4 ] Major [ 3 ]
          Description The bug occured in the 2.6.0 version of Camel I'm using. I haven't test it against the latest version but I've checked the sources and it doesn't seem to have change since.

          Given a camel route, with a onException clause like this :

          {code}
          this.onException(MyException.class)
              .onWhen(simple("${exception.myExceptionInfo.aValue} == true"))
              ...
          {code}

          MyException is a customed exception like this :

          {code:title=MyException.java}
          public class MyException extends Exception {
             ....
             public MyExceptionInfo getMyExceptionInfo() {
               ...
             }
          }
          {code}

          What I've observed is that when BeanExpression.OgnlInvokeProcessor.process iterate through the methods to calls, it does :
          {code}
                          // only invoke if we have a method name to use to invoke
                          if (methodName != null) {
                              InvokeProcessor invoke = new InvokeProcessor(holder, methodName);
                              invoke.process(resultExchange);

                              // check for exception and rethrow if we failed
                              if (resultExchange.getException() != null) {
                                  throw new RuntimeBeanExpressionException(exchange, beanName, methodName, resultExchange.getException());
                              }

                              result = invoke.getResult();
                          }
          {code}

          It successfully invoke the method : invoke.process(resultExchange);
          But it checks for exception in the exchange. Since we are in an exception clause, there is an actual exception (thrown by the application, but unrelated with the expression language search) and it fails

          There is a simple workaround for that : writing his own predicate class to test wanted conditions
          The bug was checked against 2.9.1 version of Camel.

          The simple language expressions are not calculated properly within onException clause.

          The route below only works as expected because I copy the the exchange and remove information about the exception. If the original exchange with exception information is used with simple language then the exception will be rethrown during (at the end?) the calculation of simple expression.
          If I copy the exchange and remove the exception information then the unit tests are passing nicely and the file with proper content is created, so simple language expression can be calculated properly for the object being routed.

          {code}
          from("direct:toPropertyFileAvoidFixingUnfixable")
                      .onException(NullPointerException.class)
                      .onRedelivery(new NullRegistrationDateProcessor())
                      .handled(true)
                      .retryWhile(new Predicate() {
                          public boolean matches(Exchange exchange) {

                              Predicate composite = PredicateBuilder.and(PredicateBuilder.isNull(simple("${body?.getRegistrationDate}")),
                                      PredicateBuilder.isNotNull(simple("${body?.getBirthdate}")));

                              // Exchange with exception will make computation of simple predicate fail.
                              Exchange local = exchange.copy();
                              local.setException(null);

                              boolean result = composite.matches(local);

                              return result;

                          }
                      })
                      .end()
                      .setHeader(Exchange.FILE_NAME, simple("${body.firstname}.${body.surname}"))
                      .bean(RegistrationToPropertiesBean.class, "convert")
                      .to("file://" + outFolder);
          {code}

          It is related to the issue https://issues.apache.org/jira/browse/CAMEL-4513. My guess is that the problem is present for many other places where simple language can be used within onException part of the route definition. Not just retryWhile and custom predicate used within retryWhile.
          Radoslaw Szymanek made changes -
          Field Original Value New Value
          Link This issue is a clone of CAMEL-4513 [ CAMEL-4513 ]
          Radoslaw Szymanek created issue -

            People

            • Assignee:
              Claus Ibsen
              Reporter:
              Radoslaw Szymanek
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development