Class GrpcExceptionHandlerInterceptor
java.lang.Object
org.springframework.grpc.server.exception.GrpcExceptionHandlerInterceptor
- All Implemented Interfaces:
io.grpc.ServerInterceptor, org.springframework.core.Ordered
@Order(1)
public class GrpcExceptionHandlerInterceptor
extends Object
implements io.grpc.ServerInterceptor, org.springframework.core.Ordered
A gRPC
ServerInterceptor that handles exceptions thrown during the processing
of gRPC calls. It intercepts the call and wraps the ServerCall.Listener with an
GrpcExceptionHandlerInterceptor.ExceptionHandlerListener that catches exceptions in onMessage and
onHalfClose methods, and delegates the exception handling to the provided
GrpcExceptionHandler.
A fallback mechanism is used to return UNKNOWN in case the GrpcExceptionHandler
returns a null.
Ordered just inside Micrometer's ObservationGrpcServerInterceptor (typically
@Order(0)). Closing the exception-handled call then goes through
ObservationGrpcServerCall#close, so mapped status codes appear on
grpc.server metrics instead of falling back to UNKNOWN.
Interceptors that throw from interceptCall (notably authentication) must use an
order > ORDER so those exceptions stay inside this handler. Spring Security's
gRPC orders are defined relative to this constant.
- Author:
- Dave Syer, Andrey Litvitski, Yinghuai Fu
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intOrder used so this interceptor sits just inside Micrometer's gRPC server observation interceptor (@Order(0)) when both are present.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetOrder()<ReqT,RespT>
io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT, RespT> next) Intercepts a gRPC server call to handle exceptions.
-
Field Details
-
ORDER
public static final int ORDEROrder used so this interceptor sits just inside Micrometer's gRPC server observation interceptor (@Order(0)) when both are present. Security interceptors derive their orders from this value.- See Also:
-
-
Constructor Details
-
GrpcExceptionHandlerInterceptor
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
interceptCall
public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT, RespT> call, io.grpc.Metadata headers, io.grpc.ServerCallHandler<ReqT, RespT> next) Intercepts a gRPC server call to handle exceptions.- Specified by:
interceptCallin interfaceio.grpc.ServerInterceptor- Type Parameters:
ReqT- the type of the request messageRespT- the type of the response message- Parameters:
call- the server call objectheaders- the metadata headers for the callnext- the next server call handler in the interceptor chain- Returns:
- a listener for the request messages
-