Class A2AHttpClientFactory
A2AHttpClient instances using the ServiceLoader mechanism.
This factory discovers available A2AHttpClientProvider implementations at runtime,
tries them in descending priority order, and returns the first one that succeeds.
If no provider can be instantiated, it throws an IllegalStateException.
Usage
// Get the default client (highest available priority provider)
A2AHttpClient client = A2AHttpClientFactory.create(A2AHttpClientConfiguration.DEFAULT);
// Use with try-with-resources if the client implements AutoCloseable
try (A2AHttpClient client = A2AHttpClientFactory.create(A2AHttpClientConfiguration.DEFAULT)) {
A2AHttpResponse response = client.createGet()
.url("https://example.com")
.get();
}
Priority System
Providers are tried in descending priority order. If a provider's create() throws,
the factory logs the failure at WARNING level and falls back to the next provider:
- CdiA2AHttpClient: priority 200 (CDI-provided bean, when a container and bean are active)
- AndroidA2AHttpClient: priority 110 (Android runtime only)
- VertxA2AHttpClient: priority 100 (when
vertx-web-clientis on the classpath) - JdkA2AHttpClient: priority 0 (always available, last resort)
Custom Providers
To add a custom provider, implement A2AHttpClientProvider and register it
in META-INF/services/org.a2aproject.sdk.client.http.A2AHttpClientProvider.
-
Method Summary
Modifier and TypeMethodDescriptionstatic A2AHttpClientcreate()Deprecated.static A2AHttpClientDeprecated.static A2AHttpClientcreate(A2AHttpClientConfiguration configuration) Creates a new A2AHttpClient using the supplied selection and client configuration.static A2AHttpClientcreateExcluding(String... excludedProviderNames) Deprecated.static A2AHttpClientcreateWithSseConfig(SSEParserConfig sseParserConfig) Deprecated.
-
Method Details
-
create
Deprecated.Creates a new A2AHttpClient instance using the highest available priority provider.Providers are tried in descending priority order. If a provider's
create()throws, it is skipped and the next provider is tried. Failures are logged atWARNINGlevel.- Returns:
- a new A2AHttpClient instance
- Throws:
IllegalStateException- if no provider found or all providers failed to instantiate
-
createExcluding
@Deprecated(forRemoval=false) public static A2AHttpClient createExcluding(String... excludedProviderNames) Deprecated.Creates a client while excluding the named providers.This overload is retained for source and binary compatibility. Use
create(A2AHttpClientConfiguration)withA2AHttpClientConfiguration.Builder.excludedProviderNames(List)for new code.- Parameters:
excludedProviderNames- names of providers to skip- Returns:
- a client from the highest-priority non-excluded provider
- Throws:
IllegalStateException- if no eligible provider could be instantiated
-
createWithSseConfig
@Deprecated(forRemoval=false) public static A2AHttpClient createWithSseConfig(SSEParserConfig sseParserConfig) Deprecated.Creates a client with custom SSE parser settings.This overload is retained for source and binary compatibility. Use
create(A2AHttpClientConfiguration)withA2AHttpClientConfiguration.Builder.sseParserConfig(SSEParserConfig)for new code.- Parameters:
sseParserConfig- SSE parser settings, ornullfor defaults- Returns:
- a client from the highest-priority provider that supports the settings
- Throws:
IllegalStateException- if no eligible provider could be instantiated
-
create
Deprecated.Creates a client from the named provider.This overload is retained for source and binary compatibility. New code should use
create(A2AHttpClientConfiguration)and exclude unwanted providers instead.- Parameters:
providerName- the provider name- Returns:
- a client from the named provider
- Throws:
IllegalArgumentException- if the name is null, empty, or unknown
-
create
Creates a new A2AHttpClient using the supplied selection and client configuration.When SSE parser limits or a redirect-header policy are configured, providers that do not support them are skipped. This ensures configured values are never silently ignored.
- Parameters:
configuration- provider exclusions and optional client settings- Returns:
- a configured client from the highest-priority eligible provider
- Throws:
IllegalStateException- if no eligible provider could be instantiated
-
create(A2AHttpClientConfiguration)withA2AHttpClientConfiguration.DEFAULT