Q:

How can I auto select a webservice?

My application needs to connect to a web service to get xml data. I have a primary and a secondary web service.
What is the best way to failover to the secondary web service if the primary fails to respond? Also how would I set the timeout for waiting for the primary?
Thanks

A:

The best solution is to set up a VIP for the web service, and have it failover automatically.  This way your application only cares about one endpoint and doesn't need to worry about the details.
If you really want to handle it from your Java code, it depends on what libraries you are using to connect to the web service.  If you are using core Java, it might look something like this:
try {

  URL primaryURL = new URL(web_service_endpoint);
  HttpURLConnection con = (HttpURLConnection) primaryURL.openConnection();
  con.setConnectTimeout(5000); //set timeout to 5 seconds

  //Try retrieving some XML

} catch (java.net.SocketTimeoutException e) {
  //Try connecting to secondary web service
  //Maybe a recursive method call with a different URL or something
}

