Package io.grpc
Class ServerInterceptors
- java.lang.Object
- 
- io.grpc.ServerInterceptors
 
- 
 public final class ServerInterceptors extends Object Utility methods for working withServerInterceptors.
- 
- 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static ServerServiceDefinitionintercept(BindableService bindableService, ServerInterceptor... interceptors)static ServerServiceDefinitionintercept(BindableService bindableService, List<? extends ServerInterceptor> interceptors)static ServerServiceDefinitionintercept(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler.static ServerServiceDefinitionintercept(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler.static ServerServiceDefinitioninterceptForward(BindableService bindableService, ServerInterceptor... interceptors)static ServerServiceDefinitioninterceptForward(BindableService bindableService, List<? extends ServerInterceptor> interceptors)static ServerServiceDefinitioninterceptForward(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler.static ServerServiceDefinitioninterceptForward(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler.static ServerServiceDefinitionuseInputStreamMessages(ServerServiceDefinition serviceDef)Create a newServerServiceDefinitionwhoseMethodDescriptorserializes to and from InputStream for all methods.static <ReqT,RespT>
 ServerServiceDefinitionuseMarshalledMessages(ServerServiceDefinition serviceDef, MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller)Create a newServerServiceDefinitionwithMethodDescriptorfor deserializing requests and separateMethodDescriptorfor serializing responses.static <T> ServerServiceDefinitionuseMarshalledMessages(ServerServiceDefinition serviceDef, MethodDescriptor.Marshaller<T> marshaller)Create a newServerServiceDefinitionwhoseMethodDescriptorserializes to and from T for all methods.
 
- 
- 
- 
Method Detail- 
interceptForwardpublic static ServerServiceDefinition interceptForward(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors) Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler. The first interceptor will have itsServerInterceptor.interceptCall(io.grpc.ServerCall<ReqT, RespT>, io.grpc.Metadata, io.grpc.ServerCallHandler<ReqT, RespT>)called first.- Parameters:
- serviceDef- the service definition for which to intercept all its methods.
- interceptors- array of interceptors to apply to the service.
- Returns:
- a wrapped version of serviceDefwith the interceptors applied.
 
 - 
interceptForwardpublic static ServerServiceDefinition interceptForward(BindableService bindableService, ServerInterceptor... interceptors) 
 - 
interceptForwardpublic static ServerServiceDefinition interceptForward(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors) Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler. The first interceptor will have itsServerInterceptor.interceptCall(io.grpc.ServerCall<ReqT, RespT>, io.grpc.Metadata, io.grpc.ServerCallHandler<ReqT, RespT>)called first.- Parameters:
- serviceDef- the service definition for which to intercept all its methods.
- interceptors- list of interceptors to apply to the service.
- Returns:
- a wrapped version of serviceDefwith the interceptors applied.
 
 - 
interceptForwardpublic static ServerServiceDefinition interceptForward(BindableService bindableService, List<? extends ServerInterceptor> interceptors) 
 - 
interceptpublic static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors) Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler. The last interceptor will have itsServerInterceptor.interceptCall(io.grpc.ServerCall<ReqT, RespT>, io.grpc.Metadata, io.grpc.ServerCallHandler<ReqT, RespT>)called first.- Parameters:
- serviceDef- the service definition for which to intercept all its methods.
- interceptors- array of interceptors to apply to the service.
- Returns:
- a wrapped version of serviceDefwith the interceptors applied.
 
 - 
interceptpublic static ServerServiceDefinition intercept(BindableService bindableService, ServerInterceptor... interceptors) 
 - 
interceptpublic static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors) Create a newServerServiceDefinitionwhoseServerCallHandlers will callinterceptorsbefore calling the pre-existingServerCallHandler. The last interceptor will have itsServerInterceptor.interceptCall(io.grpc.ServerCall<ReqT, RespT>, io.grpc.Metadata, io.grpc.ServerCallHandler<ReqT, RespT>)called first.- Parameters:
- serviceDef- the service definition for which to intercept all its methods.
- interceptors- list of interceptors to apply to the service.
- Returns:
- a wrapped version of serviceDefwith the interceptors applied.
 
 - 
interceptpublic static ServerServiceDefinition intercept(BindableService bindableService, List<? extends ServerInterceptor> interceptors) 
 - 
useInputStreamMessages@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1712") public static ServerServiceDefinition useInputStreamMessages(ServerServiceDefinition serviceDef) Create a newServerServiceDefinitionwhoseMethodDescriptorserializes to and from InputStream for all methods. The InputStream is guaranteed return true for markSupported(). TheServerCallHandlercreated will automatically convert back to the original types for request and response before calling the existingServerCallHandler. Calling this method combined with the intercept methods will allow the developer to choose whether to intercept messages of InputStream, or the modeled types of their application.- Parameters:
- serviceDef- the service definition to convert messages to InputStream
- Returns:
- a wrapped version of serviceDefwith the InputStream conversion applied.
 
 - 
useMarshalledMessages@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1712") public static <T> ServerServiceDefinition useMarshalledMessages(ServerServiceDefinition serviceDef, MethodDescriptor.Marshaller<T> marshaller) Create a newServerServiceDefinitionwhoseMethodDescriptorserializes to and from T for all methods. TheServerCallHandlercreated will automatically convert back to the original types for request and response before calling the existingServerCallHandler. Calling this method combined with the intercept methods will allow the developer to choose whether to intercept messages of T, or the modeled types of their application. This can also be chained to allow for interceptors to handle messages as multiple different T types within the chain if the added cost of serialization is not a concern.- Parameters:
- serviceDef- the service definition to convert messages to T
- Returns:
- a wrapped version of serviceDefwith the T conversion applied.
 
 - 
useMarshalledMessages@ExperimentalApi("https://github.com/grpc/grpc-java/issues/9870") public static <ReqT,RespT> ServerServiceDefinition useMarshalledMessages(ServerServiceDefinition serviceDef, MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller) Create a newServerServiceDefinitionwithMethodDescriptorfor deserializing requests and separateMethodDescriptorfor serializing responses. TheServerCallHandlercreated will automatically convert back to the original types for request and response before calling the existingServerCallHandler. Calling this method combined with the intercept methods will allow the developer to choose whether to intercept messages of ReqT/RespT, or the modeled types of their application. This can also be chained to allow for interceptors to handle messages as multiple different ReqT/RespT types within the chain if the added cost of serialization is not a concern.- Type Parameters:
- ReqT- the request payload type
- RespT- the response payload type.
- Parameters:
- serviceDef- the service definition to add request and response marshallers to.
- requestMarshaller- request marshaller
- responseMarshaller- response marshaller
- Returns:
- a wrapped version of serviceDefwith the ReqT and RespT conversion applied.
 
 
- 
 
-