如何使用Java在GCP中设置存储服务的代理?

时间:2018-04-23 11:43:20

标签: google-cloud-storage

我想使用JAVA从GCP Bucket下载对象。这是我写的代码示例:

timeStr = datetime.strftime(your_utc_time_object, "%Y-%m-%dT%H:%M:%S.%f") # %f: microseconds, 1/10^6 seconds.
timeStr = timeStr[:-3] # delete the trailing 3 digits, convert to milliseconds
toInsert["@timestamp"] = nowStr + "Z" # add 'Z' at last

当我运行此代码时,我遇到以下异常:

    NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
    builder.trustCertificates(GoogleUtils.getCertificateTrustStore());
    builder.setProxy(new Proxy(Proxy.Type.SOCKS, new 
    InetSocketAddress("myproxy", 1234)));
    final HttpTransport httpTransport = builder.build();

    HttpTransportFactory hf = new HttpTransportFactory(){
        @Override
        public HttpTransport create() {
            return httpTransport;
        }
    };

    ServiceAccountCredentials.fromStream(new FileInputStream("path"));
    Storage storage = StorageOptions.newBuilder()
            .setProjectId("projectId")
            .setCredentials(ServiceAccountCredentials.getApplicationDefault(hf))
            .build()
            .getService();

有没有办法为Storage Service设置代理?

1 个答案:

答案 0 :(得分:0)

根据this question中的说明,Google Cloud Client库不提供内置代理支持。您必须配置系统代理或特定于环境的代理。 例如,如果您正在运行JVM,则可以按照here所述配置代理设置。