更新时间:2025-07-08 GMT+08:00
分享

客户端初始化

使用Java SDK工具访问DataArtsFabric SQL,需要用户初始化DataArtsFabric SQL客户端。用户可以使用永久AK/SK或临时AK/SK两种认证方式初始化客户端,示例代码如下:

前提条件

永久AK/SK认证方式样例代码

  • 方法定义
DwsRestClient(String endpoint, String accessKey, String secretKey)
  • 参数说明

    参数名

    是否必填

    描述

    endpoint

    DataArtsFabric SQL提供的服务地址。

    accessKey

    接入键标识

    secretKey

    安全接入键

  • 代码样例
    // 从环境变量读取参数(推荐方式)
    String endpoint = "example.com";
    String accessKey = System.getenv("FABRICLSQL_ACCESS_KEY");
    String secretKey = System.getenv("FABRICLSQL_SECRET_KEY");
    // 验证参数是否为空(可选)
    if (endpoint == null || accessKey == null || secretKey == null) {
        throw new IllegalArgumentException("Missing required environment variables");
    }
    DwsRestClient client = new DwsRestClient(endpoint, accessKey, secretKey);

认证用的AK和SK硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全。

本示例以AK和SK保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量FABRICLSQL_ACCESS_KEY和FABRICLSQL_SECRET_KEY。

临时AK/SK认证方式样例代码

  • 方法定义
DwsRestClient(String endpoint, String accessKey, String secretKey, String securityToken)
  • 参数说明

    参数名

    是否必填

    描述

    endpoint

    DataArtsFabric SQL提供的服务地址。

    accessKey

    临时接入键标识

    secretKey

    临时安全接入键

    securityToken

    临时访问密钥Token

  • 代码样例
    // 从环境变量读取参数(推荐方式)
    String endpoint = "example.com";
    String accessKey = System.getenv("FABRICLSQL_ACCESS_KEY");
    String secretKey = System.getenv("FABRICLSQL_SECRET_KEY")
    String securityToken = System.getenv("FABRICLSQL_SECURITY_TOKEN");
    // 验证参数是否为空(可选)
    if (endpoint == null || accessKey == null || secretKey == null || securityToken == null) {
        throw new IllegalArgumentException("Missing required environment variables");
    }
    DwsRestClient client = new DwsRestClient(endpoint, accessKey, secretKey, securityToken);

相关文档