Skip to content

Conversation

@jmesnil
Copy link
Collaborator

@jmesnil jmesnil commented Nov 27, 2025

Set Content-Type: application/json header when sending push notifications
to prevent 415 Unsupported Media Type errors. The request was previously
defaulting to application/octet-stream.

Updates tests to verify that the Content-Type header is always present
in push notification requests, regardless of whether authentication
token is included.

Fixes: #486
Signed-off-by: Jeff Mesnil jmesnil@ibm.com

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jmesnil, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue preventing successful push notifications by ensuring that all outgoing requests correctly specify their content type as application/json. This change prevents 415 Unsupported Media Type errors and improves the reliability of the push notification system. The accompanying test updates guarantee the consistent application of this header.

Highlights

  • Fix Content-Type Header: The pull request addresses an issue where push notification requests were sent without the correct Content-Type header, defaulting to application/octet-stream and causing 415 Unsupported Media Type errors. It now explicitly sets Content-Type: application/json for all push notification requests.
  • Updated Test Coverage: Existing tests have been updated and new assertions added to verify that the Content-Type: application/json header is consistently present in all push notification requests, regardless of whether an authentication token is included or not.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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 correctly adds the Content-Type header to push notification requests to fix the 415 Unsupported Media Type error. The changes are logical and the tests have been updated accordingly. I have a few suggestions to improve code maintainability and test robustness, mainly related to using constants for header strings and adding more specific assertions in tests. I've also pointed out an opportunity to reduce code duplication in one of the test files.

Set `Content-Type: application/json` header when sending push notifications
to prevent `415 Unsupported Media Type` errors. The request was previously
defaulting to `application/octet-stream`.

Add constants to A2AHttpClient to represent standard HTTP headers.

Updates tests to verify that the `Content-Type` header is always present
in push notification requests, regardless of whether authentication
token is included.

Fixes: a2aproject#486
Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>
@jmesnil jmesnil force-pushed the 486_missing_content-type branch from db5ae86 to 01f9653 Compare November 27, 2025 09:55
@jmesnil
Copy link
Collaborator Author

jmesnil commented Nov 27, 2025

/gemini review

Copy link
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 correctly addresses the issue of missing Content-Type headers in push notification requests by adding Content-Type: application/json. The implementation is straightforward and the associated tests have been updated comprehensively to verify the presence of this header in all relevant scenarios. The changes look good. I have one suggestion regarding the use of standard constants for HTTP headers to improve maintainability.

Comment on lines +10 to +11
String CONTENT_TYPE= "Content-Type";
String APPLICATION_JSON= "application/json";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and adhere to standard practices, it's better to use predefined constants for common HTTP headers and media types instead of defining them manually. The Jakarta RESTful Web Services API (jakarta.ws.rs.core), which seems to be part of your project's dependencies, provides these.

I recommend removing these custom constants and using the standard ones throughout the codebase.

  1. Remove these lines.
  2. In files that use CONTENT_TYPE and APPLICATION_JSON, replace the static imports with:
    import static jakarta.ws.rs.core.HttpHeaders.CONTENT_TYPE;
    import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;

This change would affect the following files in this PR:

  • extras/push-notification-config-store-database-jpa/src/test/java/io/a2a/extras/pushnotificationconfigstore/database/jpa/JpaPushNotificationConfigStoreTest.java
  • server-common/src/main/java/io/a2a/server/tasks/BasePushNotificationSender.java
  • server-common/src/test/java/io/a2a/server/tasks/InMemoryPushNotificationConfigStoreTest.java
  • server-common/src/test/java/io/a2a/server/tasks/PushNotificationSenderTest.java

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Code does not depend on jakarta.ws.rs.core and shouldn't be depending on it for the sake of a few common HTTP constants.

@jmesnil
Copy link
Collaborator Author

jmesnil commented Nov 27, 2025

/gemini summary

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request addresses a critical bug where push notification requests were failing due to missing or incorrect "Content-Type" headers, leading to "415 Unsupported Media Type" errors. By explicitly setting "Content-Type: application/json" for these requests and introducing constants for HTTP header values, the change ensures reliable push notification delivery. The accompanying test updates provide robust verification of this fix, confirming the header's presence in various scenarios.

