Got it, thanks! On Tue, Sep 11, 2018 at 8:55 PM 'Carl Mastrangelo' via grpc.io < [email protected]> wrote:
> Personally, I would return a Noop Listener and not call next.startCall. > There's an example in our testing package called NoopServerCallListener, > but you should make your own, as we may change that one in the future. > > On Tuesday, September 11, 2018 at 2:50:21 PM UTC-7, Evan Jones wrote: >> >> 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/096d69d5-f859-4183-8e5e-245fa78fc20e%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/096d69d5-f859-4183-8e5e-245fa78fc20e%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAKa9qD%3DrRWEEdi9JAGNRj5QhvkjYC2z12NJMtd4iFg8_Bv8U3Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
