var proxy = new java.net.Proxy(
    java.net.Proxy.Type.HTTP,
    new java.net.InetSocketAddress("proxy.example.net", 8080));

com.google.auth.http.HttpTransportFactory factory = () ->
    new com.google.api.client.http.javanet.NetHttpTransport.Builder()
        .setProxy(proxy)
        .build();

var credentials =
    com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(factory);

var transportOptions =
    com.google.cloud.http.HttpTransportOptions.newBuilder()
        .setHttpTransportFactory(factory)
        .build();

var storage = com.google.cloud.storage.StorageOptions.http()
    .setCredentials(credentials)
    .setTransportOptions(transportOptions)
    .build()
    .getService();

The application's normal Application Default Credentials setup remains in place. Where a public proxy is allowed for the Storage and token endpoints, the HTTP proxy list provides candidates for the InetSocketAddress host and port. Supply the factory while loading those credentials, before their HTTP token requests need it.

Two inputs use the factory: getApplicationDefault(factory) covers the credential implementation's HTTP work; HttpTransportOptions covers the Storage HTTP service. Neither assignment automatically configures the other.

StorageOptions.http has been available since Java Storage 2.14.0. Keep the library types straight: HttpTransportOptions belongs to Google Cloud Core and NetHttpTransport to Google's HTTP client library.

A gRPC-specific Storage client has another transport. Choose the HTTP builder for this factory customization rather than attaching HTTP-only options to a gRPC channel.

متعلقہ مضامین