Skip to content

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

Open
sherryfox wants to merge 1 commit intoa2aproject:0.3.x-compatfrom
sherryfox:0.3.x
Open

feat(http-client): add Android support and implement SPI for A2AHttpClient#806
sherryfox wants to merge 1 commit intoa2aproject:0.3.x-compatfrom
sherryfox:0.3.x

Conversation

@sherryfox
Copy link
Copy Markdown

@sherryfox sherryfox commented Apr 21, 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

  • 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 🦕

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 implements a service-provider-based architecture for HTTP clients, enabling automatic resolution of the best implementation (e.g., Android vs. JDK) via an A2AHttpClientFactory. The changes include the addition of an AndroidA2AHttpClient and updates to various transport modules to utilize the new factory. Feedback focuses on enhancing the Android client's robustness by addressing potential data corruption in response parsing, implementing size limits to prevent memory issues, and using dedicated thread pools for network operations. Caching providers in the factory is also suggested to improve performance.

Comment thread http-client/src/main/java/io/a2a/client/http/AndroidA2AHttpClient.java Outdated
Comment thread http-client/src/main/java/io/a2a/client/http/A2AHttpClientFactory.java Outdated
@sherryfox sherryfox force-pushed the 0.3.x branch 2 times, most recently from d56dddb to f41989f Compare April 21, 2026 17:16
…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.

1 participant