Package io.grpc
Interface ServerInterceptor
@ThreadSafe
public interface ServerInterceptor
Interface for intercepting incoming calls before they are dispatched by
ServerCallHandler.
Implementers use this mechanism to add cross-cutting behavior to server-side calls. Common example of such behavior include:
- Enforcing valid authentication credentials
- Logging and monitoring call behavior
- Delegating calls to other servers
The interceptor may be called for multiple calls by one or more threads
without completing the previous ones first. Refer to the
ServerCall.Listener docs for more details regarding thread
safety of the returned listener.
-
Method Summary
Modifier and TypeMethodDescription<ReqT,RespT>
ServerCall.Listener<ReqT>interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next)
-
Method Details
-
interceptCall
<ReqT,RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) InterceptServerCalldispatch by thenextServerCallHandler. General semantics ofServerCallHandler.startCall(io.grpc.ServerCall<RequestT, ResponseT>, io.grpc.Metadata)apply and the returnedServerCall.Listenermust not benull.If the implementation throws an exception,
callwill be closed with an error. Implementations must not throw an exception if they started processing that may usecallon another thread.- Parameters:
call- object to receive response messagesheaders- which can contain extra call metadata fromClientCall.start(io.grpc.ClientCall.Listener<RespT>, io.grpc.Metadata), e.g. authentication credentials.next- next processor in the interceptor chain- Returns:
- listener for processing incoming messages for
call, nevernull.
-