You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Willem jiang <wi...@gmail.com> on 2013/07/01 15:55:55 UTC

Re: how to create the "custom bean" for unmarshalling the webservice request

If you are using wsdl2java to generate the artifacts from the wsdl, you should be able to get the Request class which has the jaxb annotation as you want.
JAXB dataformat fallback type will be used to do the unmarshal work for you.  
If you sql component can not take the request object, you need to write a custom converter to converter the request object for you.

BTW, you can use the POJO data format this time, you should be able to get the request object directly, then you don't need to care much about JAXB data format stuff any more.  

--  
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 Monday, July 1, 2013 at 8:40 PM, cdj0579 wrote:

> Hi~
>  
> This is how my camel route looks like:
> <camelContext id="test_context" xmlns="http://camel.apache.org/schema/spring">
> <route>
> <from uri="cxf:bean:wsConsumer?dataFormat=MESSAGE" />
> <convertBodyTo type="com.mycompany.bean.TestBean" />
> <to uri="sql:select * from projects where license = # order by id?dataSource=#myDS"/>
> <to uri="log:output" />
> </route>
> </camelContext>
>  
> Below is what my camel route want to do, I found it's difficult to achieve step 2:  
> 1.setup a cxf endpoint to consume the requst,  
> 2.convert the request into one custom bean(List type)
> 3.using SqlComponent to access database(MySQL),do a query action.
> 4.logout the query result.
>  
> the step 1,3,4 is easy to achieve ,step 2 is difficult for me.
> I known we can using JAXB to unmarshal the input webservice request into a "custom bean".  
> but how the "custom bean" create from? I'm so confued. I just have a wsdl file,and the service related classes.
> Can anyone please tell me in how to create this "custom bean" ?  
>  
> Thanks in advance for any help!  
>  
>  
>  
>  
> a new camel rider
> chen jie.




Re: RE: how to create the "custom bean" for unmarshalling the webservice request

Posted by cdj0579 <cd...@gmail.com>.
Neil, Willem:
Many thanks !
The POJO way works!

Now, without using "convertBodyTo" this is my route looks like:

<route>
<from uri="cxf:bean:wsConsumer?dataFormat=POJO" />
<bean ref="myBean" method="doTransform"/>
<to uri="sql:select * from projects where license = # order by id?dataSource=#myDS"/>
<to uri="bean:orderBean?method=processOrder"/>
<log message="${body}"/>
</route>

myBean refers to this class:
public class MyBean {
@Consume
public List<String> doTransform(String input){
        System.out.println("收到了数据:"+input);
List<String> res = new ArrayList<String>();
res.add(input);
return res;
}
}

It works great!
Thanks very much! 


cdj0579

From: Neil Franken
Date: 2013-07-02 06:28
To: users@servicemix.apache.org; cdj0579; Willem jiang
Subject: RE: Re: how to create the "custom bean" for unmarshalling the webservice request
I have done exactly this in my latest project. Change your line of code from uri="cxf:bean:wsConsumer?dataFormat=MESSAGE to from uri="cxf:bean:wsConsumer?dataFormat=POJO.  Camel will now send a POJO message across the route. The key here is to use the contract first design approach to Web services thus designing the WSDL first and coding from there.  I played with the JAXB format for a while but it gave me a little more grey hairs than it should. 

Regards
Neil


-----Original Message-----
From: cdj0579 [mailto:cdj0579@gmail.com] 
Sent: Tuesday, 2 July 2013 3:06 AM
To: Willem jiang
Cc: users
Subject: Re: Re: how to create the "custom bean" for unmarshalling the webservice request

Hi Willem:

Thank you for your kind help.
I will try out the way that using wsdl2java.
I'm very interested the POJO way ,It would be help me greatly if you could please give me more information or some example.:) thanks again!




a new camel rider.
Chen Jie.

From: Willem jiang
Date: 2013-07-01 21:55
To: users; cdj0579
Subject: Re: how to create the "custom bean" for unmarshalling the webservice request If you are using wsdl2java to generate the artifacts from the wsdl, you should be able to get the Request class which has the jaxb annotation as you want.
JAXB dataformat fallback type will be used to do the unmarshal work for you.  
If you sql component can not take the request object, you need to write a custom converter to converter the request object for you.

BTW, you can use the POJO data format this time, you should be able to get the request object directly, then you don't need to care much about JAXB data format stuff any more.  

--
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 Monday, July 1, 2013 at 8:40 PM, cdj0579 wrote:

> Hi~
>  
> This is how my camel route looks like:
> <camelContext id="test_context" 
> xmlns="http://camel.apache.org/schema/spring">
> <route>
> <from uri="cxf:bean:wsConsumer?dataFormat=MESSAGE" /> <convertBodyTo 
> type="com.mycompany.bean.TestBean" /> <to uri="sql:select * from 
> projects where license = # order by id?dataSource=#myDS"/> <to 
> uri="log:output" /> </route> </camelContext>
>  
> Below is what my camel route want to do, I found it's difficult to achieve step 2:  
> 1.setup a cxf endpoint to consume the requst, 2.convert the request 
> into one custom bean(List type) 3.using SqlComponent to access 
> database(MySQL),do a query action.
> 4.logout the query result.
>  
> the step 1,3,4 is easy to achieve ,step 2 is difficult for me.
> I known we can using JAXB to unmarshal the input webservice request into a "custom bean".  
> but how the "custom bean" create from? I'm so confued. I just have a wsdl file,and the service related classes.
> Can anyone please tell me in how to create this "custom bean" ?  
>  
> Thanks in advance for any help!  
>  
>  
>  
>  
> a new camel rider
> chen jie.

RE: Re: how to create the "custom bean" for unmarshalling the webservice request

Posted by Neil Franken <n....@insol.com.au>.
I have done exactly this in my latest project. Change your line of code from uri="cxf:bean:wsConsumer?dataFormat=MESSAGE to from uri="cxf:bean:wsConsumer?dataFormat=POJO.  Camel will now send a POJO message across the route. The key here is to use the contract first design approach to Web services thus designing the WSDL first and coding from there.  I played with the JAXB format for a while but it gave me a little more grey hairs than it should. 

Regards
Neil


-----Original Message-----
From: cdj0579 [mailto:cdj0579@gmail.com] 
Sent: Tuesday, 2 July 2013 3:06 AM
To: Willem jiang
Cc: users
Subject: Re: Re: how to create the "custom bean" for unmarshalling the webservice request

Hi Willem:

Thank you for your kind help.
I will try out the way that using wsdl2java.
I'm very interested the POJO way ,It would be help me greatly if you could please give me more information or some example.:) thanks again!




a new camel rider.
Chen Jie.

From: Willem jiang
Date: 2013-07-01 21:55
To: users; cdj0579
Subject: Re: how to create the "custom bean" for unmarshalling the webservice request If you are using wsdl2java to generate the artifacts from the wsdl, you should be able to get the Request class which has the jaxb annotation as you want.
JAXB dataformat fallback type will be used to do the unmarshal work for you.  
If you sql component can not take the request object, you need to write a custom converter to converter the request object for you.

BTW, you can use the POJO data format this time, you should be able to get the request object directly, then you don't need to care much about JAXB data format stuff any more.  

--
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 Monday, July 1, 2013 at 8:40 PM, cdj0579 wrote:

> Hi~
>  
> This is how my camel route looks like:
> <camelContext id="test_context" 
> xmlns="http://camel.apache.org/schema/spring">
> <route>
> <from uri="cxf:bean:wsConsumer?dataFormat=MESSAGE" /> <convertBodyTo 
> type="com.mycompany.bean.TestBean" /> <to uri="sql:select * from 
> projects where license = # order by id?dataSource=#myDS"/> <to 
> uri="log:output" /> </route> </camelContext>
>  
> Below is what my camel route want to do, I found it's difficult to achieve step 2:  
> 1.setup a cxf endpoint to consume the requst, 2.convert the request 
> into one custom bean(List type) 3.using SqlComponent to access 
> database(MySQL),do a query action.
> 4.logout the query result.
>  
> the step 1,3,4 is easy to achieve ,step 2 is difficult for me.
> I known we can using JAXB to unmarshal the input webservice request into a "custom bean".  
> but how the "custom bean" create from? I'm so confued. I just have a wsdl file,and the service related classes.
> Can anyone please tell me in how to create this "custom bean" ?  
>  
> Thanks in advance for any help!  
>  
>  
>  
>  
> a new camel rider
> chen jie.

Re: Re: how to create the "custom bean" for unmarshalling the webservice request

Posted by cdj0579 <cd...@gmail.com>.
Hi Willem:

Thank you for your kind help.
I will try out the way that using wsdl2java.
I'm very interested the POJO way ,It would be help me greatly if you could please give me more information or some example.:)
thanks again!




a new camel rider.
Chen Jie.

From: Willem jiang
Date: 2013-07-01 21:55
To: users; cdj0579
Subject: Re: how to create the "custom bean" for unmarshalling the webservice request
If you are using wsdl2java to generate the artifacts from the wsdl, you should be able to get the Request class which has the jaxb annotation as you want.
JAXB dataformat fallback type will be used to do the unmarshal work for you.  
If you sql component can not take the request object, you need to write a custom converter to converter the request object for you.

BTW, you can use the POJO data format this time, you should be able to get the request object directly, then you don't need to care much about JAXB data format stuff any more.  

--  
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 Monday, July 1, 2013 at 8:40 PM, cdj0579 wrote:

> Hi~
>  
> This is how my camel route looks like:
> <camelContext id="test_context" xmlns="http://camel.apache.org/schema/spring">
> <route>
> <from uri="cxf:bean:wsConsumer?dataFormat=MESSAGE" />
> <convertBodyTo type="com.mycompany.bean.TestBean" />
> <to uri="sql:select * from projects where license = # order by id?dataSource=#myDS"/>
> <to uri="log:output" />
> </route>
> </camelContext>
>  
> Below is what my camel route want to do, I found it's difficult to achieve step 2:  
> 1.setup a cxf endpoint to consume the requst,  
> 2.convert the request into one custom bean(List type)
> 3.using SqlComponent to access database(MySQL),do a query action.
> 4.logout the query result.
>  
> the step 1,3,4 is easy to achieve ,step 2 is difficult for me.
> I known we can using JAXB to unmarshal the input webservice request into a "custom bean".  
> but how the "custom bean" create from? I'm so confued. I just have a wsdl file,and the service related classes.
> Can anyone please tell me in how to create this "custom bean" ?  
>  
> Thanks in advance for any help!  
>  
>  
>  
>  
> a new camel rider
> chen jie.