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

ManagedCamelContextMBean - additional namespaces are removed

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.18.0
    • 2.18.2, 2.19.0
    • camel-core
    • None
    • Novice

    Description

      • Use a specific namespace, declared at CamelContext level, in an Xpath expression of a When
        something like:
        <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="              http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd              http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
            <!--
              The namespace for the camelContext element in Blueprint is 'https://camel.apache.org/schema/blueprint'. Additionally,
              we can also define namespace prefixes we want to use them in the XPath expressions in our CBR.
        
              While it is not required to assign id's to the <camelContext/> and <route/> elements, it is a good idea
              to set those for runtime management purposes (logging, JMX MBeans, ...)
            -->
            <camelContext id="cbr-example-context"
                xmlns="http://camel.apache.org/schema/blueprint" xmlns:order="http://fabric8.com/examples/order/v7">
                <!--
                  When this route is started, it will automatically create the work/cbr/input directory where you can drop the
                  file that need to be processed.
        
                  The <log/> elements are used to add human-friendly business logging statements. They make it easier to see what the
                  route is doing.
        
                  The <choice/> element contains the content based router. The two <when/> clauses use XPath to define the criteria 
                  for entering that part of the route. When the country in the XML message is set to UK or US, the file will be 
                  moved to a directory for that country. The <otherwise/> element ensures that any file that does not meet the 
                  requirements for either of the <when/> elements will be moved to the work/cbr/output/others directory.
                -->
                <route id="cbr-route">
                    <from id="_from1" uri="file:work/cbr/input"/>
                    <log id="_log1" message="Receiving order ${file:name}"/>
                    <choice id="_choice1">
                        <when id="_when1">
                            <xpath id="_xpath1">/order:order/order:customer/order:country = 'UK'</xpath>
                            <log id="_log2" message="Sending order ${file:name} to the UK"/>
                            <to id="_to1" uri="file:work/cbr/output/uk"/>
                        </when>
                        <when id="_when2">
                            <xpath id="_xpath2">/order:order/order:customer/order:country = 'US'</xpath>
                            <log id="_log3" message="Sending order ${file:name} to the US"/>
                            <to id="_to2" uri="file:work/cbr/output/us"/>
                        </when>
                        <otherwise id="_otherwise1">
                            <log id="_log4" message="Sending order ${file:name} to another country"/>
                            <to id="_to3" uri="file:work/cbr/output/others"/>
                        </otherwise>
                    </choice>
                    <log id="_log5" message="Done processing ${file:name}"/>
                </route>
            </camelContext>
        </blueprint>
        
      • Deploy the project
      • Using MBean retrieve dumpRoutesAsXml is providing a route without the additional xml namespace provided xmlns:order="http://fabric8.com/examples/order/v7"
        <?xml version="1.0" encoding="UTF-8"?>
        <routes id="cbr-example-context" xmlns="http://camel.apache.org/schema/spring">
            <route customId="true" id="cbr-route">
                <from customId="true" id="_from1" uri="file:work/cbr/input"/>
                <log customId="true" id="_log1" message="XXXYYY"/>
                <choice customId="true" id="_choice1">
                    <when customId="true" id="_when1">
                        <xpath id="_xpath1">/order:order/order:customer/order:country = 'UK'</xpath>
                        <log customId="true" id="_log2" message="Sending order ${file:name} to the UK"/>
                        <to customId="true" id="_to1" uri="file:work/cbr/output/uk"/>
                    </when>
                    <when customId="true" id="_when2">
                        <xpath id="_xpath2">/order:order/order:customer/order:country = 'US'</xpath>
                        <log customId="true" id="_log3" message="Sending order ${file:name} to the US"/>
                        <to customId="true" id="_to2" uri="file:work/cbr/output/us"/>
                    </when>
                    <otherwise customId="true" id="_otherwise1">
                        <log customId="true" id="_log4" message="Sending order ${file:name} to another country"/>
                        <to customId="true" id="_to3" uri="file:work/cbr/output/others"/>
                    </otherwise>
                </choice>
                <log customId="true" id="_log5" message="Done processing ${file:name}"/>
            </route>
        </routes>
        
      • Then use addOrUpdateRoutesFromXml to upload the exact same xml, you will get exceptions when the When code is invoked:
      Message History
      ---------------------------------------------------------------------------------------------------------------------------------------
      RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
      [cbr-route         ] [cbr-route         ] [file://work/cbr/input                                                         ] [         1]
      [cbr-route         ] [_log1             ] [log                                                                           ] [         0]
      [cbr-route         ] [_choice1          ] [when[xpath{XPath: /order:order/order:customer/order:country = 'UK'}]choice[whe] [         1]
      
      Stacktrace
      ---------------------------------------------------------------------------------------------------------------------------------------
      org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath: /order:order/order:customer/order:country = 'UK'. Reason: javax.xml.xpath.XPathExpressionException: com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: order
      	at org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:769)
      	at org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:155)
      	at org.apache.camel.processor.FilterProcessor.matches(FilterProcessor.java:65)
      	at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:93)
      	at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
      	at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468)
      	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
      	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)
      	at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454)
      	at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:226)
      	at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:190)
      	at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175)
      	at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
      	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      Caused by: javax.xml.xpath.XPathExpressionException: com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: order
      	at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:400)
      	at org.apache.camel.builder.xml.XPathBuilder.createXPathExpression(XPathBuilder.java:958)
      	at org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:767)
      	... 21 more
      Caused by: com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: order
      	at com.sun.org.apache.xpath.internal.compiler.XPathParser.errorForDOM3(XPathParser.java:657)
      	at com.sun.org.apache.xpath.internal.compiler.Lexer.mapNSTokens(Lexer.java:642)
      	at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:269)
      	at com.sun.org.apache.xpath.internal.compiler.Lexer.tokenize(Lexer.java:100)
      	at com.sun.org.apache.xpath.internal.compiler.XPathParser.initXPath(XPathParser.java:114)
      	at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:180)
      	at com.sun.org.apache.xpath.internal.XPath.<init>(XPath.java:268)
      	at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.compile(XPathImpl.java:392)
      

      Attachments

        Issue Links

          Activity

            People

              jamesnetherton James Netherton
              aurelien.pupier Aurelien Pupier
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: