Search in sources :

Example 6 with SerializationException

use of com.alipay.remoting.exception.SerializationException in project sofa-rpc by sofastack.

the class BoltClientTransport method convertToRpcException.

/**
 * 转换调用出现的异常为RPC异常
 *
 * @param e 异常
 * @return RPC异常
 */
protected SofaRpcException convertToRpcException(Exception e) {
    SofaRpcException exception;
    if (e instanceof SofaRpcException) {
        exception = (SofaRpcException) e;
    } else // 超时
    if (e instanceof InvokeTimeoutException) {
        exception = new SofaTimeOutException(e);
    } else // 服务器忙
    if (e instanceof InvokeServerBusyException) {
        exception = new SofaRpcException(RpcErrorType.SERVER_BUSY, e);
    } else // 序列化
    if (e instanceof SerializationException) {
        boolean isServer = ((SerializationException) e).isServerSide();
        exception = isServer ? new SofaRpcException(RpcErrorType.SERVER_SERIALIZE, e) : new SofaRpcException(RpcErrorType.CLIENT_SERIALIZE, e);
    } else // 反序列化
    if (e instanceof DeserializationException) {
        boolean isServer = ((DeserializationException) e).isServerSide();
        exception = isServer ? new SofaRpcException(RpcErrorType.SERVER_DESERIALIZE, e) : new SofaRpcException(RpcErrorType.CLIENT_DESERIALIZE, e);
    } else // 长连接断连
    if (e instanceof ConnectionClosedException) {
        exception = new SofaRpcException(RpcErrorType.CLIENT_NETWORK, e);
    } else // 客户端发送失败
    if (e instanceof InvokeSendFailedException) {
        exception = new SofaRpcException(RpcErrorType.CLIENT_NETWORK, e);
    } else // 服务端未知异常
    if (e instanceof InvokeServerException) {
        exception = new SofaRpcException(RpcErrorType.SERVER_UNDECLARED_ERROR, e.getCause());
    } else // 客户端未知
    {
        exception = new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, e);
    }
    return exception;
}
Also used : InvokeTimeoutException(com.alipay.remoting.rpc.exception.InvokeTimeoutException) SerializationException(com.alipay.remoting.exception.SerializationException) SofaTimeOutException(com.alipay.sofa.rpc.core.exception.SofaTimeOutException) InvokeSendFailedException(com.alipay.remoting.rpc.exception.InvokeSendFailedException) ConnectionClosedException(com.alipay.remoting.exception.ConnectionClosedException) InvokeServerException(com.alipay.remoting.rpc.exception.InvokeServerException) InvokeServerBusyException(com.alipay.remoting.rpc.exception.InvokeServerBusyException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) DeserializationException(com.alipay.remoting.exception.DeserializationException)

Example 7 with SerializationException

use of com.alipay.remoting.exception.SerializationException in project sofa-rpc by sofastack.

the class SimpleMapSerializer method encode.

/**
 * 简单 map 的序列化过程, 用来序列化 bolt 的 header
 *
 * @param map bolt header
 * @return 序列化后的 byte 数组
 * @throws SerializationException SerializationException
 */
public byte[] encode(Map<String, String> map) throws SerializationException {
    if (map == null || map.isEmpty()) {
        return null;
    }
    UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(64);
    try {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            /**
             * 排除不写null作为key
             */
            if (key != null && value != null) {
                writeString(out, key);
                writeString(out, value);
            }
        }
        return out.toByteArray();
    } catch (IOException ex) {
        throw new SerializationException(ex.getMessage(), ex);
    }
}
Also used : SerializationException(com.alipay.remoting.exception.SerializationException) UnsafeByteArrayOutputStream(com.alipay.sofa.rpc.common.struct.UnsafeByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SerializationException (com.alipay.remoting.exception.SerializationException)7 DeserializationException (com.alipay.remoting.exception.DeserializationException)5 RpcResponseCommand (com.alipay.remoting.rpc.protocol.RpcResponseCommand)3 DefaultCustomSerializer (com.alipay.remoting.DefaultCustomSerializer)2 ConnectionClosedException (com.alipay.remoting.exception.ConnectionClosedException)2 InvokeSendFailedException (com.alipay.remoting.rpc.exception.InvokeSendFailedException)2 InvokeServerBusyException (com.alipay.remoting.rpc.exception.InvokeServerBusyException)2 InvokeServerException (com.alipay.remoting.rpc.exception.InvokeServerException)2 InvokeTimeoutException (com.alipay.remoting.rpc.exception.InvokeTimeoutException)2 Serializer (com.alipay.sofa.rpc.codec.Serializer)2 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)2 SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)2 AbstractByteBuf (com.alipay.sofa.rpc.transport.AbstractByteBuf)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 RpcRequestCommand (com.alipay.remoting.rpc.protocol.RpcRequestCommand)1 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)1 UnsafeByteArrayOutputStream (com.alipay.sofa.rpc.common.struct.UnsafeByteArrayOutputStream)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1