Skip to content

调用接口传递@TarsContext java.util.Map<String, String> ctx 参数无效 #224

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

Open
wants to merge 2 commits into
base: v1.7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -47,6 +47,7 @@ protected void doRealInvoke(Request request, Response response) throws Throwable
BeanAccessor.setBeanValue(tarsServantResponse, "result", result.getResult());
BeanAccessor.setBeanValue(tarsServantResponse, "ret", result.getRet());
BeanAccessor.setBeanValue(tarsServantResponse, "remark", result.getRemark());
BeanAccessor.setBeanValue(tarsServantResponse, "context", result.getContext());
} catch (Exception e) {
BeanAccessor.setBeanValue(tarsServantResponse, "cause", e);
throw e;
Expand Down
19 changes: 12 additions & 7 deletions core/src/main/java/com/qq/tars/rpc/protocol/tars/TarsCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,20 @@ public void decodeResponseBody(ServantResponse resp) throws ProtocolException {
response.setResult(results[i++]);
}

response.setContext((HashMap<String, String>) is.read(TarsHelper.STAMP_MAP, 9, false));
List<TarsMethodParameterInfo> list = methodInfo.getParametersList();
for (TarsMethodParameterInfo info : list) {
if (!TarsHelper.isHolder(info.getAnnotations())) {
continue;
}
try {
TarsHelper.setHolderValue(request.getMethodParameters()[info.getOrder() - 1], results[i++]);
} catch (Exception e) {
throw new ProtocolException(e);
if (TarsHelper.isHolder(info.getAnnotations())) {
try {
TarsHelper.setHolderValue(request.getMethodParameters()[info.getOrder() - 1], results[i++]);
} catch (Exception e) {
throw new ProtocolException(e);
}
} else if (TarsHelper.isContext(info.getAnnotations()) && response.getContext() != null) {
Map<String, String> context = (HashMap<String, String>) request.getMethodParameters()[info.getOrder() - 1];
if (context != null) {
context.putAll(response.getContext());
}
}
}
response.setStatus((HashMap<String, String>) is.read(TarsHelper.STAMP_MAP, 7, false));
Expand Down