Skip to main content

About that proxy server ...

Posted by gsporar on May 27, 2005 at 11:36 AM PDT

During his excellent demo of the new features in NetBeans 4.1, Roman Strobl shows how easy it is to create a client that uses Google's web services API. Brian Leonard also does a demo of a web services client that uses Google.

So I tried it out. It's basically a two step process. From the context menu of an enterprise or web application choose New > Web Service Client. Specify the URL of the WSDL file and then click the Retrieve WSDL button:

wsClient2.png

Naturally, if like me you are running NetBeans behind a firewall you'll need to specify a proxy host and proxy port by first clicking on the Proxy Settings... button. Then NetBeans will be able to look up the WSDL.

Step two of the process is to invoke the web service from within your code. Here NetBeans helps out with a wizard that generates the necessary JNDI lookups, etc. You can get access to that functionality by right-clicking within your source file and choosing Web Service Client Resources > Call Web Service Operation.

So I did those steps, choosing to use Google's doSpellingSuggestion API. Everything went fine until it came time to actually call the web service. I got this error message:

java.rmi.RemoteException: HTTP transport error: java.net.UnknownHostException: api.google.com; nested exception is: HTTP transport error: java.net.UnknownHostException: api.google.com

Hmmmm.... A proxy problem. NetBeans can get to Google to read the WSDL because I gave it proxy settings. But my application cannot because it has not allowed for the firewall. The code generated by NetBeans does not handle this, which is reasonable because NetBeans cannot assume that my application will be behind the same firewall that I am behind while running NetBeans.

One solution is to set the appropriate proxy properties in my source code, but that involves setting permissions, etc. With some help from fellow NetBeans users, I decided to instead modify the properties via -D values passed to the JVM that runs my application.

Since the application is deployed to the bundled Sun Java System Application Server (SJSAS), this should be simple enough. But there was an important piece of information that I was missing: in order to change the SJSAS JVM options from within NetBeans, SJSAS had to be up and running. It's only a minor inconvenience, but I had been hoping I could set the properties before starting the server. Take a look at the entries that are under its entry in the Runtime tab:

JVM.png

Those entries are only listed when the server is running. So to make the change I right-clicked the JVMs entry and chose Properties. On the JVMOptions line of the dialog that displayed I clicked the ... button. That took me to the dialog below, where I was able to type in entries for http.proxyHost and http.proxyPort.

JVMOptions.png

Stopping and restarting the server then got me the desired result: I can access Google's web services from behind a firewall.