use of com.alipay.remoting.rpc.protocol.RpcResponseCommand in project dingo by dingodb.
the class ProtobufSerializer method serializeContent.
@Override
public <T extends ResponseCommand> boolean serializeContent(T response) throws SerializationException {
final RpcResponseCommand cmd = (RpcResponseCommand) response;
final Message msg = (Message) cmd.getResponseObject();
cmd.setContent(msg.toByteArray());
return true;
}
use of com.alipay.remoting.rpc.protocol.RpcResponseCommand in project sofa-jraft by sofastack.
the class ProtobufSerializer method deserializeContent.
@Override
public <T extends ResponseCommand> boolean deserializeContent(T response, InvokeContext invokeContext) throws DeserializationException {
final RpcResponseCommand cmd = (RpcResponseCommand) response;
final String className = cmd.getResponseClass();
cmd.setResponseObject(ProtobufMsgFactory.newMessageByJavaClassName(className, response.getContent()));
return true;
}
use of com.alipay.remoting.rpc.protocol.RpcResponseCommand in project sofa-jraft by sofastack.
the class ProtobufSerializer method serializeContent.
@Override
public <T extends ResponseCommand> boolean serializeContent(T response) throws SerializationException {
final RpcResponseCommand cmd = (RpcResponseCommand) response;
final Message msg = (Message) cmd.getResponseObject();
cmd.setContent(msg.toByteArray());
return true;
}
use of com.alipay.remoting.rpc.protocol.RpcResponseCommand in project sofa-rpc by sofastack.
the class SofaRpcSerializationTest method serializeResponseContent.
@Test
public void serializeResponseContent() {
String traceId = "traceId";
String rpcId = "rpcId";
RpcInternalContext.getContext().setAttachment("_trace_id", traceId);
RpcInternalContext.getContext().setAttachment("_span_id", rpcId);
RpcResponseCommand command = new RpcResponseCommand();
SofaRpcSerialization sofaRpcSerialization = new SofaRpcSerialization();
boolean exp = false;
try {
sofaRpcSerialization.serializeContent(command);
} catch (SerializationException e) {
exp = true;
Assert.assertTrue(e.getMessage().contains("traceId=" + traceId + ", rpcId=" + rpcId));
}
Assert.assertTrue(exp);
}
use of com.alipay.remoting.rpc.protocol.RpcResponseCommand 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