Class InterceptorUtil
java.lang.Object
io.camunda.zeebe.gateway.interceptors.InterceptorUtil
A set of utilities which interceptor authors can use in their interceptors.
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.grpc.Context.Key<QueryApi> Returns an instance ofQueryApiusable in an interceptor.static io.grpc.ContextsetAuthorizedTenants(List<String> authorizedTenants)
-
Method Details
-
getQueryApiKey
Returns an instance ofQueryApiusable in an interceptor. Note that, as per the gRPC documentation, it's perfectly fine to block in a call and/or listener, which may greatly simplify the usage of the API in your code.If you use the API asynchronously, there are a few gotchas to remember:
- if your interceptor is loaded via an external JAR, and it uses directly or indirectly the
Thread.getContextClassLoader()to load classes, you will need to make sure to set the appropriate context class loader in your callbacks, otherwise you may run intoClassNotFoundExceptionerrors - your callback may be executed on a different thread than the initial call, so you will
have to deal with thread safety; using a
or similar may help
invalid reference
io.grpc.internal.SerializingExecutor - since your callback may be executed on a different thread, the
Context.current()maybe different; if you want to use the same original context, you will need to close on it in your callback, or extract what you need from it beforehand and close on that
Example usage:
final Context context = Context.current(); final QueryApi api = InterceptorUtil.getQueryApiKey().get(context); final String processId; try { processId = queryApi.getBpmnProcessIdForProcess(processKey).toCompletableFuture().join(); } catch(final Exception e) { // close the call on error return; } // do something with the processId- Returns:
- the context key associated with the current query API
- if your interceptor is loaded via an external JAR, and it uses directly or indirectly the
-
getAuthorizedTenantsKey
Returns a gRPC contextContext.Keythat can be used to set aList<String>of authorized tenant IDs in an interceptor. Note that, as per the gRPC documentation, it's perfectly fine to block in a call and/or listener, which may greatly simplify the usage of the API in your code.If you use the API asynchronously, there are a few gotchas to remember:
- if your interceptor is loaded via an external JAR, and it uses directly or indirectly the
Thread.getContextClassLoader()to load classes, you will need to make sure to set the appropriate context class loader in your callbacks, otherwise you may run intoClassNotFoundExceptionerrors - your callback may be executed on a different thread than the initial call, so you will
have to deal with thread safety; using a
or similar may help
invalid reference
io.grpc.internal.SerializingExecutor - since your callback may be executed on a different thread, the
Context.current()maybe different; if you want to use the same original context, you will need to close on it in your callback, or extract what you need from it beforehand and close on that
Example usage:
final List<String> authorizedTenantIds = List.of("tenant-1", "tenant-2"); final Context context = Context.current(); context.withValue(InterceptorUtil.getAuthorizedTenantsKey(), authorizedTenantIds);- Returns:
- the context key associated with the current List of authorized tenant IDs
- if your interceptor is loaded via an external JAR, and it uses directly or indirectly the
-
setAuthorizedTenants
A helper method to set aList<String>of authorized tenant IDs on theAUTHORIZED_TENANTS_KEYgRPC Context key.- Parameters:
authorizedTenants- - a List of Strings that specify the authorized tenants for the gRPC request- Returns:
- the current
Context
-