Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Compatible with Protobuf empty object. #1376

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ public <Request extends RequestCommand> boolean deserializeContent(Request reque
long deserializeStartTime = System.nanoTime();
try {
byte[] content = requestCommand.getContent();
if (content == null || content.length == 0) {
EvenLjj marked this conversation as resolved.
Show resolved Hide resolved
throw new DeserializationException("Content of request is null");
// The content may be empty in protobuf protocol scenario.
if (content == null) {
content = new byte[0];
}
String service = headerMap.get(RemotingConstants.HEAD_SERVICE);
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Expand All @@ -282,8 +283,7 @@ public <Request extends RequestCommand> boolean deserializeContent(Request reque
Serializer rpcSerializer = com.alipay.sofa.rpc.codec.SerializerFactory
.getSerializer(requestCommand.getSerializer());
Object sofaRequest = ClassUtils.forName(requestCommand.getRequestClass()).newInstance();
rpcSerializer.decode(new ByteArrayWrapperByteBuf(requestCommand.getContent()),
sofaRequest, headerMap);
rpcSerializer.decode(new ByteArrayWrapperByteBuf(content), sofaRequest, headerMap);

//for service mesh or other scene, we need to add more info from header
setRequestPropertiesWithHeaderInfo(headerMap, sofaRequest);
Expand Down Expand Up @@ -431,8 +431,8 @@ public <Response extends ResponseCommand> boolean deserializeContent(Response re
RpcResponseCommand responseCommand = (RpcResponseCommand) response;
byte serializer = response.getSerializer();
byte[] content = responseCommand.getContent();
if (content == null || content.length == 0) {
return false;
if (content == null) {
content = new byte[0];
}
long deserializeStartTime = System.nanoTime();

Expand All @@ -451,7 +451,7 @@ public <Response extends ResponseCommand> boolean deserializeContent(Response re
(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);
rpcSerializer.decode(new ByteArrayWrapperByteBuf(content), sofaResponse, header);
if (sofaResponse instanceof SofaResponse) {
parseResponseHeader(header, (SofaResponse) sofaResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ public SofaResponse invoke(SofaRequest sofaRequest, int timeout)
buildCustomCallOptions(sofaRequest, timeout), request);

SofaResponse sofaResponse = new SofaResponse();
byte[] responseDate = response.getData().toByteArray();
byte[] responseData = response.getData().toByteArray();
Class returnType = sofaRequest.getMethod().getReturnType();
if (returnType != void.class) {
if (responseDate != null && responseDate.length > 0) {
Serializer responseSerializer = SerializerFactory.getSerializer(response.getSerializeType());
Object appResponse = responseSerializer.decode(new ByteArrayWrapperByteBuf(responseDate), returnType, null);
sofaResponse.setAppResponse(appResponse);
}
Serializer responseSerializer = SerializerFactory.getSerializer(response.getSerializeType());
Object appResponse = responseSerializer.decode(new ByteArrayWrapperByteBuf(responseData), returnType, null);
sofaResponse.setAppResponse(appResponse);
}

return sofaResponse;
Expand Down Expand Up @@ -250,13 +248,11 @@ private void processSuccess(boolean needDecode, RpcInternalContext context, Sofa
Object appResponse = o;
if (needDecode) {
Response response = (Response) o;
byte[] responseDate = response.getData().toByteArray();
byte[] responseData = response.getData().toByteArray();
Class returnType = sofaRequest.getMethod().getReturnType();
if (returnType != void.class) {
if (responseDate != null && responseDate.length > 0) {
Serializer responseSerializer = SerializerFactory.getSerializer(response.getSerializeType());
appResponse = responseSerializer.decode(new ByteArrayWrapperByteBuf(responseDate), returnType, null);
}
Serializer responseSerializer = SerializerFactory.getSerializer(response.getSerializeType());
appResponse = responseSerializer.decode(new ByteArrayWrapperByteBuf(responseData), returnType, null);
}
}

Expand Down
Loading