java - WebServices - How can i catch ConnectException? -


i have 2 servers (primary , secondary) , corresponding clients. both using same wsdl contract (so can't change operations) because want server fault tolerant. doing verify primary server , running pinging secondary. when primary server doesn't answer know server down. main problem when try ping disconnected server sends:

javax.xml.ws.webserviceexception: java.net.connectexception: connection refused

how can catch exception if never thrown in body of function? or there way verify if server up?

here code:

secondary server

private void isalive(){         string alive = null;         try {             client client = new client(uddiurl, wsname);             while(true){                                 try {                     alive = client.ping("alive");                 } catch (connectexception e1) {                     system.out.println("primary server down");                 }                 try {                     thread.sleep(2000);                 } catch (interruptedexception e) {                     e.printstacktrace();                 }                 if(alive.equals("alive")){                     system.out.println("still up");                 }             }         } catch (brokerclientexception e) {             system.err.print("failed create brokerclient");             e.printstacktrace();             return ;         }     } 

primary server

public string ping(string message){         return message; } 


Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -