Tuesday, October 20, 2009

Metro : JAX WS catalogue

One of the problems with using Netbeans to generate web services using Glassfish / Metro is that when you want to create a new Web service client, you are asked to select the web service which is normally on your local machine.

This means that the web service has an address like http://localhost:8080 and it then becomes a problem when you deploy to other environments.

One way around this is to use a catalog to resolve the addresses at run time. The file is called jax-ws-catalog.xml and it's placed in the META-INF directory.

It looks like e.g.

 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<rewriteSystem
systemIdStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/"/>
<rewriteURI
uriStartString="http://localhost:8080/"
rewritePrefix="http://some url:some port/" />
</catalog>


This searches for any URL that starts with "http://localhost:8080/" and replaces this with "http://some url:some port/" e.g.

http://localhost:8080/webserver/WebService

becomes

http://some url:some port/webserver/WebService

The ant build files in Netbeans use the -catalog option to point to a file called catalog.xml in the project root directory. You can apply the same principles to this file to resolve addresses at compile time.

Some useful links:

Using a JAX-WS Catalog

How to write an XML catalog file

Global URI re-writing with jax-ws-catalog

Enjoy!

No comments: