Java Code Examples for com.alibaba.dubbo.rpc.RpcException#NETWORK_EXCEPTION

The following examples show how to use com.alibaba.dubbo.rpc.RpcException#NETWORK_EXCEPTION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RmiProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null && e.getCause() != null) {
        Class<?> cls = e.getCause().getClass();
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 2
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        // 是根据测试Case发现的问题,对RpcException.setCode进行设置
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 3
Source File: JsonRpcProtocol.java    From dubbo-rpc-jsonrpc with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 4
Source File: DubboParser.java    From brave with Apache License 2.0 6 votes vote down vote up
/**
 * This library is no-longer being released, so it should not have any maintenance on error codes.
 * The error codes here were defined in 2012.
 */
@Nullable static String errorCode(Throwable error) {
  if (error instanceof RpcException) {
    int code = ((RpcException) error).getCode();
    switch (code) {
      case RpcException.UNKNOWN_EXCEPTION:
        return "UNKNOWN_EXCEPTION";
      case RpcException.NETWORK_EXCEPTION:
        return "NETWORK_EXCEPTION";
      case RpcException.TIMEOUT_EXCEPTION:
        return "TIMEOUT_EXCEPTION";
      case RpcException.BIZ_EXCEPTION:
        return "BIZ_EXCEPTION";
      case RpcException.FORBIDDEN_EXCEPTION:
        return "FORBIDDEN_EXCEPTION";
      case RpcException.SERIALIZATION_EXCEPTION:
        return "SERIALIZATION_EXCEPTION";
      default:
        return String.valueOf(code);
    }
  }
  return null;
}
 
