我有2个GRPC拦截器:
#1从消息中提取一些数据
#2验证数据并在无效
时关闭调用错误拦截器#1如何从消息中提取一些数据,将其放入Context
并调用拦截器#2(使用带有修改后的Contexts.interceptCall(context, call, headers, next)
实例的Context
)?
问题是我无法以覆盖<ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next)
访问邮件。
使用ForwardingServerCallListener.SimpleForwardingServerCallListener
没有帮助,因为拦截器#1的interceptCall()
在拦截器#1的onMessage()
之前被调用。
private Object msg;
private <ReqT, RespT> ServerCall.Listener<ReqT> interceptCallAfterMessage(
final ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next) {
Context context = Context.current().withValue("msg", msg); // error: msg is not yet extracted !
return Contexts.interceptCall(context, call, headers, next);
}
...
new ForwardingServerCallListener.SimpleForwardingServerCallListener(
interceptCallAfterMessage(call, headers, next)) { // happens first
@Override
public void onMessage(Object message) {
msg = message; // happens second
super.onMessage(message);
}
};