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

DefaultErrorHandler logs despite "handled true"

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.16.2
    • Fix Version/s: 2.16.3, 2.17.0
    • Component/s: camel-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown
    • Regression:
      Regression

      Description

      The assumption is that handled exceptions will not be propagated any further.
      In version 2.15.5 the test code (from the camel-jetty page) runs fine - but since 2.16.0 the handled exception is propagated to the DefaultErrorHandler which causes ERROR logs for every handled exception.

      I could not find a hint in the release notes - so I think it's a bug.

      public class MyTest extends CamelTestSupport {
      
          @Test
          public void test() throws Exception {
              // using httpclient 4.3.5
              CloseableHttpClient httpclient = HttpClients.createDefault();
              HttpGet httRequest = new HttpGet("http://127.0.0.1:7890/myserver");
              HttpResponse response = httpclient.execute(httRequest);
              assertThat(response.getStatusLine().getStatusCode(), is(500));
          }
      
          @Override
          protected RouteBuilder createRouteBuilder() throws Exception {
              return new RouteBuilder() {
      
                  @Override
                  public void configure() throws Exception {
                      from("jetty://http://localhost:7890/myserver").tracing()
                              // use onException to catch all exceptions and return a custom reply message
                              .onException(Exception.class).handled(true)
                              // create a custom failure response
                              .transform(constant("Dude something went wrong"))
                              // we must remember to set error code 500 as handled(true)
                              // otherwise would let Camel thing its a OK response (200)
                              .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)).end()
                              // now just force an exception immediately
                              .throwException(new IllegalArgumentException("I cannot do this"));
                  }
              };
          }
      }
      

      References from the user-list
      http://camel.465427.n5.nabble.com/onException-block-in-camel-2-16-1-td5777019.html#a5777064

      http://camel.465427.n5.nabble.com/jetty-handled-true-not-working-as-before-td5776774.html

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                davsclaus Claus Ibsen
                Reporter:
                asiepert Andreas Siepert
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: