You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ba5f199
Browse filesBrowse the repository at this point in the historyBrowse files
feat(http-client): add CDI provider and priority-ordered factory fallback
- extras/http-client-cdi: CdiA2AHttpClientProvider at priority 200 resolves
a user-provided A2AHttpClient bean from CDI; falls back gracefully when no
container is active or no unambiguous bean is found
- A2AHttpClientFactory now sorts providers at class init and iterates in order,
catching exceptions per-provider; create(String) reuses the cached list
instead of reloading ServiceLoader on each call
- tests use Weld SE SeContainerInitializer (no mocks) covering all four paths:
bean present, no bean, ambiguous, no CDI container
- update A2AHttpClientProvider Javadoc with full four-tier priority table
- fix VertxA2AHttpClientProvider Javadoc and rename log field to LOGGER
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Copy file name to clipboardExpand all lines: docs/content/dev/extra/http-clients.md
+64-3Lines changed: 64 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ layout: page
6
6
7
7
# HTTP Clients
8
8
9
-
The A2A SDK uses an `A2AHttpClient` abstraction for all HTTP communication — fetching agent cards, making transport calls, and Server-Sent Events (SSE) streaming. By default, the SDK uses a JDK 11+ HttpClient implementation. These extras provide alternative implementations.
9
+
The A2A SDK uses an `A2AHttpClient` abstraction for all HTTP communication — fetching agent cards, making transport calls, and Server-Sent Events (SSE) streaming. By default, the SDK uses a JDK 11+ HttpClient implementation. These extras provide alternative implementations or a CDI-based extension point for custom clients.
10
10
11
11
## Vert.x HTTP Client
12
12
@@ -53,7 +53,19 @@ For non-Quarkus environments, also add `vertx-web-client`:
53
53
54
54
### 2. Automatic Discovery (No Code Changes)
55
55
56
-
The `VertxA2AHttpClientProvider` has **priority 100** (vs. 0 for the JDK client). The SDK's `A2AHttpClientFactory` uses `ServiceLoader` to discover and select the highest-priority provider available:
56
+
The `VertxA2AHttpClientProvider` has **priority 100**. The SDK's `A2AHttpClientFactory` discovers all registered providers via `ServiceLoader`, sorts them by descending priority, and tries each in order, falling back to the next one on failure.
57
+
58
+
To force a specific provider by name (useful in tests), use `A2AHttpClientFactory.create(String providerName)`:
59
+
60
+
```java
61
+
// Force the JDK client regardless of what else is on the classpath
If Vert.x classes are not on the classpath, the provider returns priority `-1` and the SDK falls back to the JDK HttpClient.
80
+
If Vert.x classes are not on the classpath, the provider returns priority `-1` and the SDK falls back to the next available provider.
69
81
70
82
### Usage Examples
71
83
@@ -205,3 +217,52 @@ The `AndroidA2AHttpClientProvider` has **priority 110** and detects the Android
205
217
-**SSE streaming** via `getAsyncSSE()` and `postAsyncSSE()` — async operations run on a dedicated cached thread pool (`A2A-Android-Net`)
206
218
-**Timeouts**: 15 s connection, 60 s read
207
219
-**Response size limit**: 10 MB
220
+
221
+
## CDI HTTP Client
222
+
223
+
Allows providing a fully custom `A2AHttpClient` bean through the CDI container. When this module is on the classpath and a user-provided `A2AHttpClient` bean is registered, it is used in place of any other provider.
224
+
225
+
### When to Use
226
+
227
+
- Quarkus or Jakarta EE applications that need a custom HTTP client (specific TLS configuration, connection pooling, tracing, etc.)
228
+
- When neither the JDK nor the Vert.x client meets your requirements out of the box
Declare a CDI producer in your application. The SDK will discover and use it automatically:
242
+
243
+
```java
244
+
@ApplicationScoped
245
+
publicclassMyHttpClientProducer {
246
+
247
+
@Produces
248
+
@ApplicationScoped
249
+
publicA2AHttpClientproduce(MyConfigconfig) {
250
+
// return any A2AHttpClient implementation
251
+
}
252
+
}
253
+
```
254
+
255
+
> **Scope requirement:** Use a normal scope such as `@ApplicationScoped`. A `@Dependent`-scoped producer will leak a new unmanaged instance on every `create()` call because the `Instance` used to obtain the bean is discarded immediately and CDI cannot destroy the dependent instance.
256
+
257
+
### How It Works
258
+
259
+
`CdiA2AHttpClientProvider` has **priority 200** — the highest of all built-in providers (Android: 110, Vert.x: 100, JDK: 0). The `A2AHttpClientFactory` iterates providers in descending priority order and falls back to the next one if a provider is unavailable:
260
+
261
+
| Priority | Provider | Activates when |
262
+
|----------|----------|----------------|
263
+
| 200 | CDI | A CDI container is active and an `A2AHttpClient` bean is registered |
264
+
| 110 | Android | Android runtime detected |
265
+
| 100 | Vert.x |`vertx-web-client` is on the classpath |
266
+
| 0 | JDK | Always (fallback) |
267
+
268
+
If the CDI container is active but no `A2AHttpClient` bean is registered, this provider is skipped and the next available provider is used.
Copy file name to clipboardExpand all lines: docs/content/dev/extras.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ Import the extras BOM to manage versions:
30
30
31
31
## [HTTP Clients](../extra/http-clients)
32
32
33
-
Alternative `A2AHttpClient` implementations. The **Vert.x HTTP Client** (`a2a-java-sdk-http-client-vertx`) replaces the default JDK HttpClient with a reactive, non-blocking Vert.x WebClient — recommended for Quarkus, reactive frameworks, and high-throughput scenarios. An **Android HTTP Client** (`a2a-java-sdk-http-client-android`) is also available for mobile applications.
33
+
Alternative `A2AHttpClient` implementations. The **Vert.x HTTP Client** (`a2a-java-sdk-http-client-vertx`) replaces the default JDK HttpClient with a reactive, non-blocking Vert.x WebClient — recommended for Quarkus, reactive frameworks, and high-throughput scenarios. An **Android HTTP Client** (`a2a-java-sdk-http-client-android`) is available for mobile applications. The **CDI HTTP Client** (`a2a-java-sdk-http-client-cdi`) lets you supply any custom `A2AHttpClient` bean via the CDI container, taking highest priority (200) over all built-in providers.
0 commit comments