Class JdkA2AHttpClient
- All Implemented Interfaces:
A2AHttpClient
HttpClient.
This is the fallback implementation used when no higher-priority
A2AHttpClientProvider is available. It provides full support for:
- HTTP/2 with automatic fallback to HTTP/1.1
- Synchronous GET, POST, and DELETE requests
- Asynchronous Server-Sent Events (SSE) streaming
Security Note: GET, DELETE, and GET SSE requests always use an internal
no-redirect client to prevent credential leakage, regardless of the redirect policy
configured on the supplied HttpClient. POST requests do not follow HTTP redirects
automatically either. To enable one-hop redirect following for a POST request, call
followRedirects(true) on the builder. Redirect headers are filtered by
RedirectHeaderPolicy.
Host header limitation: the underlying JDK HttpClient
rejects addHeader("Host", ...) with an IllegalArgumentException
("restricted header name") unless the JVM is started with
-Djdk.httpclient.allowRestrictedHeaders=host. This is a JDK-wide
restriction that cannot be worked around per-client-instance. Applications that
need to send an explicit Host header (for example, connecting directly to
an instance while presenting the hostname a load balancer normally supplies) should
either set that system property or use an A2AHttpClient implementation that
does not build on java.net.http.HttpClient, such as
org.a2aproject.sdk.client.http.vertx.VertxA2AHttpClient (the
a2a-java-sdk-http-client-vertx extra), which has no such restriction.
Provider Priority: 0 (lowest - used as fallback)
This implementation is registered via JdkA2AHttpClientProvider
in the ServiceLoader system and is automatically used by A2AHttpClientFactory
when no other provider is available.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.a2aproject.sdk.client.http.A2AHttpClient
A2AHttpClient.Builder<T extends A2AHttpClient.Builder<T>>, A2AHttpClient.DeleteBuilder, A2AHttpClient.GetBuilder, A2AHttpClient.PostBuilder -
Field Summary
Fields inherited from interface org.a2aproject.sdk.client.http.A2AHttpClient
ACCEPT, APPLICATION_JSON, CONTENT_TYPE, EVENT_STREAM -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new JDK-based HTTP client with secure defaults.JdkA2AHttpClient(HttpClient httpClient) Creates a new JDK-based HTTP client using a caller-provided JDKHttpClient.JdkA2AHttpClient(HttpClient httpClient, SSEParserConfig sseParserConfig) Creates a new JDK-based HTTP client using a caller-provided JDKHttpClientand custom SSE parser limits.JdkA2AHttpClient(HttpClient httpClient, SSEParserConfig sseParserConfig, RedirectHeaderPolicy redirectHeaderPolicy) Creates a new JDK HTTP client with caller-supplied transport and redirect policies. -
Method Summary
Modifier and TypeMethodDescriptionCreates a builder for DELETE requests.Creates a builder for GET requests.Creates a builder for POST requests.static JdkA2AHttpClientwithConfiguration(SSEParserConfig sseParserConfig, RedirectHeaderPolicy redirectHeaderPolicy) Creates a default JDK client with custom SSE and redirect settings.static JdkA2AHttpClientwithRedirectHeaderPolicy(HttpClient httpClient, RedirectHeaderPolicy redirectHeaderPolicy) Creates a JDK HTTP client with a caller-supplied transport and redirect header policy.static JdkA2AHttpClientwithRedirectHeaderPolicy(RedirectHeaderPolicy redirectHeaderPolicy) Creates a new JDK HTTP client with a custom redirect header policy.static JdkA2AHttpClientwithSseConfig(SSEParserConfig sseParserConfig) Creates a new JDK-based HTTP client with secure defaults and custom SSE parser limits.
-
Constructor Details
-
JdkA2AHttpClient
public JdkA2AHttpClient()Creates a new JDK-based HTTP client with secure defaults.Configures the client with:
- HTTP/2 preferred (with HTTP/1.1 fallback)
- No automatic redirect following (security hardening to prevent credential leakage)
To enable redirect following for POST requests, call
followRedirects(true)on each builder. -
JdkA2AHttpClient
Creates a new JDK-based HTTP client using a caller-provided JDKHttpClient.This constructor allows full control over the
HttpClientconfiguration, such as custom SSL settings, proxy, or executor. GET, DELETE, and GET SSE requests always route through an internal no-redirect clone of the supplied client, so their redirect policy is enforced by the SDK regardless of the policy set on the suppliedHttpClient.For POST redirect following, the supplied client must use
HttpClient.Redirect.NEVER; the SDK applies its redirect header policy before issuing the follow-up request.POST redirect opt-in requires two steps: this client is only used for a POST request when
followRedirects(true)is also called on the builder. If the flag is not set the builder uses an internal no-redirect client regardless of the policy configured on thehttpClientsupplied here.- Parameters:
httpClient- the JDK HTTP client to delegate requests to- Throws:
IllegalArgumentException- ifhttpClientisnull
-
JdkA2AHttpClient
Creates a new JDK-based HTTP client using a caller-provided JDKHttpClientand custom SSE parser limits.- Parameters:
httpClient- the JDK HTTP client to delegate requests tosseParserConfig- the SSE parser configuration to use for streaming responses- Throws:
IllegalArgumentException- ifhttpClientorsseParserConfigisnull
-
JdkA2AHttpClient
public JdkA2AHttpClient(HttpClient httpClient, SSEParserConfig sseParserConfig, RedirectHeaderPolicy redirectHeaderPolicy) Creates a new JDK HTTP client with caller-supplied transport and redirect policies.When
followRedirects(true)is used, the suppliedhttpClientmust be configured withHttpClient.Redirect.NEVER. This lets the SDK apply the redirect header policy before issuing the follow-up request.- Parameters:
httpClient- the JDK HTTP client to delegate requests tosseParserConfig- the SSE parser configurationredirectHeaderPolicy- policy applied to explicitly enabled POST redirects
-
-
Method Details
-
withRedirectHeaderPolicy
Creates a new JDK HTTP client with a custom redirect header policy.- Parameters:
redirectHeaderPolicy- policy applied to explicitly enabled POST redirects- Returns:
- a client with secure transport defaults and the supplied redirect policy
-
withRedirectHeaderPolicy
public static JdkA2AHttpClient withRedirectHeaderPolicy(HttpClient httpClient, RedirectHeaderPolicy redirectHeaderPolicy) Creates a JDK HTTP client with a caller-supplied transport and redirect header policy.- Parameters:
httpClient- the JDK HTTP client to delegate requests toredirectHeaderPolicy- policy applied to explicitly enabled POST redirects- Returns:
- a client using the supplied transport and redirect policy
-
withSseConfig
Creates a new JDK-based HTTP client with secure defaults and custom SSE parser limits.Named factory method avoids overload ambiguity with
JdkA2AHttpClient(HttpClient).- Parameters:
sseParserConfig- the SSE parser configuration to use for streaming responses- Returns:
- a new JdkA2AHttpClient with the given SSE parser configuration
- Throws:
IllegalArgumentException- ifsseParserConfigisnull
-
withConfiguration
public static JdkA2AHttpClient withConfiguration(SSEParserConfig sseParserConfig, RedirectHeaderPolicy redirectHeaderPolicy) Creates a default JDK client with custom SSE and redirect settings. -
createGet
Description copied from interface:A2AHttpClientCreates a builder for GET requests.- Specified by:
createGetin interfaceA2AHttpClient- Returns:
- a new GetBuilder instance
-
createPost
Description copied from interface:A2AHttpClientCreates a builder for POST requests.- Specified by:
createPostin interfaceA2AHttpClient- Returns:
- a new PostBuilder instance
-
createDelete
Description copied from interface:A2AHttpClientCreates a builder for DELETE requests.- Specified by:
createDeletein interfaceA2AHttpClient- Returns:
- a new DeleteBuilder instance
-