You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by benshort <be...@benshort.co.uk> on 2009/02/10 20:51:52 UTC

DSL and XPath

Hi, 

Can anyone help we get the following working.

JDK 1.6
Camel 1.5.0

Test case

@Test
    public void xpath() throws Exception {

        final CamelContext context = new DefaultCamelContext();

        context.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {

                from("seda:test")
                        .choice()
                            .when().xpath("in:header('op') =
'out").to("stream:out")
                            .when().xpath("in:header('op') =
'err").to("stream:err")
                        .end();
            }
        });

        context.start();

        ProducerTemplate template = context.createProducerTemplate();

        template.sendBodyAndHeader("seda:test", "body", "op", "out");

        context.stop();        
    }


Exception thrown

2009-02-10 19:47:13,156: ERROR [seda:test thread:1] Failed delivery for
exchangeId: ID-LXP-0001/4547-1234295232453/0-0. On delivery attempt: 0
caught: org.apache.camel.RuntimeCamelException:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
org.apache.camel.RuntimeCamelException: org.xml.sax.SAXParseException:
Content is not allowed in prolog.
	at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:441)
	at
org.apache.camel.impl.converter.InstanceMethodTypeConverter.convertTo(InstanceMethodTypeConverter.java:57)
	at
org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(DefaultTypeConverter.java:94)
	at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:65)
	at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:51)
	at
org.apache.camel.builder.xml.XPathBuilder.getDocument(XPathBuilder.java:528)
	at
org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:420)
	at org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:98)
	at org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:63)
	at
org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:47)
	at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:75)
	at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:172)
	at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:93)
	at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:63)
	at
org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:47)
	at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:69)
	at java.lang.Thread.run(Thread.java:619)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
	at
com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
	at
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
	at
org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:505)
	at
org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:493)
	at
org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:516)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:437)
	... 16 more

-- 
View this message in context: http://www.nabble.com/DSL-and-XPath-tp21939519s22882p21939519.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: DSL and XPath

Posted by Jon Anstey <ja...@gmail.com>.
When using XPath, the message body must be valid XML. You can modify your
message body from "body" to "<body/>" (or something like that) to get around
this error. Or you can use some other expression language that doesn't
require XML messages to do the checking (Java bean, EL, Groovy, etc.)

On Tue, Feb 10, 2009 at 4:21 PM, benshort <be...@benshort.co.uk> wrote:

>
> Hi,
>
> Can anyone help we get the following working.
>
> JDK 1.6
> Camel 1.5.0
>
> Test case
>
> @Test
>    public void xpath() throws Exception {
>
>        final CamelContext context = new DefaultCamelContext();
>
>        context.addRoutes(new RouteBuilder() {
>            public void configure() throws Exception {
>
>                from("seda:test")
>                        .choice()
>                            .when().xpath("in:header('op') =
> 'out").to("stream:out")
>                            .when().xpath("in:header('op') =
> 'err").to("stream:err")
>                        .end();
>            }
>        });
>
>        context.start();
>
>        ProducerTemplate template = context.createProducerTemplate();
>
>        template.sendBodyAndHeader("seda:test", "body", "op", "out");
>
>        context.stop();
>    }
>
>
> Exception thrown
>
> 2009-02-10 19:47:13,156: ERROR [seda:test thread:1] Failed delivery for
> exchangeId: ID-LXP-0001/4547-1234295232453/0-0. On delivery attempt: 0
> caught: org.apache.camel.RuntimeCamelException:
> org.xml.sax.SAXParseException: Content is not allowed in prolog.
> org.apache.camel.RuntimeCamelException: org.xml.sax.SAXParseException:
> Content is not allowed in prolog.
>        at
> org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:441)
>        at
>
> org.apache.camel.impl.converter.InstanceMethodTypeConverter.convertTo(InstanceMethodTypeConverter.java:57)
>        at
>
> org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(DefaultTypeConverter.java:94)
>        at
> org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:65)
>        at
> org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:51)
>        at
>
> org.apache.camel.builder.xml.XPathBuilder.getDocument(XPathBuilder.java:528)
>        at
> org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:420)
>        at
> org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:98)
>        at
> org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:63)
>        at
> org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:47)
>        at
>
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:75)
>        at
>
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:172)
>        at
>
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:93)
>        at
>
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:63)
>        at
>
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:47)
>        at
> org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:69)
>        at java.lang.Thread.run(Thread.java:619)
> Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
>        at
>
> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
>        at
>
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
>        at
>
> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:505)
>        at
>
> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:493)
>        at
>
> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:516)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:597)
>        at
> org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:437)
>        ... 16 more
>
> --
> View this message in context:
> http://www.nabble.com/DSL-and-XPath-tp21939519s22882p21939519.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Jon

http://janstey.blogspot.com/

Re: DSL and XPath

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Feb 13, 2009 at 12:05 AM, Ashwin Karpe <as...@progress.com> wrote:
>
> Hi,
>
> If you have properties set in the header part of the exchange, then instead
> of using XPath, you should try out the following
>
>               from("seda:test")
>                        .choice()
>                            .when().simple("in.header.op =
> 'out'").to("stream:out")
>                            .when().simple("in.header.op =
> 'err'").to("stream:err")
>                        .end();
>
> Hope this helps.
>
> Cheers,
>
> Ashwin...
>
> P.S: Camel exchange headers are not propagated as XML.

The simple language does not support operators so you can not do ==
For that in the Spring XML you need to use a different language:
http://camel.apache.org/languages.html

For instance: EL, OGNL, or even Bean so you can code it in plain Java
as a POJO class

I have raised a ticket in JIRA suggesting if we could add some few
operators as its being requested/thought its doable:
https://issues.apache.org/activemq/browse/CAMEL-1338

>
>
> benshort wrote:
>>
>> Hi,
>>
>> Can anyone help we get the following working.
>>
>> JDK 1.6
>> Camel 1.5.0
>>
>> Test case
>>
>> @Test
>>     public void xpath() throws Exception {
>>
>>         final CamelContext context = new DefaultCamelContext();
>>
>>         context.addRoutes(new RouteBuilder() {
>>             public void configure() throws Exception {
>>
>>                 from("seda:test")
>>                         .choice()
>>                             .when().xpath("in:header('op') =
>> 'out").to("stream:out")
>>                             .when().xpath("in:header('op') =
>> 'err").to("stream:err")
>>                         .end();
>>             }
>>         });
>>
>>         context.start();
>>
>>         ProducerTemplate template = context.createProducerTemplate();
>>
>>         template.sendBodyAndHeader("seda:test", "body", "op", "out");
>>
>>         context.stop();
>>     }
>>
>>
>> Exception thrown
>>
>> 2009-02-10 19:47:13,156: ERROR [seda:test thread:1] Failed delivery for
>> exchangeId: ID-LXP-0001/4547-1234295232453/0-0. On delivery attempt: 0
>> caught: org.apache.camel.RuntimeCamelException:
>> org.xml.sax.SAXParseException: Content is not allowed in prolog.
>> org.apache.camel.RuntimeCamelException: org.xml.sax.SAXParseException:
>> Content is not allowed in prolog.
>>       at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:441)
>>       at
>> org.apache.camel.impl.converter.InstanceMethodTypeConverter.convertTo(InstanceMethodTypeConverter.java:57)
>>       at
>> org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(DefaultTypeConverter.java:94)
>>       at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:65)
>>       at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:51)
>>       at
>> org.apache.camel.builder.xml.XPathBuilder.getDocument(XPathBuilder.java:528)
>>       at
>> org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:420)
>>       at
>> org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:98)
>>       at
>> org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:63)
>>       at
>> org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:47)
>>       at
>> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:75)
>>       at
>> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:172)
>>       at
>> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:93)
>>       at
>> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:63)
>>       at
>> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:47)
>>       at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:69)
>>       at java.lang.Thread.run(Thread.java:619)
>> Caused by: org.xml.sax.SAXParseException: Content is not allowed in
>> prolog.
>>       at
>> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
>>       at
>> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
>>       at
>> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:505)
>>       at
>> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:493)
>>       at
>> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:516)
>>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>       at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>       at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>       at java.lang.reflect.Method.invoke(Method.java:597)
>>       at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:437)
>>       ... 16 more
>>
>>
>
>
> -----
> ---
> Ashwin Karpe, Principal Consultant, PS - Opensource Center of Competence
> Progress Software Corporation
> 14 Oak Park Drive
> Bedford, MA 01730
> ---
> +1-972-304-9084 (Office)
> +1-972-971-1700 (Mobile)
> ----
> Blog: http://opensourceknowledge.blogspot.com/
>
>
> --
> View this message in context: http://www.nabble.com/DSL-and-XPath-tp21939519s22882p21986984.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Re: DSL and XPath

Posted by Ashwin Karpe <as...@progress.com>.
Hi,

If you have properties set in the header part of the exchange, then instead
of using XPath, you should try out the following

               from("seda:test")
                        .choice()
                            .when().simple("in.header.op =
'out'").to("stream:out")
                            .when().xpath("in.header.op =
'err'").to("stream:err")
                        .end();

Hope this helps.

Cheers,

Ashwin...

P.S: Camel exchange headers are not propagated as XML.


benshort wrote:
> 
> Hi, 
> 
> Can anyone help we get the following working.
> 
> JDK 1.6
> Camel 1.5.0
> 
> Test case
> 
> @Test
>     public void xpath() throws Exception {
> 
>         final CamelContext context = new DefaultCamelContext();
> 
>         context.addRoutes(new RouteBuilder() {
>             public void configure() throws Exception {
> 
>                 from("seda:test")
>                         .choice()
>                             .when().xpath("in:header('op') =
> 'out").to("stream:out")
>                             .when().xpath("in:header('op') =
> 'err").to("stream:err")
>                         .end();
>             }
>         });
> 
>         context.start();
> 
>         ProducerTemplate template = context.createProducerTemplate();
> 
>         template.sendBodyAndHeader("seda:test", "body", "op", "out");
> 
>         context.stop();        
>     }
> 
> 
> Exception thrown
> 
> 2009-02-10 19:47:13,156: ERROR [seda:test thread:1] Failed delivery for
> exchangeId: ID-LXP-0001/4547-1234295232453/0-0. On delivery attempt: 0
> caught: org.apache.camel.RuntimeCamelException:
> org.xml.sax.SAXParseException: Content is not allowed in prolog.
> org.apache.camel.RuntimeCamelException: org.xml.sax.SAXParseException:
> Content is not allowed in prolog.
> 	at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:441)
> 	at
> org.apache.camel.impl.converter.InstanceMethodTypeConverter.convertTo(InstanceMethodTypeConverter.java:57)
> 	at
> org.apache.camel.impl.converter.DefaultTypeConverter.convertTo(DefaultTypeConverter.java:94)
> 	at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:65)
> 	at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:51)
> 	at
> org.apache.camel.builder.xml.XPathBuilder.getDocument(XPathBuilder.java:528)
> 	at
> org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:420)
> 	at
> org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:98)
> 	at
> org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:63)
> 	at
> org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:47)
> 	at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:75)
> 	at
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:172)
> 	at
> org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:93)
> 	at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:63)
> 	at
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:47)
> 	at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:69)
> 	at java.lang.Thread.run(Thread.java:619)
> Caused by: org.xml.sax.SAXParseException: Content is not allowed in
> prolog.
> 	at
> com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:239)
> 	at
> com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
> 	at
> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:505)
> 	at
> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:493)
> 	at
> org.apache.camel.converter.jaxp.XmlConverter.toDOMDocument(XmlConverter.java:516)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:437)
> 	... 16 more
> 
> 


-----
--- 
Ashwin Karpe, Principal Consultant, PS - Opensource Center of Competence 
Progress Software Corporation
14 Oak Park Drive
Bedford, MA 01730
--- 
+1-972-304-9084 (Office) 
+1-972-971-1700 (Mobile) 
---- 
Blog: http://opensourceknowledge.blogspot.com/


-- 
View this message in context: http://www.nabble.com/DSL-and-XPath-tp21939519s22882p21986984.html
Sent from the Camel - Users mailing list archive at Nabble.com.