Skip to content

feat(http-client): add Android support and implement SPI for A2AHttpClient#794

Open
sherryfox wants to merge 7 commits intoa2aproject:0.3.xfrom
sherryfox:0.3.x
Open

feat(http-client): add Android support and implement SPI for A2AHttpClient#794
sherryfox wants to merge 7 commits intoa2aproject:0.3.xfrom
sherryfox:0.3.x

Conversation

@sherryfox
Copy link
Copy Markdown

@sherryfox sherryfox commented Apr 14, 2026

Summary of Changes

This PR introduces Android support for the A2A HTTP client, decouples the hardcoded JDK client using the Service Provider Interface (SPI) pattern, and aligns with the upcoming Gson migration by rebasing onto the 0.3-workflows branch.

🌟 Key Highlights

  • Android Support: Added a dedicated HTTP client for Android using HttpURLConnection.
  • SPI Pattern: Decoupled JdkA2AHttpClient and introduced a factory to resolve the best client automatically.
  • Gson Alignment: Removed Jackson annotations from spec records to match the Gson fork approach.

📦 Detailed Changes

1. HTTP Client Factory & SPI Pattern

Introduced a factory and provider interface to allow pluggable HTTP client implementations via ServiceLoader.

  • A2AHttpClientFactory.java: Created to load implementations of A2AHttpClientProvider and select the one with the highest priority.
  • A2AHttpClientProvider.java: Introduced as the interface for providers.
  • Service Configurations: Added files to register the providers in:
    • http-client/src/main/resources/META-INF/services/io.a2a.client.http.A2AHttpClientProvider
    • http-client/src/main/resources_android/META-INF/services/io.a2a.client.http.A2AHttpClientProvider

2. Decoupling JdkA2AHttpClient

Removed hardcoded dependencies on JdkA2AHttpClient across the codebase.

  • JdkA2AHttpClient now implements A2AHttpClientProvider with a default priority of 0.
  • Updated the following files to use A2AHttpClientFactory.create() instead of direct instantiation:
    • A2A.java (in client/base)
    • A2ACardResolver.java (in http-client)
    • JSONRPCTransportProvider.java (in client/transport/jsonrpc)
    • RestTransportProvider.java (in client/transport/rest)

3. AndroidA2AHttpClient

  • Introduced AndroidA2AHttpClient.java using HttpURLConnection (which does not have forbidden dependencies on Android).
  • It implements A2AHttpClientProvider with a priority of 100, making it the preferred choice in Android environments.

4. Alignment with Gson Migration

  • Rebased onto ehsavoie/a2a-java:0.3-workflows to support the move to Gson and avoid 0.4 leaks.
  • Removed Jackson annotations from spec records (like AgentCapabilities, TaskStatus, etc.) as they are not needed in the Gson environment.

5. Documentation & Fixes

  • Documentation: Updated README.md to reflect that the default HTTP client is resolved automatically via the factory rather than being hardcoded.
  • Kafka Version Update: Kept the Kafka version at 4.2.0 (from the fork) in examples/cloud-deployment/k8s/02-kafka.yaml to ensure compatibility with the CI environment.

🧪 Verification Results

  • Build: Succeeded with mvn clean install -DskipTests=true.
  • Tests: All tests in the http-client module passed successfully (mvn test -pl http-client), including a new test verifying the factory behavior.

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests pass
  • Appropriate READMEs were updated (if necessary)

Fixes #793 🦕

…ct#789)

Replacing Jackson with Gson for json (de)serialization

Fixes #<issue_number_goes_here> 🦕

---------

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Co-authored-by: Kabir Khan <kkhan@redhat.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the HTTP client creation by introducing a ServiceLoader-based factory and adds an Android-specific implementation. It also enhances JSON serialization for several record classes in the spec module by adding @JsonProperty annotations. Feedback indicates that the new AndroidA2AHttpClient is missing specific error handling for 401 and 403 status codes in its asynchronous SSE implementation, which should be added to match the synchronous logic.

@sherryfox sherryfox force-pushed the 0.3.x branch 4 times, most recently from c35332a to ca14abd Compare April 15, 2026 08:32
ehsavoie and others added 6 commits April 15, 2026 16:54
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
Extract request id before jsonrpc validation so error responses include top-level id.

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
…lient

- Introduce `AndroidA2AHttpClient` using `HttpURLConnection` for Android compatibility.
- Implement `A2AHttpClientFactory` and `A2AHttpClientProvider` using `ServiceLoader` to decouple implementations.
- Update `A2A` and transport providers to use the factory instead of hardcoding `JdkA2AHttpClient`.
- Add `@JsonProperty` annotations to spec records to prevent parsing failures on Android.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants