Catch SocketTimeOutException In cxf Jaxrsclient

时间:2017-04-06 16:59:49

标签: java exception-handling webservice-client socketexception cxf-client

I am making a rest call using apache cxf . I am able to set timeout during invoking a service and corresponding socketConnection timeout exception gets thrown but i am not able to catch the exception and set it as user definied exception. Please find the below code for time out exception

try{
    HTTPClientPolicy clientConfig = WebClient.getConfig(service).getHttpConduit().getClient(); clientConfig.setReceiveTimeout(10000);} 
catch(SocketTimeOutException e) {
          logger.error("");
         CustomException....
    }

Exception gets thrown without going inside catch block. Could someone tell me how can i catch this exception?

1 个答案:

答案 0 :(得分:0)

try to write

catch(Exception e) {
      logger.error("");
     CustomException....
}

instead of your code. Then you can catch the exception and handle it.