Package org.a2aproject.sdk.client.http
Class A2AHttpClientFactory
java.lang.Object
org.a2aproject.sdk.client.http.A2AHttpClientFactory
Factory for creating
A2AHttpClient instances using the ServiceLoader mechanism.
This factory discovers available A2AHttpClientProvider implementations at runtime
and selects the one with the highest priority. If no providers are found, it throws
an IllegalStateException.
Usage
// Get the default client (highest priority provider)
A2AHttpClient client = A2AHttpClientFactory.create();
// Use with try-with-resources if the client implements AutoCloseable
try (A2AHttpClient client = A2AHttpClientFactory.create()) {
A2AHttpResponse response = client.createGet()
.url("https://example.com")
.get();
}
Priority System
Providers are selected based on their priority value (higher is better):
- JdkA2AHttpClient: priority 0 (fallback)
- VertxA2AHttpClient: priority 100 (preferred when available)
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()Creates a new A2AHttpClient instance using the highest priority provider available.static A2AHttpClientCreates a new A2AHttpClient instance using a specific provider by name.
-
Method Details
-
create
Creates a new A2AHttpClient instance using the highest priority provider available.This method uses the ServiceLoader mechanism to discover providers at runtime. If no providers are found, it throws an
IllegalStateException.- Returns:
- a new A2AHttpClient instance
- Throws:
IllegalStateException- if no providers are found
-
create
Creates a new A2AHttpClient instance using a specific provider by name.This method is useful for testing or when you need to force a specific implementation.
- Parameters:
providerName- the name of the provider to use- Returns:
- a new A2AHttpClient instance from the specified provider
- Throws:
IllegalArgumentException- if no provider with the given name is found
-