HTTP client implementation using Java's URLConnection for the AWS SDK for Java 2.0
This document covers HTTP proxy configuration for the UrlConnectionHttpClient, including authentication, host exclusion, and system property integration.
public final class ProxyConfiguration implements ToCopyableBuilder<ProxyConfiguration.Builder, ProxyConfiguration> {
// Static factory
public static Builder builder();
// Configuration accessors
public String host();
public int port();
public String scheme();
public String username();
public String password();
public Set<String> nonProxyHosts();
// Builder conversion
public Builder toBuilder();
}import software.amazon.awssdk.http.urlconnection.ProxyConfiguration;
import java.net.URI;
ProxyConfiguration proxy = ProxyConfiguration.builder()
.endpoint(URI.create("http://proxy.example.com:8080"))
.build();
SdkHttpClient client = UrlConnectionHttpClient.builder()
.proxyConfiguration(proxy)
.build();ProxyConfiguration proxy = ProxyConfiguration.builder()
.endpoint(URI.create("http://proxy.example.com:8080"))
.username("proxyuser")
.password("proxypassword")
.build();ProxyConfiguration proxy = ProxyConfiguration.builder()
.endpoint(URI.create("https://secure-proxy.example.com:8443"))
.username("user")
.password("pass")
.build();import java.util.Set;
ProxyConfiguration proxy = ProxyConfiguration.builder()
.endpoint(URI.create("http://proxy.example.com:8080"))
.nonProxyHosts(Set.of("localhost", "*.internal.com", "192.168.*"))
.build();
// Or add hosts individually
ProxyConfiguration proxy2 = ProxyConfiguration.builder()
.endpoint(URI.create("http://proxy.example.com:8080"))
.addNonProxyHost("localhost")
.addNonProxyHost("*.internal.com")
.addNonProxyHost("10.0.0.*")
.build();// Use system properties (http.proxyHost, http.proxyPort, etc.)
ProxyConfiguration proxy = ProxyConfiguration.builder()
.useSystemPropertyValues(true)
.build();
// Use environment variables (HTTP_PROXY, NO_PROXY, etc.)
ProxyConfiguration proxy2 = ProxyConfiguration.builder()
.useEnvironmentVariablesValues(true)
.build();
// Disable both system properties and environment variables
ProxyConfiguration proxy3 = ProxyConfiguration.builder()
.endpoint(URI.create("http://proxy.example.com:8080"))
.useSystemPropertyValues(false)
.useEnvironmentVariablesValues(false)
.build();public interface Builder extends CopyableBuilder<Builder, ProxyConfiguration> {
// Basic configuration
Builder endpoint(URI endpoint);
Builder username(String username);
Builder password(String password);
Builder scheme(String scheme);
// Host exclusion
Builder nonProxyHosts(Set<String> nonProxyHosts);
Builder addNonProxyHost(String nonProxyHost);
// System integration
Builder useSystemPropertyValues(Boolean useSystemPropertyValues);
Builder useEnvironmentVariablesValues(Boolean useEnvironmentVariablesValues);
// Build
ProxyConfiguration build();
}// Complete proxy configuration
ProxyConfiguration proxy = ProxyConfiguration.builder()
.endpoint(URI.create("http://corporate-proxy.example.com:3128"))
.username("domain\\user") // Windows domain authentication
.password("password123")
.nonProxyHosts(Set.of("localhost", "127.0.0.1", "*.internal.corp"))
.useSystemPropertyValues(false) // Don't override with system properties
.build();
// Consumer-style configuration with HTTP client
SdkHttpClient client = UrlConnectionHttpClient.builder()
.proxyConfiguration(proxy -> proxy
.endpoint(URI.create("http://proxy.example.com:8080"))
.username("user")
.password("pass")
.addNonProxyHost("localhost")
.addNonProxyHost("*.test.com"))
.build();When useSystemPropertyValues(true) is set (default), the following system properties are used:
http.proxyHost - Proxy hostnamehttp.proxyPort - Proxy port (default 80)http.proxyUser - Proxy usernamehttp.proxyPassword - Proxy passwordhttp.nonProxyHosts - Pipe-separated list of hosts to bypass proxy// System properties will be automatically used
System.setProperty("http.proxyHost", "proxy.company.com");
System.setProperty("http.proxyPort", "8080");
System.setProperty("http.proxyUser", "username");
System.setProperty("http.proxyPassword", "password");
System.setProperty("http.nonProxyHosts", "localhost|*.internal.com");
ProxyConfiguration proxy = ProxyConfiguration.builder()
.useSystemPropertyValues(true)
.build();When useEnvironmentVariablesValues(true) is set (default), the following environment variables are used:
HTTP_PROXY or http_proxy - Proxy URL (e.g., http://proxy.example.com:8080)HTTPS_PROXY or https_proxy - HTTPS proxy URLNO_PROXY or no_proxy - Comma-separated list of hosts to bypass proxyexport HTTP_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,*.internal.com,192.168.*ProxyConfiguration proxy = ProxyConfiguration.builder()
.useEnvironmentVariablesValues(true)
.build();When both system properties and environment variables are enabled:
// Typical corporate proxy setup
ProxyConfiguration corpProxy = ProxyConfiguration.builder()
.endpoint(URI.create("http://proxy.corporate.com:8080"))
.username("DOMAIN\\username")
.password("password")
.nonProxyHosts(Set.of(
"localhost",
"127.0.0.1",
"*.corporate.com",
"*.internal",
"10.*",
"192.168.*"
))
.build();
SdkHttpClient client = UrlConnectionHttpClient.builder()
.proxyConfiguration(corpProxy)
.connectionTimeout(Duration.ofSeconds(30))
.build();// Development with system property fallback
ProxyConfiguration devProxy = ProxyConfiguration.builder()
.useSystemPropertyValues(true)
.useEnvironmentVariablesValues(true)
.addNonProxyHost("localhost")
.addNonProxyHost("*.test")
.build();// Explicitly disable proxy
ProxyConfiguration noProxy = ProxyConfiguration.builder()
.useSystemPropertyValues(false)
.useEnvironmentVariablesValues(false)
.build();// Main proxy configuration class
public final class ProxyConfiguration implements ToCopyableBuilder<ProxyConfiguration.Builder, ProxyConfiguration> {
public String host();
public int port();
public String scheme();
public String username();
public String password();
public Set<String> nonProxyHosts();
public String resolveScheme(); // Resolves scheme from endpoint if available
public Builder toBuilder();
public static Builder builder();
}
// Builder interface
public interface Builder extends CopyableBuilder<Builder, ProxyConfiguration> {
// Fluent builder methods
Builder endpoint(URI endpoint);
Builder username(String username);
Builder password(String password);
Builder nonProxyHosts(Set<String> nonProxyHosts);
Builder addNonProxyHost(String nonProxyHost);
Builder useSystemPropertyValues(Boolean useSystemPropertyValues);
Builder useEnvironmentVariablesValues(Boolean useEnvironmentVariablesValues);
Builder scheme(String scheme);
// JavaBean setter methods (for framework integration)
void setEndpoint(URI endpoint);
void setUsername(String username);
void setPassword(String password);
void setNonProxyHosts(Set<String> nonProxyHosts);
void setUseSystemPropertyValues(Boolean useSystemPropertyValues);
void setUseEnvironmentVariablesValues(Boolean useEnvironmentVariablesValues);
void setScheme(String scheme);
// Build method
ProxyConfiguration build();
}Install with Tessl CLI
npx tessl i tessl/maven-software-amazon-awssdk--url-connection-client