Tuesday, March 17, 2009

NetBeans and Web Services

NetBeans is a great tool when it comes to web services (just like for all the rest, of course), and creating a web service client is just a couple of clicks away. First of all you right-click on Web Service Reference, expand the New menu item and select Web Service Client...

...then you simply tell the system where the WSDL is located, choose a client style and you're done.

NetBeans prepares a reference to each operation that you can simply drag wherever you need it: NetBeans will create a skeleton for you to customize.

I have just received the happy assignment of documenting all the tests for a system we're realizing on the IBM i5 platform using RPGLE. The project started with more than 600 pages of detailed requirements we delivered more than one year ago, without a single line of code. Now it looks like the customer has decided that we should start developing (at last!), and I wanted (and I still want) to avoid rewriting the Ulysses, as nobody is probably going to read it (probably the same fate shared by our detailed requirements, even if they were actually very good).

Luckily the system must expose all its features via web services, and we must also integrate them in a Java web application, so I thought "well, I have to prepare a facade and test it anyway, why don't I write some fixtures and document the system with Fit tables?"

After some debates with non technical managers, who often prefer a sound ream of paper, I convinced them of the advantages of my solution, then I started working right on it:
  • deploy a new instance of FitNesse (copy and launch would be closer)
  • create a simple test table
  • create a new project in NetBeans for the facade
  • create a new web service client
  • create a new class that uses the web service
  • create a new project in NetBeans for the fixtures
  • add the reference to the facade
  • create a new fixtures for the test table
  • Test!
"Null pointer exception? what do you mean with "Null pointer exception"? Let's check the output...

javax.xml.ws.WebServiceException: Failed to access the WSDL at: file:/C:/my/path/to/Project/xml-resources/web-service-references/SERVICE_WS/wsdl/ It failed with: C:\my\path\to\Service\xml-resources\web-service-references\SERVICE_WS\wsdl\\web\services\SERVICE_WS.wsdl (Impossibile trovare il percorso specificato).

That's strange... we'd already use this reference and jar trick in other projects and it worked perfectly well... following tonyx's advice I tried to work out the reference to the wsdl file, directly cabled in one of the NetBeans generated classes. After some experimenting I managed to tell NetBeans to always refer to the online wsdl for classes generation: you simply right-click your reference, select the menu item Edit web service attributes and from the wsimport options you add the option wsdllocation with the URL of the wsdl as a value.

Now my FitNesse instance happily colors my test table! Ops... red cells? the service is not working as expected... well, when do you want to know you have a problem? As soon as possible, which is now. Hey, you there, RPGLE guys... take a look at this! :-)

1 comment:

branajam said...

My name is James Branam and I'm the NetBeans Community Docs Manager. Your blog entry would make a fantastic tutorial for our Community Docs wiki (http://wiki.netbeans.org//CommunityDocs). Would you be willing to contribute it? If you need any help or have any questions, please contact me at james.branam@sun.com. I look forward to hearing from you.