• Share this article:

Annotated Web Services in JBoss

Thursday, June 21, 2007 - 14:54 by Wayne Beaton

I recently recorded a flash demo of the creation—using annotations—of a web service for JBoss 4.2 using a pre-release of the new Eclipse IDE for Java EE Developers (the work-in-progress landing page is here). You can find the demo here.

Creating the web service is pretty easy.

I noticed that JBoss requires an entry in the web.xml file for the web service (to be honest, I’ve spent a little too much time away from this technology to know if this is typical of other application servers, or if there is a way to encourage JBoss to work without it). Rather than try to fumble my way through the bits and pieces that are required for an entry in web.xml, I instead just created a servlet. The process of creating the servlet creates entries in the deployment descriptor along with a skeleton of a servlet class.

In the next step, I deleted most of the code generated for the servlet class and reduced it to a simple POJO along the lines of:

package org.eclipse.samples.ws;
import javax.jws.WebService;
@WebService
public class Welcome {
    public String getGreeting(String name) {
        return "Hello " + name;
    }
}

It’s pretty simplistic, but my intent is to show that building a web service is pretty easy, not build an actual interesting web service.

And that’s about it. The next step is to run it, which I do using the Servers view. Eclipse does a great job managing the servers. During the start up, JBoss reports that the web service has started and provides a URL for WSDL generated for it. In my demonstration, I use the Web Services Explorer to play a bit. I could just as easily used the WSDL to create a Java client using the New Web Service Client wizard.

One thing I learned in setting up the demonstration is that JBoss 4.2 (and 5.0) don’t run all that well with Java 6. When I attempted that, I wound up with a bunch of errors that just disappeared when I instead used a Java 5 JRE. Maybe it’s just me.

I’d love your feedback on the demo.