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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -