You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by pa...@orange-ftgroup.com on 2010/09/24 14:48:27 UTC

can't tranform Body to DOM

Hi,
I receive JMS messages which are actually XML documents.
In a processor I'm trying to get them as a DOM document since I need to process them in a certain way.
I'm doing this:
  org.w3c.dom.Document doc = ex.getIn().getBody(org.w3c.dom.Document.class);

And it does not seem to work (doc is always null). I don't get any error message.
I have xpath() statements in my route, which are being correctly evaluated.
I also have xslt transform endpoints which are working as expected.
But here I need to replace an attribute value and I'd like to do without xslt.

Patrice


*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration. 
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************


Re: can't tranform Body to DOM

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 24, 2010 at 9:10 PM, Donald Whytock <dw...@gmail.com> wrote:
> Would
>
> org.w3c.dom.Document doc = ex.getIn(org.w3c.dom.Document.class);
>
> work any better?
>

It's the same. By passing in the class type you tell Camel to convert
the message body to that class type (if needed to do so).


> Don
>
> On Fri, Sep 24, 2010 at 9:33 AM,  <pa...@orange-ftgroup.com> wrote:
>>
>>
>>> -----Message d'origine-----
>>> De : Claus Ibsen [mailto:claus.ibsen@gmail.com]
>>> Envoyé : vendredi 24 septembre 2010 15:23
>>> À : users@camel.apache.org
>>> Objet : Re: can't tranform Body to DOM
>>>
>>> On Fri, Sep 24, 2010 at 3:17 PM,  <pa...@orange-ftgroup.com>
>>> wrote:
>>> > I just noticed that my BodyType is set to byte[].
>>> > Maybe it explains why the conversion to Dom produces a null?
>>>
>>> What version of Camel are you using?
>>>
>>
>> I'm using version 2.2.0.fuse-02-0 (Fuse 4.2)
>>
>> I'm a bit concerned about String <-> DOM conversion along Camel routes.
>> Most of the time I need parsed XML (because I need XPath and XSLT) but this XML gets enriched by a web service that returns XML as a plain String.
>> I feel I'm not controlling when and where the message Body gets converted (this is my first project with Camel).
>>
>> Currently I'm more in a feasibility/prototyping stage but I'm expecting some refactoring in the near future, when I know how to use Camel properly ;-) to make sure performances are not too degradated by unnecessary type conversions.
>>
>>
>> *********************************
>> This message and any attachments (the "message") are confidential and intended solely for the addressees.
>> Any unauthorised use or dissemination is prohibited.
>> Messages are susceptible to alteration.
>> France Telecom Group shall not be liable for the message if altered, changed or falsified.
>> If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
>> ********************************
>>
>>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: can't tranform Body to DOM

Posted by Donald Whytock <dw...@gmail.com>.
Would

org.w3c.dom.Document doc = ex.getIn(org.w3c.dom.Document.class);

work any better?

Don

On Fri, Sep 24, 2010 at 9:33 AM,  <pa...@orange-ftgroup.com> wrote:
>
>
>> -----Message d'origine-----
>> De : Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Envoyé : vendredi 24 septembre 2010 15:23
>> À : users@camel.apache.org
>> Objet : Re: can't tranform Body to DOM
>>
>> On Fri, Sep 24, 2010 at 3:17 PM,  <pa...@orange-ftgroup.com>
>> wrote:
>> > I just noticed that my BodyType is set to byte[].
>> > Maybe it explains why the conversion to Dom produces a null?
>>
>> What version of Camel are you using?
>>
>
> I'm using version 2.2.0.fuse-02-0 (Fuse 4.2)
>
> I'm a bit concerned about String <-> DOM conversion along Camel routes.
> Most of the time I need parsed XML (because I need XPath and XSLT) but this XML gets enriched by a web service that returns XML as a plain String.
> I feel I'm not controlling when and where the message Body gets converted (this is my first project with Camel).
>
> Currently I'm more in a feasibility/prototyping stage but I'm expecting some refactoring in the near future, when I know how to use Camel properly ;-) to make sure performances are not too degradated by unnecessary type conversions.
>
>
> *********************************
> This message and any attachments (the "message") are confidential and intended solely for the addressees.
> Any unauthorised use or dissemination is prohibited.
> Messages are susceptible to alteration.
> France Telecom Group shall not be liable for the message if altered, changed or falsified.
> If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
> ********************************
>
>

Re: can't tranform Body to DOM

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 24, 2010 at 3:33 PM,  <pa...@orange-ftgroup.com> wrote:
>
>
>> -----Message d'origine-----
>> De : Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Envoyé : vendredi 24 septembre 2010 15:23
>> À : users@camel.apache.org
>> Objet : Re: can't tranform Body to DOM
>>
>> On Fri, Sep 24, 2010 at 3:17 PM,  <pa...@orange-ftgroup.com>
>> wrote:
>> > I just noticed that my BodyType is set to byte[].
>> > Maybe it explains why the conversion to Dom produces a null?
>>
>> What version of Camel are you using?
>>
>
> I'm using version 2.2.0.fuse-02-0 (Fuse 4.2)
>
> I'm a bit concerned about String <-> DOM conversion along Camel routes.
> Most of the time I need parsed XML (because I need XPath and XSLT) but this XML gets enriched by a web service that returns XML as a plain String.
> I feel I'm not controlling when and where the message Body gets converted (this is my first project with Camel).
>

Well Camel only converts when really needed, or if you ask it to do
so, such as from the Processor where you asked it to convert to a DOM.

The XPath expression/predicate in Camel can work with the input
message as source types, eg InputSource (I think the XML class name
is). That means
it can work on the message in the optimal way it sees fit.




> Currently I'm more in a feasibility/prototyping stage but I'm expecting some refactoring in the near future, when I know how to use Camel properly ;-) to make sure performances are not too degradated by unnecessary type conversions.
>

Yeah type convertions of big xml payloads can cause performance. So mind here.


>
> *********************************
> This message and any attachments (the "message") are confidential and intended solely for the addressees.
> Any unauthorised use or dissemination is prohibited.
> Messages are susceptible to alteration.
> France Telecom Group shall not be liable for the message if altered, changed or falsified.
> If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
> ********************************
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

RE: can't tranform Body to DOM

Posted by pa...@orange-ftgroup.com.

> -----Message d'origine-----
> De : Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Envoyé : vendredi 24 septembre 2010 15:23
> À : users@camel.apache.org
> Objet : Re: can't tranform Body to DOM
> 
> On Fri, Sep 24, 2010 at 3:17 PM,  <pa...@orange-ftgroup.com>
> wrote:
> > I just noticed that my BodyType is set to byte[].
> > Maybe it explains why the conversion to Dom produces a null?
> 
> What version of Camel are you using?
> 

I'm using version 2.2.0.fuse-02-0 (Fuse 4.2)

I'm a bit concerned about String <-> DOM conversion along Camel routes.
Most of the time I need parsed XML (because I need XPath and XSLT) but this XML gets enriched by a web service that returns XML as a plain String.
I feel I'm not controlling when and where the message Body gets converted (this is my first project with Camel).

Currently I'm more in a feasibility/prototyping stage but I'm expecting some refactoring in the near future, when I know how to use Camel properly ;-) to make sure performances are not too degradated by unnecessary type conversions.


*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration. 
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************


Re: can't tranform Body to DOM

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 24, 2010 at 3:17 PM,  <pa...@orange-ftgroup.com> wrote:
> I just noticed that my BodyType is set to byte[].
> Maybe it explains why the conversion to Dom produces a null?

What version of Camel are you using?

I would assume we had a byte[] -> Dom converter out of the box. But
maybe I am mistaking.
And we recently added some more XML related converters in 2.5.


> My messages are XML files dropped in a scanned folder and then picked-up by a route that forwards them into a JMS Topic where they are picked-up by my main route.
>
>> -----Message d'origine-----
>> De : Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Envoyé : vendredi 24 septembre 2010 14:55
>> À : users@camel.apache.org
>> Objet : Re: can't tranform Body to DOM
>>
>> On Fri, Sep 24, 2010 at 2:48 PM,  <pa...@orange-ftgroup.com>
>> wrote:
>> > Hi,
>> > I receive JMS messages which are actually XML documents.
>> > In a processor I'm trying to get them as a DOM document since I need
>> to process them in a certain way.
>> > I'm doing this:
>> >  org.w3c.dom.Document doc =
>> ex.getIn().getBody(org.w3c.dom.Document.class);
>> >
>> > And it does not seem to work (doc is always null). I don't get any
>> error message.
>> > I have xpath() statements in my route, which are being correctly
>> evaluated.
>> > I also have xslt transform endpoints which are working as expected.
>> > But here I need to replace an attribute value and I'd like to do
>> without xslt.
>> >
>>
>> use getMandatoryBody if you want Camel to barf if it could not convert
>> it.
>>
>>
>>
>> > Patrice
>> >
>> >
>> > *********************************
>> > This message and any attachments (the "message") are confidential and
>> intended solely for the addressees.
>> > Any unauthorised use or dissemination is prohibited.
>> > Messages are susceptible to alteration.
>> > France Telecom Group shall not be liable for the message if altered,
>> changed or falsified.
>> > If you are not the intended addressee of this message, please cancel
>> it immediately and inform the sender.
>> > ********************************
>> >
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>
> *********************************
> This message and any attachments (the "message") are confidential and intended solely for the addressees.
> Any unauthorised use or dissemination is prohibited.
> Messages are susceptible to alteration.
> France Telecom Group shall not be liable for the message if altered, changed or falsified.
> If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
> ********************************
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

RE: can't tranform Body to DOM

Posted by pa...@orange-ftgroup.com.
I just noticed that my BodyType is set to byte[]. 
Maybe it explains why the conversion to Dom produces a null?
My messages are XML files dropped in a scanned folder and then picked-up by a route that forwards them into a JMS Topic where they are picked-up by my main route.

> -----Message d'origine-----
> De : Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Envoyé : vendredi 24 septembre 2010 14:55
> À : users@camel.apache.org
> Objet : Re: can't tranform Body to DOM
> 
> On Fri, Sep 24, 2010 at 2:48 PM,  <pa...@orange-ftgroup.com>
> wrote:
> > Hi,
> > I receive JMS messages which are actually XML documents.
> > In a processor I'm trying to get them as a DOM document since I need
> to process them in a certain way.
> > I'm doing this:
> >  org.w3c.dom.Document doc =
> ex.getIn().getBody(org.w3c.dom.Document.class);
> >
> > And it does not seem to work (doc is always null). I don't get any
> error message.
> > I have xpath() statements in my route, which are being correctly
> evaluated.
> > I also have xslt transform endpoints which are working as expected.
> > But here I need to replace an attribute value and I'd like to do
> without xslt.
> >
> 
> use getMandatoryBody if you want Camel to barf if it could not convert
> it.
> 
> 
> 
> > Patrice
> >
> >
> > *********************************
> > This message and any attachments (the "message") are confidential and
> intended solely for the addressees.
> > Any unauthorised use or dissemination is prohibited.
> > Messages are susceptible to alteration.
> > France Telecom Group shall not be liable for the message if altered,
> changed or falsified.
> > If you are not the intended addressee of this message, please cancel
> it immediately and inform the sender.
> > ********************************
> >
> >
> 
> 
> 
> --
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus

*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration. 
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************


RE: can't tranform Body to DOM

Posted by pa...@orange-ftgroup.com.
> 
> use getMandatoryBody if you want Camel to barf if it could not convert
> it.
> 

I actually want Camel to convert it :-)
I did a quick & dirty workaround by parsing the Body to JDOM myself, until I understand why Camel type conversion does not seem to work.
I'll search  the doc for this getMandatoryBody thing. Maybe I'll get the reason why it won't parse it then.

Thanks,
Patrice.


*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration. 
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************


Re: can't tranform Body to DOM

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 24, 2010 at 2:48 PM,  <pa...@orange-ftgroup.com> wrote:
> Hi,
> I receive JMS messages which are actually XML documents.
> In a processor I'm trying to get them as a DOM document since I need to process them in a certain way.
> I'm doing this:
>  org.w3c.dom.Document doc = ex.getIn().getBody(org.w3c.dom.Document.class);
>
> And it does not seem to work (doc is always null). I don't get any error message.
> I have xpath() statements in my route, which are being correctly evaluated.
> I also have xslt transform endpoints which are working as expected.
> But here I need to replace an attribute value and I'd like to do without xslt.
>

use getMandatoryBody if you want Camel to barf if it could not convert it.



> Patrice
>
>
> *********************************
> This message and any attachments (the "message") are confidential and intended solely for the addressees.
> Any unauthorised use or dissemination is prohibited.
> Messages are susceptible to alteration.
> France Telecom Group shall not be liable for the message if altered, changed or falsified.
> If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
> ********************************
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus