All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.zeebe.gateway.interceptors.impl.ContextInjectingInterceptor Maven / Gradle / Ivy

There is a newer version: 8.6.0-alpha5
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Camunda License 1.0. You may not use this file
 * except in compliance with the Camunda License 1.0.
 */
package io.camunda.zeebe.gateway.interceptors.impl;

import io.camunda.zeebe.gateway.interceptors.InterceptorUtil;
import io.camunda.zeebe.gateway.query.QueryApi;
import io.grpc.Context;
import io.grpc.Metadata;
import io.grpc.ServerCall;
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import org.agrona.LangUtil;

/**
 * An interceptor implementation which injects common context for further interceptors. It's
 * expected to be one of the top level interceptors. This is for context objects which are the same
 * and shared by all interceptors, as opposed to the {@link DecoratedInterceptor} which injects
 * context information specific to the wrapped interceptor.
 *
 * 

This interceptor will inject the following in every call's context: * *

    *
  • {@link InterceptorUtil#getQueryApi()} => returns a query API usable by the interceptors *
*/ public final class ContextInjectingInterceptor implements ServerInterceptor { private final QueryApi queryApi; public ContextInjectingInterceptor(final QueryApi queryApi) { this.queryApi = queryApi; } @Override public Listener interceptCall( final ServerCall call, final Metadata headers, final ServerCallHandler next) { try { return Context.current() .withValue(InterceptorUtil.getQueryApiKey(), queryApi) .call(() -> next.startCall(call, headers)); } catch (final Exception e) { LangUtil.rethrowUnchecked(e); return null; // unreachable as the exception is rethrown above } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy