Wednesday, January 27, 2010

Sankalan 2010 Goes Green….the Copenhagen Way !!

The Department of Computer Science, University of Delhi once again proudly presents to you its annual technical fest: Sankalan 2010: Compiling Innovations towards green future….

The students at the department, understand the importance of global warming and its harmful effects and thus plan to create awareness and spread the word around.


So here we are, with open arms welcoming students all over the country to come and join us in this effort and have fun along the way. Sankalan ( a hindi word meaning Compilation ) has always been a tech-fest of its own kind, with students pouring in from everywhere and making it a success.

You can find out more information like the events (both technical and non-technical) on the fest’s blog. You can check out the official site here for registration and detailed information for the fest. So pack up your bags and get ready for entertainment and fun-packed stuff. Hope to see you there at 20-21st Feburary 2010.

Friday, January 15, 2010

Creating JBossWS Web Services with JBoss 4.2.3GA and JDK1.5

Continuing from the last post, today we will learn about creating a Simple Web Service using jBossWS (a JAX-WS implementation) and deploy it on JBoss Server. Also, we will see how can we create a WS-Client using in-build utilities and consume the web service with ease.


  1. Intermediate knowledge of Java, some experience with XML would help, though not necessary.
  2. Basic Know-how of a web-application
  3. Setting up the required environment.

Getting Started:

Create a New Java Project. Name it anything you like. Create appropriate structure for a web application like we create an output folder named ‘web’ and create ‘WEB-INF’ in it, which will hold the deployment descriptor ‘web.xml’. The initial structure of our web application looks as follows:

jbossws initial project structure

With JBossWS, to create a web service is as easy as creating a Java class and exposing a method and create its entry in the deployment descriptor. Lets first create an entry in web.xml for the the EndpointServlet class and configure it for the Java class containing the Web Service implementation as shown below:Here, we specify EndpointServlet (comes bundled with JBossWS stack) which is used to publish/deploy your web service over JBoss. We also provide its mapping giving the url-pattern of the web service.
jbossws webxml

Lets see how our Java Class which contains the web service would look like:

jbossws helloworld
Notice that we have noticed JAX-WS Annotations to decorate our class. The @WebService annotations tells us that this class contains methods exposed by a web service and @WebMethod annotation points out exactly which method is exposed.

To make sure that your code compiles, you must include the JAR’s that come with JBossWS native stack. Therefore, we add the following JAR’s to the lib folder of WEB-INF and also configure it on the build-path of the project so that you do not get compilation error in Eclipse.
  • jaxb-api.jar
  • jbossws-native-jaxws-ext.jar
  • jbossws-native-jaxws.jar
  • jbossws-native-saaj.jar
So, thats all you need to do in order to expose your web service. Lets now publish this web service on JBoss. To do so, we will package it as a WAR file using ANT. I have used the following ANT script to create WAR for my web service.
jbosswss build

Now, you can copy this war file to the deploy directory of your JBoss Installation. Restart your server and check the logs to see whether it is deployed successfully or not.

[TomcatDeployer] deploy, ctxPath=/jaxWS,
[WSDLFilePublisher] WSDL published to: file:/E:/JBoss/jboss-4.2.3.GA
So, that tells you that your web service has been deployed. To double check, you can always check the JBoss web service console on this url: http://localhost:8085/jbossws/services It shows you a list of all endpoints deployed currently, something like below:

jbossws Services console

Lets also have a look at a snippet of generated WSDL, though explaining this is out of scope of this entry.

jbossws wsdl

JAX-WS provides supports for all Java in-build data types as well as for complex user-defined objects. The WSDL that is generated on publishing the web service contains all the information about the parameters accepted by the web service and also about the format in which the data is returned. Thus, this WSDL is more of a contract on which the communicating parties must agree before communicating.

Client Generation:

Now, we consume this web service by creating client using utilities provided by JBossWS stack ( Examples include wsconsume, wsget, wsrunclient etc )

>>> wsconsume –k http://localhost:8085/jaxWS/prodsWS?wsdl

wsconsume will parse the WSDL and –k option will generate the java classes which will be used by the client using JAXB framework.

Now, we will create a TestClient (to test our webservice), which will finally consume the web service.

jbossws client

As expected, on running this client, it will print “Hello My Name is Agraj” as output. Please note that in order to run this client successfully, you must add few more client jars to the project.

The final structure of the web application (web service + client) looks like following:

jbossws final project structure
So, that’s all I want to talk about web services today, I hope it was of some help. Please post your views or corrections as comments.

Note: You may encounter a few problems while developing web services using JBossWS and JDK 1.6 since there are some compatibility issues and conflicting jars that create problems. Your best friend in such a case is Google :-)