I've never used this part of the Java implementation, but the Javadoc claims: "If the implementation throws an exception, call will be closed with an error. Implementations must not throw an exception if they started processing that may use call on another thread." https://grpc.io/grpc-java/javadoc/io/grpc/ServerInterceptor.html
Based on that and what I know about interceptors in other implementations I'm assuming you should be throwing Status.PERMISSION_DENIED.asRuntimeException() instead, and not calling the next interceptor in this case. https://grpc.io/grpc-java/javadoc/io/grpc/Status.html#asRuntimeException-- Hope that helps, Evan On Monday, September 10, 2018 at 8:04:35 PM UTC-4, Jacques wrote: > > Hello, > > I have a GRPC protocol I'm working on where I want the ServerInterceptor > to terminate the call if I find the metadata invalid. What is the correct > way to do it while returning an appropriate status code (permission denied > in this case). I'm currently calling call.close() in the interceptor but > then returning the original next.startCall(). The next.startCall() throws > an exception because it is trying to work against a now closed connection. > The method declaration doesn't allow throwing a StatusException. I'm sure > there is an example of this somewhere but I didn't run across it. Example > of current code below: > > public class ServerAuthInterceptor implements ServerInterceptor { > > > @Override > > public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, > RespT> call, Metadata headers, > > ServerCallHandler<ReqT, RespT> next) { > > if (!MyThing.isValid(headers)) { > > call.close(Status.PERMISSION_DENIED, new Metadata()); > > // TODO: what do we return here to avoid the exception caused by > startCall below? > > } > > > return next.startCall(call, headers); > > } > > > } > > > Thanks! > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/59a56429-1c12-4bf6-b530-978c32d96ae2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
