private void copyMetadataToThreadLocal(Metadata headers) {
String attachments = headers.get(GrpcUtil.GRPC_CONTEXT_ATTACHMENTS);
String values = headers.get(GrpcUtil.GRPC_CONTEXT_VALUES);
try {
if (attachments != null) {
Map<String, String> attachmentsMap =
SerializerUtil.fromJson(attachments, new TypeToken<Map<String, String>>() {}.getType());
RpcContext.getContext().setAttachments(attachmentsMap);
}
if (values != null) {
Map<String, Object> valuesMap =
SerializerUtil.fromJson(values, new TypeToken<Map<String, Object>>() {}.getType());
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
RpcContext.getContext().set(entry.getKey(), entry.getValue());
}
}
} catch (Throwable e) {
log.error(e.getMessage(), e);
}
}
}