• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ant script to generate webservice client

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am new to webservice .i have a wsdl url.i want to create a client classes by using ant script .can any on help me
thanks
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what web service runtime (implementation, soap stack) you're using.

Say, for JAX-RS RI, use wsimport command. Google for ant with wsimport for example.

As for other implementations, something like wsdl2java (not sure the specific command name).
Check with the web service runtime (implementation, soap stack) you're using.
 
john Dalton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

H Paul wrote:It depends on what web service runtime (implementation, soap stack) you're using.

Say, for JAX-RS RI, use wsimport command. Google for ant with wsimport for example.

As for other implementations, something like wsdl2java (not sure the specific command name).
Check with the web service runtime (implementation, soap stack) you're using.





Thanks for your reply. I am using axis2 with tomcat and jboss. the wsdl2java is like topdown approah right?
is it different from web service client.please correct me
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, wsdl2java creates Java client code from a WSDL.

The first result I get on Google for "ant wsdl2java axis2" is the page you're looking for.
 
john Dalton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Yes, wsdl2java creates Java client code from a WSDL.

The first result I get on Google for "ant wsdl2java axis2" is the page you're looking for.




Then what is difference between using topdown approach and creation of Webservice client?
 
H Paul
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way I understand:

From the server side perspective: there are 2 ways to create a web service
either Top down (creating a WSDL first - the service contract)
or Bottom up (creating a server side web service java code first, then generate wsdl from the java code)

1. Top down is creating a WSDL first (the service contract)

Once I got the WSDL correctly:
a.I can give it to the web service provider to generate server side code (usually class with no logic),
here the web service provider will add logic.

b.I can give it to the client to generate client side code (wsdl2java).
The client will use these generated codes to communicate the web service provider.

2. Bottom up is creating a server side web service java code first, then I generate
the wsdl either explicitly using java2wsdl or deploy the code on the server, the server will
implicily generate the wsdl for me. Then I can give wsdl to any client to generate the client code (wsdl2java)


From the client side perspective:

All I have is the wsdl provided by the web service provider.
I use the wsdl to generate the client code to call the web service.
 
john Dalton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply paul.

Here is the my actual question stated at starting of topic


is there any way to generate client code by using the ANT script
I am usng Axis2,tomcat
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's explained on the page you get when you google the phrase I posted. There's no point repeating all that information here when it's explained and easily accessible elsewhere already.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it can be understood in a simpler manner. Since you're using Axis2 and Tomcat and Jboss, I suppose you're using Eclipse too, so it's easier to use Eclipse than raw Ant.

1) If you didn't yet, configure Eclipse to use Axis2, it's done in Window > Preferences > Web Service > Axis2 (something like that, I don't have it ATM to check names).

2) Create a Dynamic Web Project in Eclipse, it will have everything you need.

3) Right click on the src folder > new > Web Service Client.

Wizard is kinda complex and error inductor in begining, be careful to choose Axis2 instead of Axis (Eclipse brings Axis built-in and must be configured to use an externally installed Axis2, so it may wanna use Axis as default, be careful!). Eclipse has 1 or 2 plugins for testing the client, but they use Web UI and their code is kinda complex, so avoid them. Also, you're gonna be asked for the package where you wanna put the classes Axis2 will create, it uses a default ugly one and you can change it, use a specific package only for Axis2 generated classes for better organization.

4) Basically Axis2 will create 2 class files, you're gonna directly use only the Stub one. It's the WebService client that your code will consume. Open that class and you'll see it's VERY complicated, together with the main Stub class there are many inner classes. Just search in it for operations names and you're gonna find a method with same name of each operation.

This method receives an object that holds all parameters (search for its class name, then search for setters for each parameter) and returns an object holding the result (also search for its class to see how to get final result out of it).

It's kinda complex but always work the same for each WSDL operation. Once you get Axis2 feeling you'll be confortable with it and take only a few minutes to find all needed methods and classes and start consuming your stub.

Note also that Stub has 1 of many constructors, that receives a string. If you use the constructor with no parameters it will use as endpoint the one provided in WSDL, but with this string constructor you can change endpoint as wanted. This is good because WebService provider should provide the production one and also a test one in another endpoint where you can safely run tests while developing your client. You can also use Apache HTTP Monitor to bind a local port to endpoint host, then you can use replace host and port in original endpoint, with this you can monitor your calls and see raw XML envelops!

5) Ready to consume your stub, create a test class with a main method. You're gonna create a request object and set its parameters, then create a stub object and call its operation method. If nothing goes wrong it will return the response object, you can get return out of it and sysout print.

6) Once this test class works, you can use it as a basis to develop a real client that consumes your WebService services / calls its operations.

7) To deploy your client, right click the project > export > Runnable Jar File. In wizard, choose to package all depandances, so that jar will have all Axis2 jars which contains Axis2 SOAP client and HTTP client. Also choose your class with main method to be ran.

In this generated jar file, as I said, you'll have all Axis2 jars, which will provide you not only its SOAP client code (from which your Stub extends), but also a very good HTTP client. Therefore you can run this unique file directly from java JVM, you won't even need to deploy it to somewhere else. (For developing WebService server we end up with a war file that's deployed on a Servlet container. Yes, it's really amazing how this jar client has an HTTP client built-in!! In begining I thought Axis2 client also required to be deployed on Tomcat!).


and that's it!


There are way way different ways of developing SOAP clients from WSDL, this is the simplest one IMO.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic