Pages

Saturday, April 12, 2008

Developing JAX-WS based Web Services using Java WSDP

After developing web services using JAX-RPC, I shifted my attention to another web service standard for Java - JAX-WS (Java API for XML based web services). It is a successor to JAX-RPC 1.1, and obviously, it enjoys some advantages over its predecessor.

The major differences between the two standards are:
  1. JAX-WS supports SOAP 1.2, and XML over HTTP.
  2. JAX-RPC supports WS-I's Basic Profile (BP) version 1.0. JAX-WS supports BP 1.1. (WS-I is the Web services interoperability organization.)
  3. JAX-RPC maps to Java 1.4. JAX-WS maps to Java 5.0. JAX-WS relies on many of the features new in Java 5.0.
  4. JAX-WS's data mapping model is JAXB, unlike JAX-RPC. which create LiteralSerializer classes for all the data elements.
  5. JAX-RPC handlers rely on SAAJ 1.2. JAX-WS handlers rely on the new SAAJ 1.3 specification.
  6. JAX-WS heavily relies on annotations.
Now, for the implementation. I created a sample web service application based on JAX-WS (the pack comes with the Java WSDP). To develop a web service, two tasks are provided: wsimport and wsgen.

wsimport creates service artifacts and client stubs by looking into the WSDL. wsgen reads a web service endpoint class and generates all the required artifacts for web service deployment, and invocation. Both need to be used together to create a web service.

The steps that need to be followed for creating a web service and deploying it can be listed down as follows (refer to the build.xml in the uploaded zip file):
  1. Create the WSDL (assuming top-down approach) .
  2. Generate the service interfaces using wsimport. Additionally, server binding configuration xml can be used to specify the namespace mapping with Java packages, and specifying the server side handlers. Refer to the ant task - create-server-wsdl.
  3. Implement service endpoint using the interface.
  4. Generate the service artifacts from the implemented class using wsgen. This generally comprises of JAXB objects.
  5. Create a war file, which has the following structure:
    • WEB-INF/classes
    • WEB-INF/lib
    • WEB-INF/web.xml
    • WEB-INF/sun-jaxws.xml
    • WEB-INF/wsdl/wsdl-file.wsdl
    (For steps 4 and 5, refer to the ant task - build-war)
The sun-jaxws.xml is an additional file which needs to be created. It specifies the end point interfaces, the implementation class, the port, and the url pattern for the service, which is used by the container in which the service is deployed.

Once the war is created, it can be deployed on any web server/ application server. I tested it on both Tomcat web server 5 and Sun Application Server 9.

The client stubs can be generated using the wsimport and specifying the WSDL file. (ant task - create-client-wsdl). Again, the binding configuration file for the client can be used to provide namespace mapping and client side handlers.

As with JAX-RPC implementation, the wsimport and wsgen tasks are dependent on a number of configuration xml files. But unlike the wsdeploy task in JAX-RPC, where a valid web.xml deployment descriptor is created with a listener class and a JAX-RPC servlet automatically, here, in JAX-WS, these entries have to be manually entered. Also, there is a heavy use of annotations, and JAXB objects.

The sample application, together with the build script is uploaded as BookQuoteService.zip

Thursday, April 10, 2008

Developing JAX-RPC based Web Services using Java WSDP


A bit of technical stuff today. Yesterday I tried out Sun's WSDP (Web Services Development Pack) to create client and server side artifacts using WSDL, and deploying it on a web server.
Earlier, I used to develop web services using BEA's Weblogic workshop, which had loads of automated tools to create the service en
dpoint interfaces, looking at the WSDL, and generate client proxies to invoke the web services. But, as I am currently studying about JAX-RPC, I was interested to try out the JAX-RPC implementation developed by Sun.
I downloaded the available Java WSDP pack from the Sun site. I used the tools present in the pack to compile and deploy a web service: wscompile and wsdeploy. It started by creation of a sample WSDL file. Once created, I created an ant build script which made use of wscompile to generate server side artifcats. This als
o involved the creation of a configuration file for the wscompile task to understand. Once the service endpoint interfaces were generated, I implemented the iterface with a dummy web service, and compiled the whole application.

There are 2 phases of development of a w
eb service using the pack - first a raw WAR file is created, having the server side classes, a web deployment descriptor (web.xml), and a JAX-RPC deployment descriptor (jaxrpc-ri.xml). The raw WAR file has the following structure:
  • WEB-INF/classes
  • WEB-INF/jaxrpc-ri.xml
  • WEB-INF/web.xml
  • WEB-INF/model.xml.gz
The model.xml.gz file is generated while using wscompile.
Based on the jaxrpc-ri.xml (has to be manually created), use the wsdeploy task to create a "cooked" WAR which is ready to be deployed on a web server. Again, in the original Ant build script, this task was added.

Once the service is deployed, now comes the creation of client stubs/proxies to invoke the webservice. Using the same wscompile to
ol (but this time specifying that the client side artifacts need to be generated), the client stubs are created, and thats about it.

The configuration files provides all the f
eatures to include handlers, namespace mapping etc which is generally needed in the web service.

With this development pack, only JSE (Java Service Endpoints) are created (no EJB endpoints).

For further details, and instructions (including sample applications), refer to Understanding your JAX-RPC SI Environment.

The sample application can be downloaded here.

Tuesday, April 08, 2008

Angry pup, eh???

While I am posting about pets and dogs, I thought of putting this picture on my blog too... I just couldn't stop laughing when I came across this pic somewhere on the internet :)

Nostalgia....

Today, as I was going through my photo albums, I thought of selecting some of the cutest pics of my pets. I remember clicking so many pics whenever I bought a new film for my camera. Here are some of those timeless snaps....

Every time I look at these photographs, I miss them even more....

Monday, April 07, 2008

The Darjeeling Limited - Is that supposed to be India???

Some weeks back, I had the opportunity to watch a movie named "The Darjeeling Limited". And I was disappointed, seriously. It tells the story of 3 brothers, who have drifted apart from each other, make a soul-searching trip to India - and what a trip it turns out to be!!! They show nonsense stuffs happening to them in India.
Let me elaborate - for one, the train is named "The Darjeeling Limited", but believe me, it is no where near the scenic hill station - it keeps wandering in the desert, and sometimes gets lost too!!! Yup, you have heard me right, they show that the Indian trains get lost, even though its moving on railway tracks!!! Can you beat that???Then comes the train itself - I don't know what kind of rickety tourist train have they shown.

India is shown as a land of snake charmers - one of the three brothers, on a trip to some Hindu temple, buys a snake!!! And, somehow that snake is lost in the train. The head steward(or whatever) of the train, takes the snake, and worships him. Weird!!!And to top it all, they show some "International" airport, and my goodness, what an airport it is - it seems shabbier than the dirtiest railway stations in the smallest towns in the country!!

The way India has been depicted in the movie is seriously disappointing - I wonder what the director was even thinking... The movie has an impressive star cast by the way, and that was the only reason, I was interested to watch the movie in the first place - Owen Wilson, Andrien Brody and Jason Schwartzman play the role of the 3 brothers. Irfan Khan also has a small role in the film, even though, without any dialogs...