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;
}
Aggregations