You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bgoetzmann <bg...@sophia.symag.com> on 2007/09/28 16:59:40 UTC

From File to POJO using JAXB

Hello,

Looking at the ETL example that is impressive, I see that a detected file is
converted to a POJO ; this is defined a route declared in the EtlRoutes
class:

from("file:src/data?noop=true").convertBodyTo(PersonDocument.class)...

I know that when a file is detected in the src folder the body of the
message that comes in is of type File ; how the XML content of this file is
converted (marshalled) to the POJO PersonDocument that has JAXB annotations?
Can I have more details, for example how Camel knows that it has to marshall
using JAXB?

Thank you!

Bertrand.
-- 
View this message in context: http://www.nabble.com/From-File-to-POJO-using-JAXB-tf4535029s22882.html#a12942160
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: From File to POJO using JAXB

Posted by James Strachan <ja...@gmail.com>.
I've an early cut of the Data Format feature implemented in trunk for
CAMEL-165...

http://cwiki.apache.org/CAMEL/data-format.html

As always feedback welcome. Essentially it allows you to be specific
in the DSL to marshal or unmarshal messages using some kind of
encoding like Serialization, JAXB2, XmlBeans and so forth.


On 02/10/2007, bgoetzmann <bg...@sophia.symag.com> wrote:
>
> I only see now that when having camel-core jar in classpath, this installs
> some converters, and in particular the converter File to InputStream!
>
> In fact I've made a sample project based on the ETL example in order to show
> the integration of XML files into a database using JAXB and JPA. Without
> having camel-core in my class path I get an exception: I was unable to
> unmashall a File to a POJO using JAXB. With the converter in camel-core it's
> the content of the file that is unmarshalled to a POJO, and there, it was
> possible to send this POJO to the jpa URI.
>
> As you said James, it would be interesting to indicate explicit conversions
> in routes.
>
> I continue to explore Camel, this very interesting project!
>
>
>
> bgoetzmann wrote:
> >
> > Thank you James,
> >
> > Looking at the source code of the FallbackTypeConverter's unmarshall
> > method class, I don't see where the content file is unmarshalled to the
> > POJO. Perhaps the file object is first converted to InputStream?
> >
> > Bertrand.
> >
> >
> > James.Strachan wrote:
> >>
> >> On 28/09/2007, bgoetzmann <bg...@sophia.symag.com> wrote:
> >>>
> >>> Hello,
> >>>
> >>> Looking at the ETL example that is impressive, I see that a detected
> >>> file is
> >>> converted to a POJO ; this is defined a route declared in the EtlRoutes
> >>> class:
> >>>
> >>> from("file:src/data?noop=true").convertBodyTo(PersonDocument.class)...
> >>>
> >>> I know that when a file is detected in the src folder the body of the
> >>> message that comes in is of type File ; how the XML content of this file
> >>> is
> >>> converted (marshalled) to the POJO PersonDocument that has JAXB
> >>> annotations?
> >>> Can I have more details, for example how Camel knows that it has to
> >>> marshall
> >>> using JAXB?
> >>>
> >>> Thank you!
> >>
> >> If camel-jaxb.jar is on the classpath it installs a
> >> FallbackTypeConverter which looks at the requested type and if its a
> >> JAXB2 POJO (i.e. has an @XmlRootElement) then it tries to convert the
> >> body to the JAXB2 POJO using JAXB.
> >>
> >> We should probably add the concept of explicit message Source (input
> >> format) and Sink (output format) to make this a little more explicit
> >> and a little less magic. (I've spun up a separate thread on this...)
> >>
> >> http://www.nabble.com/musings-on-Source-Sink-integration-%28e.g.-serialization-v-JAXB2-v-SOAP-encoding-etc%29-tf4548713s22882.html
> >>
> >> --
> >> James
> >> -------
> >> http://macstrac.blogspot.com/
> >>
> >> Open Source SOA
> >> http://open.iona.com
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/From-File-to-POJO-using-JAXB-tf4535029s22882.html#a12997579
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com

Re: From File to POJO using JAXB

Posted by bgoetzmann <bg...@sophia.symag.com>.
I only see now that when having camel-core jar in classpath, this installs
some converters, and in particular the converter File to InputStream!

In fact I've made a sample project based on the ETL example in order to show
the integration of XML files into a database using JAXB and JPA. Without
having camel-core in my class path I get an exception: I was unable to
unmashall a File to a POJO using JAXB. With the converter in camel-core it's
the content of the file that is unmarshalled to a POJO, and there, it was
possible to send this POJO to the jpa URI.

As you said James, it would be interesting to indicate explicit conversions
in routes.

I continue to explore Camel, this very interesting project!



bgoetzmann wrote:
> 
> Thank you James,
> 
> Looking at the source code of the FallbackTypeConverter's unmarshall
> method class, I don't see where the content file is unmarshalled to the
> POJO. Perhaps the file object is first converted to InputStream?
> 
> Bertrand.
> 
> 
> James.Strachan wrote:
>> 
>> On 28/09/2007, bgoetzmann <bg...@sophia.symag.com> wrote:
>>>
>>> Hello,
>>>
>>> Looking at the ETL example that is impressive, I see that a detected
>>> file is
>>> converted to a POJO ; this is defined a route declared in the EtlRoutes
>>> class:
>>>
>>> from("file:src/data?noop=true").convertBodyTo(PersonDocument.class)...
>>>
>>> I know that when a file is detected in the src folder the body of the
>>> message that comes in is of type File ; how the XML content of this file
>>> is
>>> converted (marshalled) to the POJO PersonDocument that has JAXB
>>> annotations?
>>> Can I have more details, for example how Camel knows that it has to
>>> marshall
>>> using JAXB?
>>>
>>> Thank you!
>> 
>> If camel-jaxb.jar is on the classpath it installs a
>> FallbackTypeConverter which looks at the requested type and if its a
>> JAXB2 POJO (i.e. has an @XmlRootElement) then it tries to convert the
>> body to the JAXB2 POJO using JAXB.
>> 
>> We should probably add the concept of explicit message Source (input
>> format) and Sink (output format) to make this a little more explicit
>> and a little less magic. (I've spun up a separate thread on this...)
>> 
>> http://www.nabble.com/musings-on-Source-Sink-integration-%28e.g.-serialization-v-JAXB2-v-SOAP-encoding-etc%29-tf4548713s22882.html
>> 
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>> 
>> Open Source SOA
>> http://open.iona.com
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/From-File-to-POJO-using-JAXB-tf4535029s22882.html#a12997579
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: From File to POJO using JAXB

Posted by bgoetzmann <bg...@sophia.symag.com>.
Thank you James,

Looking at the source code of the FallbackTypeConverter's unmarshall method
class, I don't see where the content file is unmarshalled to the POJO.
Perhaps the file object is first converted to InputStream?

Bertrand.


James.Strachan wrote:
> 
> On 28/09/2007, bgoetzmann <bg...@sophia.symag.com> wrote:
>>
>> Hello,
>>
>> Looking at the ETL example that is impressive, I see that a detected file
>> is
>> converted to a POJO ; this is defined a route declared in the EtlRoutes
>> class:
>>
>> from("file:src/data?noop=true").convertBodyTo(PersonDocument.class)...
>>
>> I know that when a file is detected in the src folder the body of the
>> message that comes in is of type File ; how the XML content of this file
>> is
>> converted (marshalled) to the POJO PersonDocument that has JAXB
>> annotations?
>> Can I have more details, for example how Camel knows that it has to
>> marshall
>> using JAXB?
>>
>> Thank you!
> 
> If camel-jaxb.jar is on the classpath it installs a
> FallbackTypeConverter which looks at the requested type and if its a
> JAXB2 POJO (i.e. has an @XmlRootElement) then it tries to convert the
> body to the JAXB2 POJO using JAXB.
> 
> We should probably add the concept of explicit message Source (input
> format) and Sink (output format) to make this a little more explicit
> and a little less magic. (I've spun up a separate thread on this...)
> 
> http://www.nabble.com/musings-on-Source-Sink-integration-%28e.g.-serialization-v-JAXB2-v-SOAP-encoding-etc%29-tf4548713s22882.html
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source SOA
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/From-File-to-POJO-using-JAXB-tf4535029s22882.html#a12995397
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: From File to POJO using JAXB

Posted by James Strachan <ja...@gmail.com>.
On 28/09/2007, bgoetzmann <bg...@sophia.symag.com> wrote:
>
> Hello,
>
> Looking at the ETL example that is impressive, I see that a detected file is
> converted to a POJO ; this is defined a route declared in the EtlRoutes
> class:
>
> from("file:src/data?noop=true").convertBodyTo(PersonDocument.class)...
>
> I know that when a file is detected in the src folder the body of the
> message that comes in is of type File ; how the XML content of this file is
> converted (marshalled) to the POJO PersonDocument that has JAXB annotations?
> Can I have more details, for example how Camel knows that it has to marshall
> using JAXB?
>
> Thank you!

If camel-jaxb.jar is on the classpath it installs a
FallbackTypeConverter which looks at the requested type and if its a
JAXB2 POJO (i.e. has an @XmlRootElement) then it tries to convert the
body to the JAXB2 POJO using JAXB.

We should probably add the concept of explicit message Source (input
format) and Sink (output format) to make this a little more explicit
and a little less magic. (I've spun up a separate thread on this...)

http://www.nabble.com/musings-on-Source-Sink-integration-%28e.g.-serialization-v-JAXB2-v-SOAP-encoding-etc%29-tf4548713s22882.html

-- 
James
-------
http://macstrac.blogspot.com/

Open Source SOA
http://open.iona.com