Highlights

  • Ensured JSON Content-Type: Explicitly sets the "Content-Type" header to "application/json" for all outgoing push notification requests, resolving "415 Unsupported Media Type" errors that occurred when the header defaulted to "application/octet-stream".
  • Introduced HTTP Constants: Defined "CONTENT_TYPE" and "APPLICATION_JSON" as constants within "A2AHttpClient" for improved maintainability and consistency across the codebase when dealing with HTTP header names and values.
  • Enhanced Test Coverage: Updated existing tests across multiple modules to verify the consistent presence and correct value of the "Content-Type" header in push notification requests, regardless of whether an authentication token is included or not.
Changelog
  • extras/push-notification-config-store-database-jpa/src/test/java/io/a2a/extras/pushnotificationconfigstore/database/jpa/JpaPushNotificationConfigStoreTest.java
    • Added static imports for "A2AHttpClient.APPLICATION_JSON" and "A2AHttpClient.CONTENT_TYPE".
    • Modified "testSendNotificationSuccess" to mock and verify the addition of the "Content-Type: application/json" header to POST requests.
  • http-client/src/main/java/io/a2a/client/http/A2AHttpClient.java
    • Introduced "public static final" string constants "CONTENT_TYPE" and "APPLICATION_JSON" for HTTP header names and values.
  • server-common/src/main/java/io/a2a/server/tasks/BasePushNotificationSender.java
    • Added static imports for "A2AHttpClient.APPLICATION_JSON" and "A2AHttpClient.CONTENT_TYPE".
    • Ensured the "Content-Type: application/json" header is added to the "postBuilder" when dispatching notifications.
  • server-common/src/test/java/io/a2a/server/tasks/InMemoryPushNotificationConfigStoreTest.java
    • Added static imports for "A2AHttpClient.APPLICATION_JSON" and "A2AHttpClient.CONTENT_TYPE".
    • Updated "setupBasicMockHttpResponse" to mock the "Content-Type" header.
    • Refactored "testSendNotificationSuccess" to use the "setupBasicMockHttpResponse()" helper method, reducing code duplication.
  • server-common/src/test/java/io/a2a/server/tasks/PushNotificationSenderTest.java
    • Added static imports for "A2AHttpClient.APPLICATION_JSON" and "A2AHttpClient.CONTENT_TYPE".
    • Modified "testSendNotificationWithInvalidToken" to assert the presence of only the "Content-Type" header when no authentication token is sent, and verify its value.
    • Modified "testSendNotificationWithTokenSuccess" to assert the presence of both the authentication token and "Content-Type" headers, and verify their values.
Activity
  • "gemini-code-assist[bot]" provided an initial summary of the changes, highlighting the fix for the "Content-Type" header and updated test coverage.
  • "jmesnil" requested a code review and a summary from "gemini-code-assist[bot]".
  • "gemini-code-assist[bot]" provided several review comments, primarily suggesting the use of standard Jakarta constants for HTTP headers and consolidating test setup in tests.
  • "jmesnil" responded to a suggestion from "gemini-code-assist[bot]", clarifying that the project does not depend on "jakarta.ws.rs.core" and should not introduce such a dependency solely for common HTTP constants.

@kabir kabir merged commit 686e40a into a2aproject:main Nov 27, 2025
10 checks passed
@jmesnil jmesnil added this to the 1.0.0 milestone Dec 11, 2025
kabir pushed a commit to kabir/a2a-java that referenced this pull request Dec 23, 2025
…t#489)

Set `Content-Type: application/json` header when sending push
notifications
to prevent `415 Unsupported Media Type` errors. The request was
previously
defaulting to `application/octet-stream`.

Updates tests to verify that the `Content-Type` header is always present
in push notification requests, regardless of whether authentication
token is included.

Fixes: a2aproject#486
Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>

- [X] Follow the [`CONTRIBUTING` Guide](../CONTRIBUTING.md).
- [X] Make your Pull Request title in the
<https://www.conventionalcommits.org/> specification.
- Important Prefixes for
[release-please](https://github.com/googleapis/release-please):
- `fix:` which represents bug fixes, and correlates to a
[SemVer](https://semver.org/) 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.
- [X] Ensure the tests pass
- [X] Appropriate READMEs were updated (if necessary)

Fixes a2aproject#486 🦕

Signed-off-by: Jeff Mesnil <jmesnil@ibm.com>
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.

[Bug]: Missing Content-Type: application/json request header for push notification request

2 participants