Search in sources :

Example 6 with DeserializationException

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

the class SofaRpcSerialization method deserializeContent.

@Override
public <Response extends ResponseCommand> boolean deserializeContent(Response response, InvokeContext invokeContext) throws DeserializationException {
    if (response instanceof RpcResponseCommand) {
        RpcResponseCommand responseCommand = (RpcResponseCommand) response;
        byte serializer = response.getSerializer();
        byte[] content = responseCommand.getContent();
        if (content == null || content.length == 0) {
            return false;
        }
        long deserializeStartTime = System.nanoTime();
        try {
            Object sofaResponse = ClassUtils.forName(responseCommand.getResponseClass()).newInstance();
            Map<String, String> header = (Map<String, String>) responseCommand.getResponseHeader();
            if (header == null) {
                header = new HashMap<String, String>();
            }
            putKV(header, RemotingConstants.HEAD_TARGET_SERVICE, (String) invokeContext.get(RemotingConstants.HEAD_TARGET_SERVICE));
            putKV(header, RemotingConstants.HEAD_METHOD_NAME, (String) invokeContext.get(RemotingConstants.HEAD_METHOD_NAME));
            putKV(header, RemotingConstants.HEAD_GENERIC_TYPE, (String) invokeContext.get(RemotingConstants.HEAD_GENERIC_TYPE));
            Serializer rpcSerializer = com.alipay.sofa.rpc.codec.SerializerFactory.getSerializer(serializer);
            rpcSerializer.decode(new ByteArrayWrapperByteBuf(responseCommand.getContent()), sofaResponse, header);
            if (sofaResponse instanceof SofaResponse) {
                parseResponseHeader(header, (SofaResponse) sofaResponse);
            }
            responseCommand.setResponseObject(sofaResponse);
            return true;
        } catch (Exception ex) {
            throw new DeserializationException(ex.getMessage(), ex);
        } finally {
            // R5:Record response deserialization time
            recordDeserializeResponse(responseCommand, invokeContext, deserializeStartTime);
        }
    }
    return false;
}
Also used : ByteArrayWrapperByteBuf(com.alipay.sofa.rpc.transport.ByteArrayWrapperByteBuf) DeserializationException(com.alipay.remoting.exception.DeserializationException) SerializationException(com.alipay.remoting.exception.SerializationException) DeserializationException(com.alipay.remoting.exception.DeserializationException) RpcResponseCommand(com.alipay.remoting.rpc.protocol.RpcResponseCommand) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) HashMap(java.util.HashMap) Map(java.util.Map) Serializer(com.alipay.sofa.rpc.codec.Serializer) DefaultCustomSerializer(com.alipay.remoting.DefaultCustomSerializer)

Aggregations

DeserializationException (com.alipay.remoting.exception.DeserializationException)6 SerializationException (com.alipay.remoting.exception.SerializationException)4 HashMap (java.util.HashMap)4 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 RpcRequestCommand (com.alipay.remoting.rpc.protocol.RpcRequestCommand)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 ByteArrayWrapperByteBuf (com.alipay.sofa.rpc.transport.ByteArrayWrapperByteBuf)2 Map (java.util.Map)2 Test (org.junit.Test)2 RpcResponseCommand (com.alipay.remoting.rpc.protocol.RpcResponseCommand)1 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)1 UnsafeByteArrayInputStream (com.alipay.sofa.rpc.common.struct.UnsafeByteArrayInputStream)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1