You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by dilipmathi <di...@gmail.com> on 2012/08/24 17:03:14 UTC

Question about CXF DynamicClientFactory

I needs to generate Java client for Webservice. I have two choices to do that
one is use apache cxf DynamicClientFactory class and other is use Dispatch
API .

>From CXF documentation i understood that DynamicClientFactory class will
generate the Webservice SEI , Data classes in runtime(Using wsdl2Java tool).
If i wants to call any webservice methods i needs to load the appropriate
data class name and i needs to set the parameter using reflection like
follows.

JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("people.wsdl", classLoader);

Object person =
Thread.currentThread().getContextClassLoader().loadClass("com.acme.Person").newInstance();

Method m = person.getClass().getMethod("setName", String.class);
m.invoke(person, "Joe Schmoe");

client.invoke("addPerson", person);

In the above code the Person class is generated in the runtime by CXF and
reflection is used to set the property values . My question here is if i
wants to set 20 parameter values, then i needs to make 20 reflection call to
do that.Is this a efficient way to do that? or any alternative is there.

or better to use Dispatch API . Please help me. Thanks in advance.



--
View this message in context: http://cxf.547215.n5.nabble.com/Question-about-CXF-DynamicClientFactory-tp5713112.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Question about CXF DynamicClientFactory

Posted by Daniel Kulp <dk...@apache.org>.
In general, my advice is:

If you have the schema or WSDL at compile time, generate code at that point from the xsd and use the Dispatch client.   It's very simple.

If you do not have the WSDL/XSD at compile time, you kind of have to use the DynamicClientFactory and a ton of reflection.

If you are using a dynamic language like Groovy or some other template thing (velocity, etc..) that does the reflection for you under the covers, using the dynamic client also works very well.

Dan




On Aug 24, 2012, at 11:03 AM, dilipmathi <di...@gmail.com> wrote:

> I needs to generate Java client for Webservice. I have two choices to do that
> one is use apache cxf DynamicClientFactory class and other is use Dispatch
> API .
> 
> From CXF documentation i understood that DynamicClientFactory class will
> generate the Webservice SEI , Data classes in runtime(Using wsdl2Java tool).
> If i wants to call any webservice methods i needs to load the appropriate
> data class name and i needs to set the parameter using reflection like
> follows.
> 
> JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
> Client client = dcf.createClient("people.wsdl", classLoader);
> 
> Object person =
> Thread.currentThread().getContextClassLoader().loadClass("com.acme.Person").newInstance();
> 
> Method m = person.getClass().getMethod("setName", String.class);
> m.invoke(person, "Joe Schmoe");
> 
> client.invoke("addPerson", person);
> 
> In the above code the Person class is generated in the runtime by CXF and
> reflection is used to set the property values . My question here is if i
> wants to set 20 parameter values, then i needs to make 20 reflection call to
> do that.Is this a efficient way to do that? or any alternative is there.
> 
> or better to use Dispatch API . Please help me. Thanks in advance.
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Question-about-CXF-DynamicClientFactory-tp5713112.html
> Sent from the cxf-user mailing list archive at Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com