Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-21505

Neither any custom exchange formatter, nor the "logMask" parameter are considered when dumping an Exception on the logs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not a Bug
    • Icon: Major Major
    • None
    • fuse-7.11.1-GA
    • Camel
    • None
    • False
    • Hide

      None

      Show
      None
    • False
    • User Experience
    • Todo
    • Workaround Exists
    • Hide

      To configure a formatter for an error handler, add this to the blueprint.xml:

      <bean id="myFormatter" class="org.example.formatter.MyExchangeFormatter" />
      <bean id="myRedeliveryPolicy" class="org.apache.camel.processor.RedeliveryPolicy">
          <property name="exchangeFormatterRef" value="myFormatter"/>
      </bean>
      <bean id="myErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
          <property name="deadLetterUri" value="mock:dead"/>
          <property name="redeliveryPolicy" ref="myRedeliveryPolicy"/>
      </bean>
      <camelContext id=...
          <route id="test" errorHandlerRef="myErrorHandler">
          ...
          </route>
      </camelContext>
      
      Show
      To configure a formatter for an error handler, add this to the blueprint.xml: <bean id= "myFormatter" class= "org.example.formatter.MyExchangeFormatter" /> <bean id= "myRedeliveryPolicy" class= "org.apache.camel.processor.RedeliveryPolicy" > <property name= "exchangeFormatterRef" value= "myFormatter" /> </bean> <bean id= "myErrorHandler" class= "org.apache.camel.builder.DeadLetterChannelBuilder" > <property name= "deadLetterUri" value= "mock:dead" /> <property name= "redeliveryPolicy" ref= "myRedeliveryPolicy" /> </bean> <camelContext id=... <route id= "test" errorHandlerRef= "myErrorHandler" > ... </route> </camelContext>
    • Hide

      1. Unzip "jira-attached.zip"

      2. Go to the unzipped directory, compile and install
      $ mvn clean install

      3. Unzip and start Fuse 7.11 for Karaf

      4. Install the bundle via Fuse Karaf CLI

      karaf> install -s mvn:com.mycompany/camel-blueprint-cbr-1/1.0.0-SNAPSHOT

      5. Check the logs

      karaf> log:tail

      Show
      1. Unzip "jira-attached.zip" 2. Go to the unzipped directory, compile and install $ mvn clean install 3. Unzip and start Fuse 7.11 for Karaf 4. Install the bundle via Fuse Karaf CLI karaf> install -s mvn:com.mycompany/camel-blueprint-cbr-1/1.0.0-SNAPSHOT 5. Check the logs karaf> log:tail
    • Important
    • Very Likely

      I need to mask some sensitive information on the logs, and it works well if I use the Camel context's "logMask" option, or a custom exchange formatted, as seen below:

       

      // code placeholder
      13:12:27.907 INFO [Camel (cbr-example-context) thread #3 - timer://foo] Exchange[, Id: ID-laptop-t14s-1686333907675-2-1, ExchangePattern: InOnly, Properties: CamelCreatedTimestamp: Fri Jun 09 13:12:27 COT 2023CamelExternalRedelivered: falseCamelMessageHistory: [DefaultMessageHistory[routeId=test, node=setBody1], DefaultMessageHistory[routeId=test, node=process3], DefaultMessageHistory[routeId=test, node=to2]]CamelTimerCounter: 1CamelTimerFiredTime: Fri Jun 09 13:12:27 COT 2023CamelTimerName: fooCamelTimerPeriod: 1000CamelToEndpoint: log://exchange?multiline=true&showAll=true
      , Headers: breadcrumbId: ID-laptop-t14s-1686333907675-2-1firedTime: Fri Jun 09 13:12:27 COT 2023Password: ***Username: ***
      , BodyType: String, Body: HHH<node> <password>xxxxx</password> </node>, Out: null:  

      However, when an Exception is dumped, neither the custom exchange formatter nor the "logMask" parameter, are considered when dumping an Exception on the logs, as seen below, as none of the sensitive parameters are masked:

      13:12:27.908 INFO [Camel (cbr-example-context) thread #3 - timer://foo] === Boom? ===13:12:27.908 INFO [Camel (cbr-example-context) thread #3 - timer://foo] 1 exchangeFormatter --> org.apache.camel.processor.DefaultExchangeFormatter13:12:27.909 ERROR [Camel (cbr-example-context) thread #3 - timer://foo] Failed delivery for (MessageId: ID-laptop-t14s-1686333907675-2-2 on ExchangeId: ID-laptop-t14s-1686333907675-2-1). Exhausted after delivery attempt: 1 caught: java.lang.Exception: Boom!
      HERE PAL!
      Message History
      -----------------------------------------------------------------------------------------------------------------------------------RouteId              ProcessorId          Processor                                                                        Elapsed (ms)[test              ] [test              ] [timer://foo?delay=2000&repeatCount=1                                          ] [        19][test              ] [setBody1          ] [setBody[constant{HELLO!}]                                                     ] [         2][test              ] [process3          ] [ref:passwordInjector                                                          ] [         0][test              ] [to2               ] [log:exchange?showAll=true&multiline=true                                      ] [        14][test              ] [process4          ] [ref:throwException                                                            ] [         0]
      Exchange
      ---------------------------------------------------------------------------------------------------------------------------------------
      Exchange[
          Id                  ID-laptop-t14s-1686333907675-2-1
          ExchangePattern     InOnly
          Headers             {breadcrumbId=ID-laptop-t14s-1686333907675-2-1, CamelRedelivered=false, CamelRedeliveryCounter=0, firedTime=Fri Jun 09 13:12:27 COT 2023, Password=thepassword, Username=TheUsername}
          BodyType            String
          Body                <node> <password>abc</password> </node>
      ]
      Stacktrace---------------------------------------------------------------------------------------------------------------------------------------java.lang.Exception: Boom! 

      The following code on class "org/apache/camel/processor/RedeliveryErrorHandler.java", seems to be ignoring the custom formater:

      if (!shouldRedeliver && data.currentRedeliveryPolicy.isLogExhaustedMessageHistory()) {
          // only use the exchange formatter if we should log exhausted message body (and if using a custom formatter then always use it)
          ExchangeFormatter formatter = customExchangeFormatter
              ? exchangeFormatter : (data.currentRedeliveryPolicy.isLogExhaustedMessageBody() || camelContext.isLogExhaustedMessageBody() ? exchangeFormatter : null);
          log.info("1 exchangeFormatter --> " + exchangeFormatter.getClass().getName());
          String routeStackTrace = MessageHelper.dumpMessageHistoryStacktrace(exchange, formatter, e != null && logStackTrace);
          if (routeStackTrace != null) {
              msg = msg + "\n" + routeStackTrace;
          }
      }
       

      The log.info statement shows the following: 

      1 exchangeFormatter --> org.apache.camel.processor.DefaultExchangeFormatter

      The full log is on attached file: "jira-fuse.log"

        1. jira-fuse.log
          6 kB
          Alfredo Narvaez

              rnetuka@redhat.com Radovan Netuka
              rhn-support-anarvaez Alfredo Narvaez
              Tomas Veskrna Tomas Veskrna
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: