You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Vegi, Vamsi (MAN-Corporate-CON)" <Va...@Manheim.com> on 2013/05/20 19:22:21 UTC

how is the automatica type conversion happening

Hello

I am confused how the camel framework is automatically unmarshalling the XML file into an JaxB object
Here is my Configurator, with the route def

======================================================================
@Override
public void configure() throws Exception {
  LOG.info("CompanyMsgRouter: configure called");
  try {
       jaxbContext = JAXBContext.newInstance(CompanyMsg.class);
       jaxbUnmarshaller = jaxbContext.createUnmarshaller();
  } catch (JAXBException e) {
e.printStackTrace();
  }

from("file:C:\\camel\\files\\in?noop=true") // contains XML Msg
.routeId(READ_Q_ROUTE_ID)
.log(LoggingLevel.INFO, "uploading file:${header.CamelFilePath}")
.bean(new TransformSvcCompanyMsg(), "getCompleteCompanyDao"); // expects JAXB object here


}
======================================================================

The method: getCompleteCompanyDao has the signature like like
public Company getCompleteCompanyDao(final CompanyMsg compMsg) {
:
:
}

Question is: when I run the app, it works fine, but I am confused as when and where the unmarshalling is happening.
I am not explicitly calling the JaxB unmarshaller
Is it using the jaxBUnMarshaller that I had previously defined?
Btw, all the needed JaxB classes are in the path.


-thanks
-V



Re: how is the automatica type conversion happening

Posted by Willem jiang <wi...@gmail.com>.
There is a cache of the JAXB context, so the FallbackTypeConverter don't need to create a new one per request.



--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, May 21, 2013 at 8:38 PM, Vegi, Vamsi (MAN-Corporate-CON) wrote:

> Thank you,
> Well CompanyMsg is indeed a JaxB annotated. it is generated by the XJC compiler.
> But here is the question:
> Does Camel creates the JaxBContext every time? You know, that is an expensive operation.  
> I am talking about performance tuning here.
> If that was already taken care of, great.
>  
> in case, it is not taken care of, how can I use spring bean (JaxBContext) and give it to Camel for it to use the type conversion.
>  
> Thanks much
>  
> -Vamsi
>  
>  
>  
>  
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]  
> Sent: Tuesday, May 21, 2013 1:13 AM
> To: users@camel.apache.org (mailto:users@camel.apache.org)
> Subject: Re: how is the automatica type conversion happening
>  
> Hi
>  
> Its the type converter that kicks in
> http://camel.apache.org/type-converter.html
>  
> There is a fallback converter for JAXB so when you declare the method signature to have CompanyMsg as parameter type, then Camel will try to convert the message body to this type. And as CompanyMsg is a JAXB annotated class, then JAXB kicks-in.
>  
> On Mon, May 20, 2013 at 7:22 PM, Vegi, Vamsi (MAN-Corporate-CON) <Vamsi.Vegi@manheim.com (mailto:Vamsi.Vegi@manheim.com)> wrote:
> > Hello
> >  
> > I am confused how the camel framework is automatically unmarshalling  
> > the XML file into an JaxB object Here is my Configurator, with the  
> > route def
> >  
> > ======================================================================
> > @Override
> > public void configure() throws Exception {
> > LOG.info (http://LOG.info)("CompanyMsgRouter: configure called");
> > try {
> > jaxbContext = JAXBContext.newInstance(CompanyMsg.class);
> > jaxbUnmarshaller = jaxbContext.createUnmarshaller();
> > } catch (JAXBException e) {
> > e.printStackTrace();
> > }
> >  
> > from("file:C:\\camel\\files\\in?noop=true") // contains XML Msg
> > .routeId(READ_Q_ROUTE_ID)
> > .log(LoggingLevel.INFO, "uploading file:${header.CamelFilePath}")  
> > .bean(new TransformSvcCompanyMsg(), "getCompleteCompanyDao"); //  
> > expects JAXB object here
> >  
> >  
> > }
> > ======================================================================
> >  
> > The method: getCompleteCompanyDao has the signature like like public  
> > Company getCompleteCompanyDao(final CompanyMsg compMsg) {
> > :
> > :
> > }
> >  
> > Question is: when I run the app, it works fine, but I am confused as when and where the unmarshalling is happening.
> > I am not explicitly calling the JaxB unmarshaller Is it using the  
> > jaxBUnMarshaller that I had previously defined?
> > Btw, all the needed JaxB classes are in the path.
> >  
> >  
> > -thanks
> > -V
>  
>  
>  
>  
>  
> --
> Claus Ibsen
> -----------------
> www.camelone.org (http://www.camelone.org): The open source integration conference.
>  
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com (mailto:cibsen@redhat.com)
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen




RE: how is the automatica type conversion happening

Posted by "Vegi, Vamsi (MAN-Corporate-CON)" <Va...@Manheim.com>.
Thanks a lot, it's very useful feedback from all you.



-----Original Message-----
From: Christian Posta [mailto:christian.posta@gmail.com] 
Sent: Tuesday, May 21, 2013 10:00 AM
To: users@camel.apache.org
Subject: Re: how is the automatica type conversion happening

As for configuring your own JAXB formatter, take a look at this page which shows how to use a bean defined in spring context

http://camel.apache.org/jaxb.html




On Tue, May 21, 2013 at 5:38 AM, Vegi, Vamsi (MAN-Corporate-CON) < Vamsi.Vegi@manheim.com> wrote:

> Thank you,
> Well CompanyMsg is indeed a JaxB annotated. it is generated by the XJC 
> compiler.
> But here is the question:
> Does Camel creates the JaxBContext every time? You know, that is an 
> expensive operation.
> I am talking about performance tuning here.
> If that was already taken care of, great.
>
> in case, it is not taken care of, how can I use spring bean 
> (JaxBContext) and give it to Camel for it to use the type conversion.
>
> Thanks much
>
> -Vamsi
>
>
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Tuesday, May 21, 2013 1:13 AM
> To: users@camel.apache.org
> Subject: Re: how is the automatica type conversion happening
>
> Hi
>
> Its the type converter that kicks in
> http://camel.apache.org/type-converter.html
>
> There is a fallback converter for JAXB so when you declare the method 
> signature to have CompanyMsg as parameter type, then Camel will try to 
> convert the message body to this type. And as CompanyMsg is a JAXB 
> annotated class, then JAXB kicks-in.
>
> On Mon, May 20, 2013 at 7:22 PM, Vegi, Vamsi (MAN-Corporate-CON) < 
> Vamsi.Vegi@manheim.com> wrote:
> > Hello
> >
> > I am confused how the camel framework is automatically unmarshalling 
> > the XML file into an JaxB object Here is my Configurator, with the 
> > route def
> >
> > ====================================================================
> > ==
> > @Override
> > public void configure() throws Exception {
> >   LOG.info("CompanyMsgRouter: configure called");
> >   try {
> >        jaxbContext = JAXBContext.newInstance(CompanyMsg.class);
> >        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
> >   } catch (JAXBException e) {
> > e.printStackTrace();
> >   }
> >
> > from("file:C:\\camel\\files\\in?noop=true") // contains XML Msg
> > .routeId(READ_Q_ROUTE_ID)
> > .log(LoggingLevel.INFO, "uploading file:${header.CamelFilePath}") 
> > .bean(new TransformSvcCompanyMsg(), "getCompleteCompanyDao"); // 
> > expects JAXB object here
> >
> >
> > }
> > ====================================================================
> > ==
> >
> > The method: getCompleteCompanyDao has the signature like like public 
> > Company getCompleteCompanyDao(final CompanyMsg compMsg) {
> > :
> > :
> > }
> >
> > Question is: when I run the app, it works fine, but I am confused as
> when and where the unmarshalling is happening.
> > I am not explicitly calling the JaxB unmarshaller Is it using the 
> > jaxBUnMarshaller that I had previously defined?
> > Btw, all the needed JaxB classes are in the path.
> >
> >
> > -thanks
> > -V
> >
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>
>
>
>


--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta


Re: how is the automatica type conversion happening

Posted by Christian Posta <ch...@gmail.com>.
As for configuring your own JAXB formatter, take a look at this page which
shows how to use a bean defined in spring context

http://camel.apache.org/jaxb.html




On Tue, May 21, 2013 at 5:38 AM, Vegi, Vamsi (MAN-Corporate-CON) <
Vamsi.Vegi@manheim.com> wrote:

> Thank you,
> Well CompanyMsg is indeed a JaxB annotated. it is generated by the XJC
> compiler.
> But here is the question:
> Does Camel creates the JaxBContext every time? You know, that is an
> expensive operation.
> I am talking about performance tuning here.
> If that was already taken care of, great.
>
> in case, it is not taken care of, how can I use spring bean (JaxBContext)
> and give it to Camel for it to use the type conversion.
>
> Thanks much
>
> -Vamsi
>
>
>
>
> -----Original Message-----
> From: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Sent: Tuesday, May 21, 2013 1:13 AM
> To: users@camel.apache.org
> Subject: Re: how is the automatica type conversion happening
>
> Hi
>
> Its the type converter that kicks in
> http://camel.apache.org/type-converter.html
>
> There is a fallback converter for JAXB so when you declare the method
> signature to have CompanyMsg as parameter type, then Camel will try to
> convert the message body to this type. And as CompanyMsg is a JAXB
> annotated class, then JAXB kicks-in.
>
> On Mon, May 20, 2013 at 7:22 PM, Vegi, Vamsi (MAN-Corporate-CON) <
> Vamsi.Vegi@manheim.com> wrote:
> > Hello
> >
> > I am confused how the camel framework is automatically unmarshalling
> > the XML file into an JaxB object Here is my Configurator, with the
> > route def
> >
> > ======================================================================
> > @Override
> > public void configure() throws Exception {
> >   LOG.info("CompanyMsgRouter: configure called");
> >   try {
> >        jaxbContext = JAXBContext.newInstance(CompanyMsg.class);
> >        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
> >   } catch (JAXBException e) {
> > e.printStackTrace();
> >   }
> >
> > from("file:C:\\camel\\files\\in?noop=true") // contains XML Msg
> > .routeId(READ_Q_ROUTE_ID)
> > .log(LoggingLevel.INFO, "uploading file:${header.CamelFilePath}")
> > .bean(new TransformSvcCompanyMsg(), "getCompleteCompanyDao"); //
> > expects JAXB object here
> >
> >
> > }
> > ======================================================================
> >
> > The method: getCompleteCompanyDao has the signature like like public
> > Company getCompleteCompanyDao(final CompanyMsg compMsg) {
> > :
> > :
> > }
> >
> > Question is: when I run the app, it works fine, but I am confused as
> when and where the unmarshalling is happening.
> > I am not explicitly calling the JaxB unmarshaller Is it using the
> > jaxBUnMarshaller that I had previously defined?
> > Btw, all the needed JaxB classes are in the path.
> >
> >
> > -thanks
> > -V
> >
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: cibsen@redhat.com
> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>
>
>
>


-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

RE: how is the automatica type conversion happening

Posted by "Vegi, Vamsi (MAN-Corporate-CON)" <Va...@Manheim.com>.
Thank you,
Well CompanyMsg is indeed a JaxB annotated. it is generated by the XJC compiler.
But here is the question:
Does Camel creates the JaxBContext every time? You know, that is an expensive operation. 
I am talking about performance tuning here.
If that was already taken care of, great.

in case, it is not taken care of, how can I use spring bean (JaxBContext) and give it to Camel for it to use the type conversion.

Thanks much

-Vamsi




-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Sent: Tuesday, May 21, 2013 1:13 AM
To: users@camel.apache.org
Subject: Re: how is the automatica type conversion happening

Hi

Its the type converter that kicks in
http://camel.apache.org/type-converter.html

There is a fallback converter for JAXB so when you declare the method signature to have CompanyMsg as parameter type, then Camel will try to convert the message body to this type. And as CompanyMsg is a JAXB annotated class, then JAXB kicks-in.

On Mon, May 20, 2013 at 7:22 PM, Vegi, Vamsi (MAN-Corporate-CON) <Va...@manheim.com> wrote:
> Hello
>
> I am confused how the camel framework is automatically unmarshalling 
> the XML file into an JaxB object Here is my Configurator, with the 
> route def
>
> ======================================================================
> @Override
> public void configure() throws Exception {
>   LOG.info("CompanyMsgRouter: configure called");
>   try {
>        jaxbContext = JAXBContext.newInstance(CompanyMsg.class);
>        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
>   } catch (JAXBException e) {
> e.printStackTrace();
>   }
>
> from("file:C:\\camel\\files\\in?noop=true") // contains XML Msg
> .routeId(READ_Q_ROUTE_ID)
> .log(LoggingLevel.INFO, "uploading file:${header.CamelFilePath}") 
> .bean(new TransformSvcCompanyMsg(), "getCompleteCompanyDao"); // 
> expects JAXB object here
>
>
> }
> ======================================================================
>
> The method: getCompleteCompanyDao has the signature like like public 
> Company getCompleteCompanyDao(final CompanyMsg compMsg) {
> :
> :
> }
>
> Question is: when I run the app, it works fine, but I am confused as when and where the unmarshalling is happening.
> I am not explicitly calling the JaxB unmarshaller Is it using the 
> jaxBUnMarshaller that I had previously defined?
> Btw, all the needed JaxB classes are in the path.
>
>
> -thanks
> -V
>
>



--
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen




Re: how is the automatica type conversion happening

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Its the type converter that kicks in
http://camel.apache.org/type-converter.html

There is a fallback converter for JAXB so when you declare the method
signature to have CompanyMsg as parameter type, then Camel will try to
convert the message body to this type. And as CompanyMsg is a JAXB
annotated class, then JAXB kicks-in.

On Mon, May 20, 2013 at 7:22 PM, Vegi, Vamsi (MAN-Corporate-CON)
<Va...@manheim.com> wrote:
> Hello
>
> I am confused how the camel framework is automatically unmarshalling the XML file into an JaxB object
> Here is my Configurator, with the route def
>
> ======================================================================
> @Override
> public void configure() throws Exception {
>   LOG.info("CompanyMsgRouter: configure called");
>   try {
>        jaxbContext = JAXBContext.newInstance(CompanyMsg.class);
>        jaxbUnmarshaller = jaxbContext.createUnmarshaller();
>   } catch (JAXBException e) {
> e.printStackTrace();
>   }
>
> from("file:C:\\camel\\files\\in?noop=true") // contains XML Msg
> .routeId(READ_Q_ROUTE_ID)
> .log(LoggingLevel.INFO, "uploading file:${header.CamelFilePath}")
> .bean(new TransformSvcCompanyMsg(), "getCompleteCompanyDao"); // expects JAXB object here
>
>
> }
> ======================================================================
>
> The method: getCompleteCompanyDao has the signature like like
> public Company getCompleteCompanyDao(final CompanyMsg compMsg) {
> :
> :
> }
>
> Question is: when I run the app, it works fine, but I am confused as when and where the unmarshalling is happening.
> I am not explicitly calling the JaxB unmarshaller
> Is it using the jaxBUnMarshaller that I had previously defined?
> Btw, all the needed JaxB classes are in the path.
>
>
> -thanks
> -V
>
>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen