com.scalar.dl.client.rpc.AuthorizationInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardl-java-client-sdk Show documentation
Show all versions of scalardl-java-client-sdk Show documentation
A client-side Java library to interact with Scalar DL network.
/*
* This file is part of the Scalar DL client SDK.
* Copyright (c) 2019 Scalar, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
* You can be released from the requirements of the license by purchasing
* a commercial license. For more information, please contact Scalar, Inc.
*/
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