com.scalar.dl.client.rpc.RpcUtil 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.
package com.scalar.dl.client.rpc;
import com.scalar.dl.client.exception.ClientException;
import com.scalar.dl.ledger.service.StatusCode;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import javax.net.ssl.SSLException;
public class RpcUtil {
public static void configureTls(
NettyChannelBuilder builder, boolean tlsEnabled, Optional tlsCaRootCert) {
if (tlsEnabled) {
if (tlsCaRootCert.isPresent()) {
// With a custom root CA certificate
try {
builder.sslContext(
GrpcSslContexts.forClient()
.trustManager(
new ByteArrayInputStream(
tlsCaRootCert.get().getBytes(StandardCharsets.UTF_8)))
.build());
} catch (SSLException e) {
throw new ClientException("couldn't configure SSL.", e, StatusCode.RUNTIME_ERROR);
}
} else {
// Use a certificate from the trusted CAs if it's not given
}
} else {
builder.usePlaintext();
}
}
public static void configureHeader(
NettyChannelBuilder builder, Optional authorizationCredential) {
authorizationCredential.ifPresent(
credential -> {
// add an authorization header
builder.intercept(new AuthorizationInterceptor(credential));
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy