Core foundational library for AWS SDK for Java 1.x providing authentication, HTTP transport, regions, protocols, and shared utilities for all AWS service clients
—
The AWS Java SDK Core provides comprehensive HTTP client management with support for connection pooling, SSL/TLS configuration, proxy settings, timeouts, and request/response handling.
// Main HTTP client for AWS requests
class AmazonHttpClient {
public AmazonHttpClient(ClientConfiguration config);
public AmazonHttpClient(ClientConfiguration config,
RequestMetricCollector requestMetricCollector);
public <T> Response<T> requestExecutionBuilder()
.request(Request<?> request)
.originalRequest(AmazonWebServiceRequest originalRequest)
.executionContext(ExecutionContext executionContext)
.errorResponseHandler(HttpResponseHandler<? extends SdkBaseException> errorResponseHandler)
.execute(HttpResponseHandler<T> responseHandler);
}
// HTTP response representation
class HttpResponse {
public HttpResponse(Request<?> request, HttpRequestBase httpRequest);
public InputStream getContent();
public Map<String, String> getHeaders();
public int getStatusCode();
public String getStatusText();
public HttpRequestBase getHttpRequest();
public Request<?> getOriginalRequest();
}
// HTTP response handler interface
interface HttpResponseHandler<T> {
T handle(HttpResponse response) throws Exception;
boolean needsConnectionLeftOpen();
}
// HTTP method enumeration
enum HttpMethodName {
GET, HEAD, POST, PUT, DELETE, OPTIONS, PATCH;
public String toString();
}
// SDK HTTP metadata
class SdkHttpMetadata {
public int getHttpStatusCode();
public Map<String, String> getHttpHeaders();
public long getContentLength();
public String getContentType();
}
// Execution context for requests
class ExecutionContext {
public List<RequestHandler2> getRequestHandler2s();
public RequestMetricCollector getAwsRequestMetrics();
public AWSCredentials getCredentials();
public AWSCredentialsProvider getCredentialsProvider();
public ExecutionContext withCredentials(AWSCredentials credentials);
public ExecutionContext withCredentialsProvider(AWSCredentialsProvider credentialsProvider);
}// JSON response handler
class JsonResponseHandler<T> implements HttpResponseHandler<T> {
public JsonResponseHandler(Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller);
public T handle(HttpResponse response) throws Exception;
public boolean needsConnectionLeftOpen();
}
// JSON error response handler
class JsonErrorResponseHandler implements HttpResponseHandler<SdkBaseException> {
public JsonErrorResponseHandler(
List<JsonErrorUnmarshallerV2> errorUnmarshallers);
public SdkBaseException handle(HttpResponse response) throws Exception;
public boolean needsConnectionLeftOpen();
}
// StAX XML response handler
class StaxResponseHandler<T> implements HttpResponseHandler<T> {
public StaxResponseHandler(Unmarshaller<T, StaxUnmarshallerContext> responseUnmarshaller);
public T handle(HttpResponse response) throws Exception;
public boolean needsConnectionLeftOpen();
}
// Default error response handler
class DefaultErrorResponseHandler implements HttpResponseHandler<SdkBaseException> {
public DefaultErrorResponseHandler(
List<Unmarshaller<SdkBaseException, Node>> exceptionUnmarshallers);
public SdkBaseException handle(HttpResponse response) throws Exception;
public boolean needsConnectionLeftOpen();
}
// RPC v2 CBOR response handler
class RpcV2CborResponseHandler<T> implements HttpResponseHandler<T> {
public RpcV2CborResponseHandler(
Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller);
public T handle(HttpResponse response) throws Exception;
public boolean needsConnectionLeftOpen();
}
// RPC v2 CBOR error response handler
class RpcV2CborErrorResponseHandler implements HttpResponseHandler<SdkBaseException> {
public RpcV2CborErrorResponseHandler(
List<JsonErrorUnmarshallerV2> errorUnmarshallers);
public SdkBaseException handle(HttpResponse response) throws Exception;
public boolean needsConnectionLeftOpen();
}// HTTP client and proxy configuration
class ClientConfiguration {
// Connection settings
public ClientConfiguration withMaxConnections(int maxConnections);
public ClientConfiguration withConnectionTimeout(int connectionTimeout);
public ClientConfiguration withSocketTimeout(int socketTimeout);
public ClientConfiguration withConnectionTTL(long connectionTTL);
public ClientConfiguration withConnectionMaxIdleMillis(long connectionMaxIdleMillis);
public ClientConfiguration withValidateAfterInactivityMillis(int validateAfterInactivityMillis);
// Retry settings
public ClientConfiguration withRetryPolicy(RetryPolicy retryPolicy);
public ClientConfiguration withMaxErrorRetry(int maxErrorRetry);
public ClientConfiguration withThrottledRetries(boolean throttledRetries);
// Proxy settings
public ClientConfiguration withProxyHost(String proxyHost);
public ClientConfiguration withProxyPort(int proxyPort);
public ClientConfiguration withProxyUsername(String proxyUsername);
public ClientConfiguration withProxyPassword(String proxyPassword);
public ClientConfiguration withProxyDomain(String proxyDomain);
public ClientConfiguration withProxyWorkstation(String proxyWorkstation);
public ClientConfiguration withNonProxyHosts(String nonProxyHosts);
public ClientConfiguration withProxyAuthenticationMethods(Set<ProxyAuthenticationMethod> methods);
// SSL/TLS settings
public ClientConfiguration withProtocol(Protocol protocol);
public ClientConfiguration withSecureRandom(SecureRandom secureRandom);
public ClientConfiguration withTrustAllCertificates(boolean trustAllCertificates);
// Advanced settings
public ClientConfiguration withUserAgent(String userAgent);
public ClientConfiguration withUserAgentPrefix(String userAgentPrefix);
public ClientConfiguration withUserAgentSuffix(String userAgentSuffix);
public ClientConfiguration withRequestTimeout(int requestTimeout);
public ClientConfiguration withClientExecutionTimeout(int clientExecutionTimeout);
public ClientConfiguration withTcpKeepAlive(boolean tcpKeepAlive);
public ClientConfiguration withDnsResolver(DnsResolver dnsResolver);
public ClientConfiguration withCacheResponseMetadata(boolean cacheResponseMetadata);
public ClientConfiguration withResponseMetadataCacheSize(int responseMetadataCacheSize);
public ClientConfiguration withHeader(String name, String value);
// Getters
public int getMaxConnections();
public int getConnectionTimeout();
public int getSocketTimeout();
public long getConnectionTTL();
public long getConnectionMaxIdleMillis();
public int getValidateAfterInactivityMillis();
public RetryPolicy getRetryPolicy();
public int getMaxErrorRetry();
public String getProxyHost();
public int getProxyPort();
public String getProxyUsername();
public String getProxyPassword();
public String getProxyDomain();
public String getProxyWorkstation();
public String getNonProxyHosts();
public Protocol getProtocol();
public SecureRandom getSecureRandom();
public boolean trustAllCertificates();
public String getUserAgent();
public String getUserAgentPrefix();
public String getUserAgentSuffix();
public int getRequestTimeout();
public int getClientExecutionTimeout();
public boolean useTcpKeepAlive();
public DnsResolver getDnsResolver();
public boolean getCacheResponseMetadata();
public int getResponseMetadataCacheSize();
public Map<String, String> getHeaders();
}
// Factory for client configurations
class ClientConfigurationFactory {
public ClientConfiguration getConfig();
}
// Pre-configured client settings
class PredefinedClientConfigurations {
public static ClientConfiguration defaultConfig();
public static ClientConfiguration standard();
}
// Per-request configuration
class RequestConfig {
public static RequestConfig NO_OP;
public RequestConfig withRequestTimeout(int requestTimeout);
public RequestConfig withClientExecutionTimeout(int clientExecutionTimeout);
public RequestConfig withProgressListener(ProgressListener progressListener);
public RequestConfig withRequestMetricCollector(RequestMetricCollector requestMetricCollector);
public RequestConfig withRequestClientOptions(RequestClientOptions requestClientOptions);
public RequestConfig withCredentialsProvider(AWSCredentialsProvider credentialsProvider);
public int getRequestTimeout();
public int getClientExecutionTimeout();
public ProgressListener getProgressListener();
public RequestMetricCollector getRequestMetricCollector();
public RequestClientOptions getRequestClientOptions();
public AWSCredentialsProvider getCredentialsProvider();
}
// Request-specific options
class RequestClientOptions {
public RequestClientOptions withReadLimit(int readLimit);
public RequestClientOptions withSkipAppendUriPath(boolean skipAppendUriPath);
public int getReadLimit();
public boolean isSkipAppendUriPath();
}// Service protocols
enum Protocol {
HTTP("http", 80, false),
HTTPS("https", 443, true);
public String toString();
public int getDefaultPort();
public boolean isSecure();
}
// Proxy authentication methods
enum ProxyAuthenticationMethod {
BASIC("Basic"),
DIGEST("Digest"),
KERBEROS("Kerberos"),
NTLM("NTLM"),
SPNEGO("SPNEGO");
public String toString();
}// Factory for Apache HTTP clients
class ApacheHttpClientFactory {
public static ConnectionManagerAwareHttpClient create(ClientConfiguration config);
public static ConnectionManagerAwareHttpClient create(ClientConfiguration config,
RequestMetricCollector requestMetricCollector);
}
// Factory for connection managers
class ApacheConnectionManagerFactory {
public static HttpClientConnectionManager create(ClientConfiguration config,
RequestMetricCollector requestMetricCollector);
}
// Connection manager aware HTTP client
interface ConnectionManagerAwareHttpClient extends HttpClient {
HttpClientConnectionManager getHttpClientConnectionManager();
}
// SDK HTTP client wrapper
class SdkHttpClient implements ConnectionManagerAwareHttpClient {
public SdkHttpClient(HttpClient httpClient, HttpClientConnectionManager connectionManager);
public HttpResponse execute(HttpUriRequest request) throws IOException;
public HttpClientConnectionManager getHttpClientConnectionManager();
}
// Factory for Apache HTTP requests
class ApacheHttpRequestFactory implements HttpRequestFactory {
public HttpRequestBase createHttpRequest(String uri, HttpMethodName httpMethod);
}
// HTTP GET with request body support
class HttpGetWithBody extends HttpEntityEnclosingRequestBase {
public HttpGetWithBody(String uri);
public HttpGetWithBody(URI uri);
public String getMethod();
}
// Proxy route planner
class SdkProxyRoutePlanner extends DefaultProxyRoutePlanner {
public SdkProxyRoutePlanner(String proxyHost, int proxyPort, Protocol protocol,
String nonProxyHosts);
public HttpRoute determineRoute(HttpHost host, HttpRequest request,
HttpContext context) throws HttpException;
}
// Apache HTTP client utilities
class ApacheUtils {
public static boolean isRequestSuccessful(HttpResponse response);
public static HttpEntity newStringEntity(String s);
public static HttpEntity newByteArrayEntity(byte[] content);
public static HttpEntity newInputStreamEntity(InputStream content, long contentLength);
}// Factory for connection managers
interface ClientConnectionManagerFactory {
HttpClientConnectionManager create(ClientConfiguration config);
}
// Generic connection manager factory
interface ConnectionManagerFactory<T> {
T create(ClientConfiguration config);
}
// Keep-alive strategy
class SdkConnectionKeepAliveStrategy implements ConnectionKeepAliveStrategy {
public long getKeepAliveDuration(HttpResponse response, HttpContext context);
}
// Plain socket factory
class SdkPlainSocketFactory extends PlainConnectionSocketFactory {
public Socket createSocket(HttpContext context) throws IOException;
public Socket connectSocket(int connectTimeout, Socket socket, HttpHost host,
InetSocketAddress remoteAddress, InetSocketAddress localAddress,
HttpContext context) throws IOException;
}// TLS socket factory
class SdkTLSSocketFactory extends SSLConnectionSocketFactory {
public SdkTLSSocketFactory(SSLContext sslContext, HostnameVerifier hostnameVerifier);
public Socket createLayeredSocket(Socket socket, String target, int port,
HttpContext context) throws IOException;
public Socket connectSocket(int connectTimeout, Socket socket, HttpHost host,
InetSocketAddress remoteAddress, InetSocketAddress localAddress,
HttpContext context) throws IOException;
}
// TLS key managers provider interface
interface TlsKeyManagersProvider {
KeyManager[] getKeyManagers();
}
// No-operation TLS key managers provider
class NoneTlsKeyManagersProvider implements TlsKeyManagersProvider {
public KeyManager[] getKeyManagers();
}
// Master secret validators
class MasterSecretValidators {
public static final MasterSecretValidator DENY_ALL;
public static final MasterSecretValidator ALLOW_ALL;
}
// SSL session clearing predicate
interface ShouldClearSslSessionPredicate {
boolean shouldClear();
}
// Privileged master secret validator
class PrivilegedMasterSecretValidator implements MasterSecretValidator {
public boolean isMasterSecretValid(Object masterSecret);
}// HTTP client settings
class HttpClientSettings {
public int getMaxConnections();
public int getConnectionTimeout();
public int getSocketTimeout();
public long getConnectionTTL();
public long getConnectionMaxIdleMillis();
public int getValidateAfterInactivityMillis();
public boolean useTcpKeepAlive();
public String getProxyHost();
public int getProxyPort();
public String getProxyUsername();
public String getProxyPassword();
public String getNonProxyHosts();
public Protocol getProtocol();
public SecureRandom getSecureRandom();
public TlsKeyManagersProvider getTlsKeyManagersProvider();
public boolean trustAllCertificates();
}
// Factory for HTTP requests
interface HttpRequestFactory {
HttpRequestBase createHttpRequest(String uri, HttpMethodName httpMethod);
}
// Repeatable input stream request entity
class RepeatableInputStreamRequestEntity extends AbstractHttpEntity
implements Repeatable {
public RepeatableInputStreamRequestEntity(InputStream content, long contentLength);
public boolean isRepeatable();
public long getContentLength();
public InputStream getContent() throws IOException;
public void writeTo(OutputStream outstream) throws IOException;
}
// Delegating DNS resolver
class DelegatingDnsResolver implements DnsResolver {
public DelegatingDnsResolver(DnsResolver delegate);
public InetAddress[] resolve(String host) throws UnknownHostException;
}// Timer for client execution
class ClientExecutionTimer {
public ClientExecutionTimer();
public void startTimer(ClientExecutionAbortTask clientExecutionAbortTask);
public boolean hasTimeoutExpired();
public boolean isEnabled();
public void abortTimer();
}
// Task for aborting client execution
class ClientExecutionAbortTask extends TimerTask {
public ClientExecutionAbortTask(AmazonHttpClient client, HttpRequestBase httpRequest);
public void run();
public boolean hasClientExecutionAborted();
public boolean hasTimeoutExpired();
public void setCurrentHttpRequest(HttpRequestBase currentHttpRequest);
}
// Client execution timeout exception
class ClientExecutionTimeoutException extends SdkClientException {
public ClientExecutionTimeoutException(String message);
}
// Timer for HTTP requests
class HttpRequestTimer {
public HttpRequestTimer();
public void startTimer(HttpRequestAbortTask httpRequestAbortTask);
public boolean hasTimeoutExpired();
public boolean isEnabled();
public void abortTimer();
}
// Task for aborting HTTP requests
class HttpRequestAbortTask extends TimerTask {
public HttpRequestAbortTask(HttpRequestBase httpRequest);
public void run();
public boolean hasRequestAborted();
public boolean hasTimeoutExpired();
}
// Builder for timeout thread pools
class TimeoutThreadPoolBuilder {
public TimeoutThreadPoolBuilder threadNamePrefix(String threadNamePrefix);
public ScheduledThreadPoolExecutor build();
}import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.retry.PredefinedRetryPolicies;
// Basic client configuration
ClientConfiguration config = new ClientConfiguration()
.withMaxConnections(100)
.withConnectionTimeout(5000) // 5 seconds
.withSocketTimeout(30000) // 30 seconds
.withRetryPolicy(PredefinedRetryPolicies.DEFAULT)
.withProtocol(Protocol.HTTPS)
.withTcpKeepAlive(true);
// Advanced configuration
ClientConfiguration advancedConfig = new ClientConfiguration()
.withMaxConnections(200)
.withConnectionTimeout(10000)
.withSocketTimeout(60000)
.withConnectionTTL(300000) // 5 minutes
.withConnectionMaxIdleMillis(60000) // 1 minute
.withRequestTimeout(120000) // 2 minutes
.withClientExecutionTimeout(300000) // 5 minutes
.withRetryPolicy(PredefinedRetryPolicies.DEFAULT_MAX_ERROR_RETRY);import com.amazonaws.ClientConfiguration;
import com.amazonaws.ProxyAuthenticationMethod;
import java.util.*;
// Basic proxy configuration
ClientConfiguration proxyConfig = new ClientConfiguration()
.withProxyHost("proxy.company.com")
.withProxyPort(8080);
// Authenticated proxy configuration
ClientConfiguration authenticatedProxyConfig = new ClientConfiguration()
.withProxyHost("proxy.company.com")
.withProxyPort(8080)
.withProxyUsername("username")
.withProxyPassword("password");
// Advanced proxy configuration
Set<ProxyAuthenticationMethod> authMethods = new HashSet<>();
authMethods.add(ProxyAuthenticationMethod.BASIC);
authMethods.add(ProxyAuthenticationMethod.DIGEST);
ClientConfiguration advancedProxyConfig = new ClientConfiguration()
.withProxyHost("proxy.company.com")
.withProxyPort(8080)
.withProxyUsername("username")
.withProxyPassword("password")
.withProxyDomain("DOMAIN")
.withProxyWorkstation("WORKSTATION")
.withNonProxyHosts("localhost|127.0.0.1|*.company.com")
.withProxyAuthenticationMethods(authMethods);import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import java.security.SecureRandom;
// Basic HTTPS configuration
ClientConfiguration httpsConfig = new ClientConfiguration()
.withProtocol(Protocol.HTTPS);
// Custom SSL configuration
SecureRandom secureRandom = new SecureRandom();
ClientConfiguration customSslConfig = new ClientConfiguration()
.withProtocol(Protocol.HTTPS)
.withSecureRandom(secureRandom);
// Trust all certificates (NOT recommended for production)
ClientConfiguration trustAllConfig = new ClientConfiguration()
.withProtocol(Protocol.HTTPS)
.withTrustAllCertificates(true);import com.amazonaws.ClientConfiguration;
import com.amazonaws.DnsResolver;
import java.net.*;
import java.util.*;
// Custom DNS resolver implementation
public class CustomDnsResolver implements DnsResolver {
@Override
public InetAddress[] resolve(String host) throws UnknownHostException {
// Custom DNS resolution logic
if ("my-custom-service.com".equals(host)) {
return new InetAddress[]{InetAddress.getByName("192.168.1.100")};
}
return InetAddress.getAllByName(host);
}
}
// Use custom DNS resolver
ClientConfiguration config = new ClientConfiguration()
.withDnsResolver(new CustomDnsResolver());import com.amazonaws.RequestConfig;
import com.amazonaws.event.ProgressListener;
import com.amazonaws.metrics.RequestMetricCollector;
// Request-specific timeout configuration
RequestConfig requestConfig = RequestConfig.NO_OP
.withRequestTimeout(60000) // 1 minute
.withClientExecutionTimeout(120000); // 2 minutes
// Request with progress tracking
ProgressListener progressListener = new ProgressListener() {
@Override
public void progressChanged(ProgressEvent progressEvent) {
System.out.println("Progress: " + progressEvent.getBytesTransferred());
}
};
RequestConfig progressConfig = RequestConfig.NO_OP
.withProgressListener(progressListener);import com.amazonaws.http.*;
import com.amazonaws.transform.Unmarshaller;
// Custom response handler
HttpResponseHandler<String> customHandler = new HttpResponseHandler<String>() {
@Override
public String handle(HttpResponse response) throws Exception {
// Read response content
InputStream content = response.getContent();
// Convert to string and return
return IOUtils.toString(content);
}
@Override
public boolean needsConnectionLeftOpen() {
return false;
}
};
// JSON response handler with unmarshaller
Unmarshaller<MyObject, JsonUnmarshallerContext> unmarshaller =
new MyObjectJsonUnmarshaller();
JsonResponseHandler<MyObject> jsonHandler =
new JsonResponseHandler<>(unmarshaller);Connection Pooling: Configure appropriate max connections based on your application's concurrency needs.
Timeout Configuration: Set reasonable connection, socket, and request timeouts to prevent hanging requests.
Retry Policies: Use appropriate retry policies for your use case, considering both client and service-side errors.
Proxy Configuration: Properly configure proxy settings for corporate environments, including authentication.
SSL/TLS Security: Use secure configurations and avoid trustAllCertificates in production environments.
Resource Management: Ensure HTTP clients and connection managers are properly closed to prevent resource leaks.
DNS Resolution: Use custom DNS resolvers for advanced networking scenarios or service discovery.
Monitoring: Implement request metric collectors to monitor HTTP performance and errors.
The HTTP transport layer provides comprehensive support for all aspects of HTTP communication with AWS services, enabling reliable and efficient network operations with extensive configuration options.
Install with Tessl CLI
npx tessl i tessl/maven-com-amazonaws--aws-java-sdk-core