Java Webservice Client (Best way)
Asked Answered
M

4

82

I have a third party WSDL, I need to write code in Java for a web service client to invoke the operations in the third party WSDL. Right now, I have generated the client stub using the WSDL2JAVA tool from Axis and used the XMLbeans for data binding.

  1. What is the best approach to do this JAVA?
  2. I read about SAAJ, looks like that will be more granular level of approach?
  3. Is there any other way than using the WSDL2Java tool, to generate the code. Maybe wsimport in another option. What are the pros and cons?
  4. Can someone send the links for some good tutorials on these topics?
  5. What are the options we need to use while generating the code using the WSDL2Java?

I used some of the basic things initially. Now I have these options

C:\axis2-1.5.1\bin>wsdl2java -uri  mywsdlurl  -o client -p somepackage -d xmlbeans -s -t -ssi
Mcnulty answered 27/8, 2010 at 22:46 Comment(0)
K
164

What is the best approach to do this JAVA?

I would personally NOT use Axis 2, even for client side development only. Here is why I stay away from it:

  1. I don't like its architecture and hate its counter productive deployment model.
  2. I find it to be low quality project.
  3. I don't like its performances (see this benchmark against JAX-WS RI).
  4. It's always a nightmare to setup dependencies (I use Maven and I always have to fight with the gazillion of dependencies) (see #2)
  5. Axis sucked big time and Axis2 isn't better. No, this is not a personal opinion, there is a consensus.
  6. I suffered once, never again.

The only reason Axis is still around is IMO because it's used in Eclipse since ages. Thanks god, this has been fixed in Eclipse Helios and I hope Axis2 will finally die. There are just much better stacks.

I read about SAAJ, looks like that will be more granular level of approach?

To do what?

Is there any other way than using the WSDL2Java tool, to generate the code. Maybe wsimport in another option. What are the pros and cons?

Yes! Prefer a JAX-WS stack like CXF or JAX-WS RI (you might also read about Metro, Metro = JAX-WS RI + WSIT), they are just more elegant, simpler, easier to use. In your case, I would just use JAX-WS RI which is included in Java 6 and thus wsimport.

Can someone send the links for some good tutorials on these topics?

That's another pro, there are plenty of (good quality) tutorials for JAX-WS, see for example:

What are the options we need to use while generating the code using the WSDL2Java?

No options, use wsimport :)

See also

Related questions

Konrad answered 28/8, 2010 at 9:40 Comment(13)
Amazing work, thank you. Could you please also make WSIT a link to some description of it (e.g. to download.oracle.com/docs/cd/E17802_01/webservices/webservices/…)Deliberate
@Deliberate Done, added a link to the WSIT project (the one you posted is also a good one, so readers have both).Konrad
I gave you a +1 on this long ago without even following all the links. Man alive, that bileblog hits it on the nose! :) Again, thanks for this.Wilfordwilfred
You say axis is no longer in Helios - what replaced it?Wilfordwilfred
It looks like CXF - now to get the darn thing to work :( #4407252Wilfordwilfred
+1 for Apache CXF, just built a working client code that consumes an existing TIBCO Web Service. Godspeed for CXF docs to improve more!Fridafriday
+1 for JAX-WS. Lost many days with Axis2... a total MESS (not to mention a ton of dependencies)Manella
@PascalThivent: Why is JAXWS better than Axis2 on client side development aside from Axis2 having lots of dependencies? Please don't get me wrong. I like JAXWS. In fact, that's what I'm using right now. But it takes a long time for JAXWS to load its proxies because it has to read all sorts of things from a WSDL file first. The JAXWS proxies are also not thread safe. As such, having a single proxy for the whole app is not an option. Creating a pool of proxies might also consume a lot of resources. Is there a solution for this on JAXWS?Drayage
@PascalThivent: I want to use JAXWS for the client but the thread safety issue on JAXWS is bothering me.Drayage
Hey Pascal, Glen Mazza's link is broken now.Widgeon
@AdeelAnsari I tried the internet archives but that did not work because of robots.txt. Here is an alternative link: web-gmazza.rhcloud.com/blog/entry/soap-client-tutorialImmovable
Thanks, @KarthicRaghupathi. Replaced the original with this.Widgeon
Wasted almost a day and a half stuggling to get axis2 working in my app, half of that fiddling with maven exclusions and trying to figure out how to override defaults to get httpclient 4 working. I had a client already generated from wsimport which i mistakenly thought would be better converted to axis2. Ugh... I'm sure it has it's up sides, but man o man... for a simple soap client, it's overkill.Epps
C
8

I have had good success using Spring WS for the client end of a web service app - see http://static.springsource.org/spring-ws/sites/1.5/reference/html/client.html

My project uses a combination of:

  • XMLBeans (generated from a simple Maven job using the xmlbeans-maven-plugin)

  • Spring WS - using marshalSendAndReceive() reduces the code down to one line for sending and receiving

  • some Dozer - mapping the complex XMLBeans to simple beans for the client GUI

Chlortetracycline answered 27/8, 2010 at 23:16 Comment(0)
P
1

You can find some resources related to developing web services client using Apache axis2 here.

http://today.java.net/pub/a/today/2006/12/13/invoking-web-services-using-apache-axis2.html

Below posts gives good explanations about developing web services using Apache axis2.

http://www.ibm.com/developerworks/opensource/library/ws-webaxis1/

http://wso2.org/library/136

Payton answered 25/3, 2012 at 15:41 Comment(0)
A
0

Some ideas in the following answer:

Steps in creating a web service using Axis2 - The client code

Gives an example of a Groovy client invoking the ADB classes generated from the WSDL.

There are lots of web service frameworks out there...

Aranyaka answered 28/8, 2010 at 3:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.