Class A2AHttpClientFactory

java.lang.Object
org.a2aproject.sdk.client.http.A2AHttpClientFactory

public final class A2AHttpClientFactory extends Object
Factory for creating 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-client is 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.