Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A2aproject A2a java JdkA2AHttpClient

From Leeroopedia
Knowledge Sources
Domains HTTP_Client, SSE, Security
Last Updated 2026-10-30 00:00 GMT

Overview

Concrete default JDK-based HTTP client implementation using `java.net.http.HttpClient` with SSE streaming, redirect protection, and configurable parser limits.

Description

The JdkA2AHttpClient class implements the A2AHttpClient SPI using Java 11+ HttpClient. It provides full support for HTTP/2 with HTTP/1.1 fallback, synchronous GET/POST/DELETE requests, and asynchronous Server-Sent Events (SSE) streaming via ServerSentEventParser and BoundedLineAccumulator. By default, it does not follow HTTP redirects to prevent credential leakage (security hardening). Redirect following for POST requires both a redirect-capable `HttpClient` constructor argument and `followRedirects(true)` on the builder. Registered as the fallback provider (priority 0) via JdkA2AHttpClientProvider.

Usage

  • Default HTTP client: Automatically used by A2AHttpClientFactory when no higher-priority provider (Vert.x, Android) is on the classpath
  • SSE streaming: Handles streaming responses for `sendMessageStreaming` and `subscribeToTask` across all transports
  • Custom configuration: Use `JdkA2AHttpClient(HttpClient)` for custom HTTP client settings (TLS, proxy, timeouts)
  • SSRF protection: Push notification delivery uses the no-redirect client to prevent SSRF bypass

Code Reference

Source Location

  • Repository: a2a-java
  • File: `http-client/src/main/java/org/a2aproject/sdk/client/http/JdkA2AHttpClient.java`
  • Lines: L71-668

Signature

public class JdkA2AHttpClient implements A2AHttpClient {
    public JdkA2AHttpClient();
    public static JdkA2AHttpClient withSseConfig(SSEParserConfig sseParserConfig);
    public JdkA2AHttpClient(HttpClient httpClient);
    public JdkA2AHttpClient(HttpClient httpClient, SSEParserConfig sseParserConfig);

    @Override GetBuilder createGet();
    @Override PostBuilder createPost();
    @Override DeleteBuilder createDelete();

    // Inner builder classes: JdkGetBuilder, JdkPostBuilder, JdkDeleteBuilder
    // Each supports addHeader(), addHeaders(), url()
    // GetBuilder: get(), getAsyncSSE()
    // PostBuilder: body(), post(), postAsyncSSE(), followRedirects(boolean)
    // DeleteBuilder: delete()
}

Import

import org.a2aproject.sdk.client.http.JdkA2AHttpClient;

I/O Contract

Inputs

Name Type Required Description
httpClient java.net.http.HttpClient No (default created) Custom JDK HTTP client
sseParserConfig SSEParserConfig No (DEFAULT used) SSE parsing limits
url String Yes Target URL for each request
body String Yes (POST) Request body (typically JSON)
headers Map<String, String> No HTTP headers
followRedirects boolean No (false) Whether to follow HTTP redirects

Outputs

Name Type Description
get/post/delete returns A2AHttpResponse HTTP response with status, headers, body
getAsyncSSE/postAsyncSSE returns CompletableFuture<Void> Completes when SSE stream ends
SSE events ServerSentEvent Delivered to messageConsumer callback

Usage Examples

Synchronous POST Request

import org.a2aproject.sdk.client.http.JdkA2AHttpClient;
import org.a2aproject.sdk.client.http.A2AHttpResponse;

JdkA2AHttpClient client = new JdkA2AHttpClient();

A2AHttpResponse response = client.createPost()
    .url("http://localhost:9999/message:send")
    .body("{\"jsonrpc\":\"2.0\",\"method\":\"message/send\",...}")
    .addHeader("Content-Type", "application/json")
    .post();

System.out.println("Status: " + response.statusCode());
System.out.println("Body: " + response.body());

SSE Streaming with Custom Parser Limits

import org.a2aproject.sdk.client.http.SSEParserConfig;

SSEParserConfig config = new SSEParserConfig.Builder()
    .setMaxEventSize(1_000_000)
    .setMaxLineLength(10_000)
    .build();

JdkA2AHttpClient client = JdkA2AHttpClient.withSseConfig(config);

client.createPost()
    .url("http://localhost:9999/message:stream")
    .body(jsonBody)
    .postAsyncSSE(
        event -> System.out.println("Event: " + event.data()),
        error -> System.err.println("Error: " + error),
        () -> System.out.println("Stream complete")
    );

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment