Jungi's Blog...


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

NetBeans 5.0 & Web service client on JBoss

Today we will create JSR-109 (container generated) web service client for the web service from my previous post. And we will use JBoss again ;-)

Creating simple UI

Code of the form in index.jsp, nothing more to say here:


Source code of form in index.jsp

Creating the client

Again an easy step - use a wizard for it. Fill in values for wsdl url (should be smth like http://localhost:8080/JBossWebservice/CalcService?WSDL), package name (I will use math.calculator.client), press Retrieve button and Finish the wizard. The client will be generated by IDE.


Coding the servlet

Now we will create the heart of our simple application - servlet which will call our web service and show us the result of that call. First, we will create some helper methods - for retrieving parameter from HttpServletRequest and for showing instance of ComplexNumber in human-readable way:


Source code of helper methods in CalcServlet.java


Following picture shows possible implementation of processRequest method without ws invocation code:


Template for processRequest method in CalcServlet.java


Now use "Web Service Client Resources -> Call Web Service Operation" action from editor's context menu on emtpy lines in our code. This action will add necessary helper methods to our servlet and also the ws operation invocation code. Only thing we have to do is to modify generated code in processRequest method. The result can look like this:


Source code of the processRequest method's template in CalcServlet.java

Building and deploying project

This is the most important part if we want to be run this project on JBoss. As in previous case (ws creation) we have to create server-side artifacts manually - here's target for project’s build.xml (if the name of your service is not CalcService replace it with yourServiceName):


Build.xml<


And the last thing we have to do is to remove JAX-RPC library from the libraries which will be packaged with our application - we need this library only for building our project. So uncheck "package" checkbox in for JAX-RPC 1.6 library in Project properties -> Libraries.


Now we are ready to deploy and run our project. 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... :-)


Troubleshooting:

  • don't forget to set proxy if you are behind firewall - most problems are caused by this. In NetBeans there it can be configured in Tools -> Options. JBoss should be started with -Dhttp.proxyHost=yourProxyHost -Dhttp.proxyPort=yourProxyPort options (can be configured in $JBOSS_HOME/bin/run.{sh|bat}). If you are setting/changing proxy during working with project, it's better to recreate the websvc client because there's currently no way how to change proxy settings for the wscompile.
  • JBoss allows user to set address which will be used in deployed WSDL - it's always good to set it to fqdn, ip address or "localhost". You can set this in $JBOSS_HOME/server/default/deploy/jboss-ws4ee.sar/META-INF/jboss-service.xml under attributte "WebServiceHost".

Comments:

Nice job, but why don't you preserve the image resolution? The images could be easily readable without clicking.

Posted by Roumen on February 03, 2006 at 03:28 PM CET #

I'm still playing with it, hope it's better now

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

Post a Comment:
Comments are closed for this entry.

Today's Page Hits: 32