Camel
  1. Camel
  2. CAMEL-4799

Umbrella ticket for XPath improvements

    Details

    • Type: Improvement Improvement
    • 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
    • Estimated Complexity:
      Unknown

      Description

      As agreed with Claus Ibsen over IRC, this ticket will group several XPath language improvements as sub-tasks. At least the following will be included:

      • Balance up the XPath Java DSL with Spring DSL, namely to be able to specify Saxon as the XPathFactory from Spring DSL
      • Crank up the logging for more verbosity when dealing with namespaces and during the evaluation process
      • Improve namespace handling to make it more intelligent (e.g. if the XML doc has a default namespace and no other namespaces, and the XPath expression doesn't specify one, assume that the expression should be evaluated against the default namespace)
      • Result QName definition to work with Saxon Object Model and XPath 2 constructs which are not embraced by JAXP (e.g. sequences), and possibly some type converters (still under evaluation)
      • Balance up the Scala DSL if necessary

        Activity

        Hide
        Raúl Kripalani added a comment - - edited

        After analysing the possibility of making namespace handling more intelligent so that Camel does some magic behind the scenes for you, I think it is not a good idea. It can easily lead to a scenario where XPath expression would no longer be deterministic and could cause more woes than being useful. I considered various possibilities:

        • Evaluating the XPath expression within the default namespace -> but JAXP doesn't provide a mechanism for doing so
        • Automatically discovering the default namespace and setting it in the XPath expression -> but JAXP doesn't provide a mechanism for doing so
        • Automatically "learning" [prefix -> namespace] bindings from messages, but prefixes are volatile and they can change with each message

        So instead, I decided to create an option that dumps to LOG all [prefix -> namespace] mappings in the incoming message, to facilitate debugging. Additionally, every time a new XPath expression is added to the pool, the NamespaceContext is dumped too. With this, the user can compare the namespaces known to the XPath exp. with the incoming one and easily spot mistakes. This is documented in CAMEL-4852.

        Show
        Raúl Kripalani added a comment - - edited After analysing the possibility of making namespace handling more intelligent so that Camel does some magic behind the scenes for you, I think it is not a good idea. It can easily lead to a scenario where XPath expression would no longer be deterministic and could cause more woes than being useful. I considered various possibilities: Evaluating the XPath expression within the default namespace -> but JAXP doesn't provide a mechanism for doing so Automatically discovering the default namespace and setting it in the XPath expression -> but JAXP doesn't provide a mechanism for doing so Automatically "learning" [prefix -> namespace] bindings from messages, but prefixes are volatile and they can change with each message So instead, I decided to create an option that dumps to LOG all [prefix -> namespace] mappings in the incoming message, to facilitate debugging. Additionally, every time a new XPath expression is added to the pool, the NamespaceContext is dumped too. With this, the user can compare the namespaces known to the XPath exp. with the incoming one and easily spot mistakes. This is documented in CAMEL-4852 .
        Hide
        Claus Ibsen added a comment -

        Raul I have granted your account karma to assign tickets.

        I will look into getting this patch on the trunk.

        Show
        Claus Ibsen added a comment - Raul I have granted your account karma to assign tickets. I will look into getting this patch on the trunk.
        Hide
        Claus Ibsen added a comment -

        Raul, you may want to read about checkstyle, and how to check for that.
        http://camel.apache.org/building.html

        As your patch have some checkstyle issues, which I will fix before committing the patch.

        Show
        Claus Ibsen added a comment - Raul, you may want to read about checkstyle, and how to check for that. http://camel.apache.org/building.html As your patch have some checkstyle issues, which I will fix before committing the patch.
        Hide
        Claus Ibsen added a comment -

        I have applied the patch with a few changes

        • fixed CS
        • moved the spring tests to camel-saxon as this component uses the saxon xpath engine
        Show
        Claus Ibsen added a comment - I have applied the patch with a few changes fixed CS moved the spring tests to camel-saxon as this component uses the saxon xpath engine
        Hide
        Claus Ibsen added a comment -

        I wonder if we should log at INFO level instead of TRACE? The reason is that it makes it easier for Camel ends to use, as all they have to do is to enable the trace namespace option, and it will get logged.

        Now they also need to enable TRACE logging option which for some end users is not so easy. For example they do not know the logger name etc.

        And maybe we should rename the option from traceNamespaces, to logNamespaces ?

        Show
        Claus Ibsen added a comment - I wonder if we should log at INFO level instead of TRACE? The reason is that it makes it easier for Camel ends to use, as all they have to do is to enable the trace namespace option, and it will get logged. Now they also need to enable TRACE logging option which for some end users is not so easy. For example they do not know the logger name etc. And maybe we should rename the option from traceNamespaces, to logNamespaces ?
        Hide
        Raúl Kripalani added a comment -

        Ok. Since you have already applied the patch, I'll provide a new patch based on r1227211.

        Show
        Raúl Kripalani added a comment - Ok. Since you have already applied the patch, I'll provide a new patch based on r1227211.
        Hide
        Raúl Kripalani added a comment -

        Patch attached based on HEAD to:

        • change the name of traceNamespaces to logNamespaces
        • output discovered namespaces on INFO level
        • output namespace context of expression on INFO level if logNamespaces is enabled; otherwise on TRACE level
        Show
        Raúl Kripalani added a comment - Patch attached based on HEAD to: change the name of traceNamespaces to logNamespaces output discovered namespaces on INFO level output namespace context of expression on INFO level if logNamespaces is enabled; otherwise on TRACE level
        Hide
        Claus Ibsen added a comment -

        Thanks for the rename patch. Mind that camel-saxon should be changed as well, where we have some unit tests also. I will fix that as well when applying the patch.

        We then need some details in the wiki documentation for the xpath page.

        Show
        Claus Ibsen added a comment - Thanks for the rename patch. Mind that camel-saxon should be changed as well, where we have some unit tests also. I will fix that as well when applying the patch. We then need some details in the wiki documentation for the xpath page.
        Hide
        Claus Ibsen added a comment -

        The rename patch has been applied to trunk. Thanks Raul.

        Show
        Claus Ibsen added a comment - The rename patch has been applied to trunk. Thanks Raul.
        Hide
        Claus Ibsen added a comment -

        Raul, do you mind adding a few notes about this new logNamespaces to the xpath wiki page?
        http://camel.apache.org/xpath

        Show
        Claus Ibsen added a comment - Raul, do you mind adding a few notes about this new logNamespaces to the xpath wiki page? http://camel.apache.org/xpath

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development