Example 5
Source File: HttpProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        // 是根据测试Case发现的问题,对RpcException.setCode进行设置
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 6
Source File: RmiProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null && e.getCause() != null) {
        Class<?> cls = e.getCause().getClass();
        // 是根据测试Case发现的问题,对RpcException.setCode进行设置
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 7
Source File: HttpProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        // 是根据测试Case发现的问题,对RpcException.setCode进行设置
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 8
Source File: RmiProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null && e.getCause() != null) {
        Class<?> cls = e.getCause().getClass();
        // 是根据测试Case发现的问题,对RpcException.setCode进行设置
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 9
Source File: JsonRpcProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 10
Source File: HttpProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example 11
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected int getErrorCode(Throwable e) {
	if (e instanceof Fault) {
        e = e.getCause();
    }
    if (e instanceof SocketTimeoutException) {
        return RpcException.TIMEOUT_EXCEPTION;
    } else if (e instanceof IOException) {
        return RpcException.NETWORK_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 12
Source File: RestExpressInvoker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static byte[] post(String url, byte[] requestContent, Map<String, String> headerMap) throws IOException {
	HttpPost httpPost = new HttpPost(url);
	if (requestContent != null) {
		HttpEntity httpEntity = new ByteArrayEntity(requestContent);
		httpPost.setEntity(httpEntity);
	}
	if (headerMap != null) {
		for (Map.Entry<String, String> entry : headerMap.entrySet()) {
			httpPost.setHeader(entry.getKey(), entry.getValue());
		}
	}
	HttpResponse response = httpclient.execute(httpPost);
	int responseCode = response.getStatusLine().getStatusCode();
	if (responseCode == HttpStatus.SC_OK || responseCode == HttpStatus.SC_CREATED
			|| responseCode == HttpStatus.SC_ACCEPTED || responseCode == HttpStatus.SC_NO_CONTENT) {
		HttpEntity responseEntity = response.getEntity();
		if (responseEntity != null) {
			return EntityUtils.toByteArray(responseEntity);
		}
	} else if (responseCode == HttpStatus.SC_NOT_FOUND) {
		throw new RpcException(RpcException.UNKNOWN_EXCEPTION, "not found service for url [" + url + "]");
	} else if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
		throw new RpcException(RpcException.NETWORK_EXCEPTION, "occur an exception at server end.");
	} else {
		throw new RpcException(RpcException.NETWORK_EXCEPTION, "Unknow HttpStatus Code");
	}
	return null;
}
 
Example 13
Source File: HessianProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof HessianConnectionException) {
        if (e.getCause() != null) {
            Class<?> cls = e.getCause().getClass();
            if (SocketTimeoutException.class.equals(cls)) {
                return RpcException.TIMEOUT_EXCEPTION;
            }
        }
        return RpcException.NETWORK_EXCEPTION;
    } else if (e instanceof HessianMethodSerializationException) {
        return RpcException.SERIALIZATION_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 14
Source File: HessianProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof HessianConnectionException) {
        if (e.getCause() != null) {
            Class<?> cls = e.getCause().getClass();
            if (SocketTimeoutException.class.equals(cls)) {
                return RpcException.TIMEOUT_EXCEPTION;
            }
        }
        return RpcException.NETWORK_EXCEPTION;
    } else if (e instanceof HessianMethodSerializationException) {
        return RpcException.SERIALIZATION_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 15
Source File: WebServiceProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
protected int getErrorCode(Throwable e) {
	if (e instanceof Fault) {
        e = e.getCause();
    }
    if (e instanceof SocketTimeoutException) {
        return RpcException.TIMEOUT_EXCEPTION;
    } else if (e instanceof IOException) {
        return RpcException.NETWORK_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 16
Source File: WebServiceProtocol.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
protected int getErrorCode(Throwable e) {
    if (e instanceof Fault) {
        e = e.getCause();
    }
    if (e instanceof SocketTimeoutException) {
        return RpcException.TIMEOUT_EXCEPTION;
    } else if (e instanceof IOException) {
        return RpcException.NETWORK_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 17
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected int getErrorCode(Throwable e) {
	if (e instanceof Fault) {
        e = e.getCause();
    }
    if (e instanceof SocketTimeoutException) {
        return RpcException.TIMEOUT_EXCEPTION;
    } else if (e instanceof IOException) {
        return RpcException.NETWORK_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 18
Source File: WebServiceProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected int getErrorCode(Throwable e) {
	if (e instanceof Fault) {
        e = e.getCause();
    }
    if (e instanceof SocketTimeoutException) {
        return RpcException.TIMEOUT_EXCEPTION;
    } else if (e instanceof IOException) {
        return RpcException.NETWORK_EXCEPTION;
    }
    return super.getErrorCode(e);
}
 
Example 19
Source File: HttpInvoker.java    From dubbo-plus with Apache License 2.0 5 votes vote down vote up
public static byte[] post(String url,byte[] requestContent,Map<String,String> headerMap) throws IOException {
    HttpPost httpPost = new HttpPost(url);
    if(requestContent!=null){
        HttpEntity httpEntity = new ByteArrayEntity(requestContent);
        httpPost.setEntity(httpEntity);
    }
    if(headerMap!=null){
        Header[] headers = new Header[headerMap.size()];
        int index=0;
        for(Map.Entry<String,String> entry:headerMap.entrySet()){
            Header header = new BasicHeader(RestfulConstants.RESTFUL_HEADER_KEY_PREFIX+entry.getKey(),entry.getValue());
            headers[index]=header;
            index++;
        }
        httpPost.setHeaders(headers);
    }
    CloseableHttpResponse response =  httpclient.execute(httpPost);
    int responseCode = response.getStatusLine().getStatusCode();
    if(responseCode==200){
        HttpEntity responseEntity = response.getEntity();
        if(responseEntity!=null){
            return EntityUtils.toByteArray(responseEntity);
        }
    }else if(responseCode==404){
        throw new RpcException(RpcException.UNKNOWN_EXCEPTION,"not found service for url ["+url+"]");
    }else if(responseCode==500){
        throw new RpcException(RpcException.NETWORK_EXCEPTION,"occur an exception at server end.");
    }
    return null;
}
 
Example 20
Source File: HessianProtocol.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
protected int getErrorCode(Throwable e) {
    if (e instanceof HessianConnectionException) {
        if (e.getCause() != null) {
            Class<?> cls = e.getCause().getClass();
            if (SocketTimeoutException.class.equals(cls)) {
                return RpcException.TIMEOUT_EXCEPTION;
            }
        }
        return RpcException.NETWORK_EXCEPTION;
    } else if (e instanceof HessianMethodSerializationException) {
        return RpcException.SERIALIZATION_EXCEPTION;
    }
    return super.getErrorCode(e);
}