Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在jersey client 1.8中处理读取超时异常_Java_Jersey Client - Fatal编程技术网

Java 如何在jersey client 1.8中处理读取超时异常

Java 如何在jersey client 1.8中处理读取超时异常,java,jersey-client,Java,Jersey Client,我正在使用jersey 1.8 呼叫外部服务。 这是我的密码 try{ ClientResponse response = webResource.header(HttpHeaders.AUTHORIZATION, encodedHashString).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, formData); }catch(ClientHandlerException

我正在使用
jersey 1.8

呼叫外部服务。 这是我的密码

 try{
     ClientResponse response = webResource.header(HttpHeaders.AUTHORIZATION, encodedHashString).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, formData);
 }catch(ClientHandlerException che){
   //handelling code here
 {
当发生读取超时异常时,它给出
clienthandler异常
,而底层异常是
SocketTimeoutException
。但这里的问题是,我不能仅仅说,因为它的
ClientHandlerException
是一个超时异常,因为这个异常可能发生在其他与客户端相关的错误上。
处理它的确切代码是什么,如果是读取超时异常,我需要做一些处理。

尝试以下操作:

try {
    ClientResponse response = webResource.header(HttpHeaders.AUTHORIZATION, encodedHashString).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, formData);
} catch(ClientHandlerException ex) {
    handleClientHandlerException(ex);
}

private void handleClientHandlerException(ClientHandlerException ex) throws ClientHandlerException {
    if (ex.getCause() instanceof SocketTimeoutException) {
        // handelling SocketTimeoutException code here
    }
    throw ex;
}
HandleClientHandlexception
中,如果原因不是
SocketTimeoutException
,您还可以尝试类似于apache commons lang的方法来获取根本原因。

您可以使用guava中的方法