Camel
  1. Camel
  2. CAMEL-4799 Umbrella ticket for XPath improvements
  3. CAMEL-4852

Extra logging when evaluating XPath expressions to help address namespace issues

    Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.10.0
    • Component/s: camel-core, camel-spring
    • Labels:
      None
    • Patch Info:
      Patch Available
    • Estimated Complexity:
      Unknown

      Description

      Create a new option traceNamespaces which audits/analyses/extracts all namespaces present in the incoming message and logs them out, in order to help detect potential issues with namespace referencing in XPath expressions.

      Since JAXP doesn't provide any mechanism to discover namespaces, this behaviour should be implemented with an XPath query.
      To be used only in development mode, as the entire XML document will be traversed in order to discover the [prefix -> namespace URI/URL] pairs.

      The default namespace should be discovered and output too.

      For each message, if the traceNamespaces option is active, Camel should dump a line similar to the following:
      E.g.:

      {xmlns:nsb=[http://namespaceb.net], xmlns:nsa=[http://namespacec.net, http://namespacea.net], DEFAULT=[http://defaultNamespace.net]}

      If a prefix is declared multiple times, two things can happen:

      • The prefix is always bound to the same namespace
      • The prefix is bound to different namespaces in different parts of the XML document

      In the first case, the duplicate should be eliminated in the log line. In the second case, the prefix should appear bound to all unique namespaces (see prefix nsa in the above example).

      Additionally, when a new XPath expression / predicate is initialised, Camel should dump the NamespaceContext of the expression, so that the user can then compare the namespaces known by the expression against the namespaces that exist in the incoming message.

        Activity

        Raúl Kripalani created issue -
        Raúl Kripalani made changes -
        Field Original Value New Value
        Description Create a new option {{traceNamespaces}} which audits/analyses/extracts all namespaces present in the incoming message and logs them out, in order to help detect potential issues with namespace referencing in XPath expressions.

        Since JAXP doesn't provide any mechanism to discover namespaces, this behaviour should be implemented with an XPath query.
        To be used only in development mode, as the entire XML document will be traversed in order to discover the [prefix -> namespace URI/URL] pairs.

        The default namespace should be discovered and output too.

        For each message, if the traceNamespaces option is active, Camel should dump a line similar to the following:
        E.g.: {xmlns:nsb=[http://namespaceb.net], xmlns:nsa=[http://namespacec.net, http://namespacea.net], DEFAULT=[http://defaultNamespace.net]}

        If a prefix is declared multiple times, two things can happen:
        * The prefix is always bound to the same namespace
        * The prefix is bound to different namespaces in different parts of the XML document

        In the first case, the duplicate should be eliminated in the log line. In the second case, the prefix should appear bound to all unique namespaces (see prefix nsa in the above example).

        Additionally, when a new XPath expression / predicate is initialised, Camel should dump the NamespaceContext of the expression, so that the user can then compare the namespaces known by the expression against the namespaces that exist in the incoming message.
        Hide
        Raúl Kripalani added a comment -

        Patch attached in CAMEL-4799.

        All new logging output in TRACE level.

        Namespace auditing in incoming message can be activated in Spring DSL by setting the traceNamespaces attribute to true (traceNamespace=true) or in Java DSL by using .traceNamespaces().

        Tricky part was the unit test. To verify that the logging occurs, I mocked out the SLF4j Logger using EasyMock and replaced the private static final LOG variable in XPathBuilder via Java Reflection. All this is done in org.apache.camel.builder.xml.XPathTransformTest.

        Show
        Raúl Kripalani added a comment - Patch attached in CAMEL-4799 . All new logging output in TRACE level. Namespace auditing in incoming message can be activated in Spring DSL by setting the traceNamespaces attribute to true (traceNamespace=true) or in Java DSL by using .traceNamespaces(). Tricky part was the unit test. To verify that the logging occurs, I mocked out the SLF4j Logger using EasyMock and replaced the private static final LOG variable in XPathBuilder via Java Reflection. All this is done in org.apache.camel.builder.xml.XPathTransformTest .
        Raúl Kripalani made changes -
        Patch Info Patch Available [ 10042 ]
        Raúl Kripalani made changes -
        Assignee Raul Kripalani [ raulvk ]
        Claus Ibsen made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Raúl Kripalani added a comment -

        Documentation added on the XPath Expression Language page.

        Show
        Raúl Kripalani added a comment - Documentation added on the XPath Expression Language page.

          People

          • Assignee:
            Raúl Kripalani
            Reporter:
            Raúl Kripalani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development