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

com.scalar.dl.client.rpc.AuthorizationInterceptor Maven / Gradle / Ivy

The newest version!
package com.scalar.dl.client.rpc;

import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
import io.grpc.ClientInterceptor;
import io.grpc.ForwardingClientCall;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;

public class AuthorizationInterceptor implements ClientInterceptor {
  private static final String KEY = "authorization";
  private final String token;

  public AuthorizationInterceptor(String token) {
    this.token = token;
  }

  @Override
  public  ClientCall interceptCall(
      MethodDescriptor methodDescriptor, CallOptions callOptions, Channel channel) {
    return new ForwardingClientCall.SimpleForwardingClientCall(
        channel.newCall(methodDescriptor, callOptions)) {
      @Override
      public void start(Listener responseListener, Metadata headers) {
        headers.put(Metadata.Key.of(KEY, Metadata.ASCII_STRING_MARSHALLER), token);
        super.start(responseListener, headers);
      }
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy