How can I automatically select a web service?

My application must connect to the web service in order to receive the XML data. I have a primary and secondary web service.

What is the best way to return to a secondary web service if the primary is not responding? Also how to set a timeout to wait for the primary?

thank

+3
source share
1 answer

The best solution is to create a VIP for the web service and automatically recover from a failure. Thus, your application only cares about one endpoint and does not need details.

Java, , -. Java, :

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
}
+1

Source: https://habr.com/ru/post/1794160/


All Articles