Jungi's Blog...


Main | NetBeans 5.0 & Web... »
Friday Feb 03, 2006

NetBeans 5.0 & Web services on JBoss

Let’s create doc/lit web service which will provide two operations: plus and minus. Sounds easy? So do it for complex type and have JBoss as target server… ;-)

Required software

Coding ComplexNumber.java

Complex number consists of real and imaginary part, so we will create a value object for it. It will have two private fields, some getters and setters and two constructors. Full code:

Source code of ComplexNumber.java

Creating Web Service

Creating web service is also an easy step there’s a wizard for its creation and actions for adding operation to web service (you can find it in the editor’s and web service’s context menu). So here’s only listing of web service implementation:

Web service implementation

Building and deploying project

This is the most important part if we want to be able to use the service which will be deployed to JBoss – we have to create server-side artifacts manually but wscompile is our friend here :-) (see JBossWSFAQ). So let’s do it – add following target into project’s build.xml (if the name of your service is not CalcService replace it with _yourServiceName_ ):

Build.xml

Now we are ready to deploy our project and to test our web service. Let's see if it works (click on the picture for better view):

Build.xml

And here you can download sources for this project. Enjoy... :-)

Comments:

unreadable graphics - crap!

Posted by citrus on February 03, 2006 at 03:12 PM CET #

Hopefully fixed ;-)

Posted by jungi on February 03, 2006 at 04:06 PM CET #

Hello, nice . but there is one suggestion (off-topic). IMHO classes like "ComplexNumber" should be immutable. like: public final class ComplexNumber{ private final int real; private final int img public ComplexNumber(int real, int img) { this.real = real; this.img = img; } // only getters. }

Posted by afsina on February 04, 2006 at 06:26 AM CET #

Hi, yes, they should be - but in this case they cannot - there are strictly defined rules for (value) objects which can be used as arguments and return types for web service operations - see j2ee tutorial.

Posted by jungi on February 04, 2006 at 06:03 PM CET #

Post a Comment:
Comments are closed for this entry.

Today's Page Hits: 11