Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-2935

Broken failure reporting via DefaultProucerTemplate.asyncCallback and Synchronization.onFailure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.0
    • 2.4.0
    • camel-core
    • None

    Description

      The recent change in ProducerCache.send

      ProducerCache.java
          public void send(Endpoint endpoint, Exchange exchange) {
              try {
                  sendExchange(endpoint, null, null, exchange);
                  // RECENT CHANGE HERE:
                  // ensure that CamelExecutionException is always thrown
                  if (exchange.getException() != null) {
                      exchange.setException(wrapCamelExecutionException(exchange, exchange.getException()));
                  }
              } catch (Exception e) {
                  throw wrapCamelExecutionException(exchange, e);
              }
          }
      

      that throws a CamelExecutionException if exchange.getException is not null, makes it impossible for DefaultProducerTemplate.asyncCallback to report failures (other than fault messages) asynchronously via Synchronization.onFailure

      DefaultProducerTemplate.java
          public Future<Exchange> asyncCallback(final Endpoint endpoint, final Exchange exchange, final Synchronization onCompletion) {
              Callable<Exchange> task = new Callable<Exchange>() {
                  public Exchange call() throws Exception {
      
                      // FIXME: exception is thrown in Camel 2.4 where a normal return with answer.getException != null was done in Camel 2.3
                      Exchange answer = send(endpoint, exchange);
      
                      if (answer.isFailed()) {
                          onCompletion.onFailure(answer);
                      } else {
                          // ...
                      }
                      return answer;
                  }
              };
              // ...
          }
      

      This was working in Camel 2.3 (but unfortunately there wasn't any test case for it). I attached a patch for DefaultProducerTemplateAsyncTest that demonstrates the problem. I didn't commit a fix yet because I'm unsure at the moment about the best way to fix that. Of course I tried a naive fix in the DefaultProducerTemplate.asyncCallback methods which causes the test (in the patch) to pass but I'd like to hear other opinions before I continue.

      Attachments

        1. on-failure.patch
          5 kB
          Martin Krasser

        Activity

          People

            davsclaus Claus Ibsen
            mrt1nz Martin Krasser
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: