Package io.grpc
Class ServerInterceptors
- java.lang.Object
-
- io.grpc.ServerInterceptors
-
public final class ServerInterceptors extends Object
Utility methods for working withServerInterceptor
s.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ServerServiceDefinition
intercept(BindableService bindableService, ServerInterceptor... interceptors)
static ServerServiceDefinition
intercept(BindableService bindableService, List<? extends ServerInterceptor> interceptors)
static ServerServiceDefinition
intercept(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before calling the pre-existingServerCallHandler
.static ServerServiceDefinition
intercept(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before calling the pre-existingServerCallHandler
.static ServerServiceDefinition
interceptForward(BindableService bindableService, ServerInterceptor... interceptors)
static ServerServiceDefinition
interceptForward(BindableService bindableService, List<? extends ServerInterceptor> interceptors)
static ServerServiceDefinition
interceptForward(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before calling the pre-existingServerCallHandler
.static ServerServiceDefinition
interceptForward(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before calling the pre-existingServerCallHandler
.static ServerServiceDefinition
useInputStreamMessages(ServerServiceDefinition serviceDef)
Create a newServerServiceDefinition
whoseMethodDescriptor
serializes to and from InputStream for all methods.static <ReqT,RespT>
ServerServiceDefinitionuseMarshalledMessages(ServerServiceDefinition serviceDef, MethodDescriptor.Marshaller<ReqT> requestMarshaller, MethodDescriptor.Marshaller<RespT> responseMarshaller)
Create a newServerServiceDefinition
withMethodDescriptor
for deserializing requests and separateMethodDescriptor
for serializing responses.static <T> ServerServiceDefinition
useMarshalledMessages(ServerServiceDefinition serviceDef, MethodDescriptor.Marshaller<T> marshaller)
Create a newServerServiceDefinition
whoseMethodDescriptor
serializes to and from T for all methods.
-
-
-
Method Detail
-
interceptForward
public static ServerServiceDefinition interceptForward(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before 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
serviceDef
with the interceptors applied.
-
interceptForward
public static ServerServiceDefinition interceptForward(BindableService bindableService, ServerInterceptor... interceptors)
-
interceptForward
public static ServerServiceDefinition interceptForward(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before 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
serviceDef
with the interceptors applied.
-
interceptForward
public static ServerServiceDefinition interceptForward(BindableService bindableService, List<? extends ServerInterceptor> interceptors)
-
intercept
public static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, ServerInterceptor... interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before 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
serviceDef
with the interceptors applied.
-
intercept
public static ServerServiceDefinition intercept(BindableService bindableService, ServerInterceptor... interceptors)
-
intercept
public static ServerServiceDefinition intercept(ServerServiceDefinition serviceDef, List<? extends ServerInterceptor> interceptors)
Create a newServerServiceDefinition
whoseServerCallHandler
s will callinterceptors
before 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
serviceDef
with the interceptors applied.
-
intercept
public 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 newServerServiceDefinition
whoseMethodDescriptor
serializes to and from InputStream for all methods. The InputStream is guaranteed return true for markSupported(). TheServerCallHandler
created 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
serviceDef
with 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 newServerServiceDefinition
whoseMethodDescriptor
serializes to and from T for all methods. TheServerCallHandler
created 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
serviceDef
with 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 newServerServiceDefinition
withMethodDescriptor
for deserializing requests and separateMethodDescriptor
for serializing responses. TheServerCallHandler
created 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 typeRespT
- the response payload type.- Parameters:
serviceDef
- the service definition to add request and response marshallers to.requestMarshaller
- request marshallerresponseMarshaller
- response marshaller- Returns:
- a wrapped version of
serviceDef
with the ReqT and RespT conversion applied.
-
-