Skip to content

Commit 8ad8f08

Browse files
committed
refactor(rest): accept a2a+json on server but send old one
1 parent eae33bc commit 8ad8f08

3 files changed

Lines changed: 23 additions & 26 deletions

File tree

‎common/src/main/java/org/a2aproject/sdk/common/MediaType.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ public interface MediaType {
66
/** MIME type for JSON content: {@code application/json}. */
77
String APPLICATION_JSON = "application/json";
88

9-
/** MIME type the HTTP+JSON binding should use (A2A spec section 11): {@code application/a2a+json}. */
9+
/** MIME type accepted from HTTP+JSON clients alongside {@code application/json}: {@code application/a2a+json}. */
1010
String APPLICATION_A2A_JSON = "application/a2a+json";
1111
}

‎transport/rest/src/main/java/org/a2aproject/sdk/transport/rest/handler/RestHandler.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.a2aproject.sdk.transport.rest.handler;
22

3-
import static org.a2aproject.sdk.common.MediaType.APPLICATION_A2A_JSON;
43
import static org.a2aproject.sdk.common.MediaType.APPLICATION_JSON;
54
import static org.a2aproject.sdk.server.util.async.AsyncUtils.createTubeConfig;
65

@@ -703,7 +702,7 @@ private HTTPRestResponse createSuccessResponse(int statusCode, com.google.protob
703702
try {
704703
// Include default value fields to ensure empty arrays, zeros, etc. are present in JSON
705704
String jsonBody = ProtoJsonUtils.toJson(JsonFormat.printer().alwaysPrintFieldsWithNoPresence(), builder);
706-
return new HTTPRestResponse(statusCode, APPLICATION_A2A_JSON, jsonBody);
705+
return new HTTPRestResponse(statusCode, APPLICATION_JSON, jsonBody);
707706
} catch (InvalidProtocolBufferException e) {
708707
LOGGER.log(Level.SEVERE, "Failed to serialize response", e);
709708
return createErrorResponse(new InternalError("Internal error"));
@@ -723,7 +722,7 @@ public HTTPRestResponse createErrorResponse(A2AError error) {
723722

724723
private HTTPRestResponse createErrorResponse(int statusCode, A2AError error) {
725724
String jsonBody = new HTTPRestErrorResponse(error).toJson();
726-
return new HTTPRestResponse(statusCode, APPLICATION_A2A_JSON, jsonBody);
725+
return new HTTPRestResponse(statusCode, APPLICATION_JSON, jsonBody);
727726
}
728727

729728
/**

‎transport/rest/src/test/java/org/a2aproject/sdk/transport/rest/handler/RestHandlerTest.java‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.a2aproject.sdk.transport.rest.handler;
22

3-
import static org.a2aproject.sdk.common.MediaType.APPLICATION_A2A_JSON;
43
import static org.a2aproject.sdk.common.MediaType.APPLICATION_JSON;
54

65
import java.util.Collections;
@@ -60,13 +59,13 @@ public void testGetTaskSuccess() {
6059
RestHandler.HTTPRestResponse response = handler.getTask(callContext, "", MINIMAL_TASK.id(), 0);
6160

6261
Assertions.assertEquals(200, response.getStatusCode());
63-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
62+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
6463
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
6564

6665
response = handler.getTask(callContext, "", MINIMAL_TASK.id(), 2);
6766

6867
Assertions.assertEquals(200, response.getStatusCode());
69-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
68+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
7069
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
7170
}
7271

@@ -99,7 +98,7 @@ public void testListTasksStatusWireString() {
9998
null, null, null);
10099

101100
Assertions.assertEquals(200, response.getStatusCode());
102-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
101+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
103102
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
104103
}
105104

@@ -141,7 +140,7 @@ public void testSendMessage() throws InvalidProtocolBufferException {
141140

142141
RestHandler.HTTPRestResponse response = handler.sendMessage(callContext, "", requestBody);
143142
Assertions.assertEquals(200, response.getStatusCode(), response.toString());
144-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
143+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
145144
Assertions.assertNotNull(response.getBody());
146145
}
147146

@@ -176,7 +175,7 @@ public void testSendMessageWrongValueBody() {
176175
RestHandler.HTTPRestResponse response = handler.sendMessage(callContext, "", requestBody);
177176

178177
Assertions.assertEquals(422, response.getStatusCode());
179-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
178+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
180179
JsonObject body = JsonParser.parseString(response.getBody()).getAsJsonObject();
181180
JsonObject error = body.getAsJsonObject("error");
182181
Assertions.assertEquals(422, error.get("code").getAsInt());
@@ -212,7 +211,7 @@ public void testCancelTaskSuccess() {
212211
RestHandler.HTTPRestResponse response = handler.cancelTask(callContext, "", requestBody, MINIMAL_TASK.id());
213212

214213
Assertions.assertEquals(200, response.getStatusCode());
215-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
214+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
216215
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
217216
}
218217

@@ -254,7 +253,7 @@ public void testCancelTaskWithMetadata() {
254253
RestHandler.HTTPRestResponse response = handler.cancelTask(callContext, "", requestBody, MINIMAL_TASK.id());
255254

256255
Assertions.assertEquals(200, response.getStatusCode());
257-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
256+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
258257
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
259258
}
260259

@@ -278,7 +277,7 @@ public void testCancelTaskWithEmptyMetadata() {
278277
RestHandler.HTTPRestResponse response = handler.cancelTask(callContext, "", requestBody, MINIMAL_TASK.id());
279278

280279
Assertions.assertEquals(200, response.getStatusCode());
281-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
280+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
282281
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
283282
}
284283

@@ -298,7 +297,7 @@ public void testCancelTaskWithNoMetadata() {
298297
RestHandler.HTTPRestResponse response = handler.cancelTask(callContext, "", requestBody, MINIMAL_TASK.id());
299298

300299
Assertions.assertEquals(200, response.getStatusCode());
301-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
300+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
302301
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
303302
}
304303

@@ -316,7 +315,7 @@ public void testCancelTaskWithNullBody() {
316315
RestHandler.HTTPRestResponse response = handler.cancelTask(callContext, "", null, MINIMAL_TASK.id());
317316

318317
Assertions.assertEquals(200, response.getStatusCode());
319-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
318+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
320319
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
321320
}
322321

@@ -391,7 +390,7 @@ public void testPushNotificationConfigSuccess() {
391390
RestHandler.HTTPRestResponse response = handler.createTaskPushNotificationConfiguration(callContext, "", requestBody, MINIMAL_TASK.id());
392391

393392
Assertions.assertEquals(201, response.getStatusCode(), response.toString());
394-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
393+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
395394
Assertions.assertNotNull(response.getBody());
396395
}
397396

@@ -432,11 +431,11 @@ public void testGetPushNotificationConfig() {
432431
}""".formatted(MINIMAL_TASK.id());
433432
RestHandler.HTTPRestResponse response = handler.createTaskPushNotificationConfiguration(callContext, "", createRequestBody, MINIMAL_TASK.id());
434433
Assertions.assertEquals(201, response.getStatusCode(), response.toString());
435-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
434+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
436435
// Now get it
437436
response = handler.getTaskPushNotificationConfiguration(callContext, "", MINIMAL_TASK.id(), "default-config-id");
438437
Assertions.assertEquals(200, response.getStatusCode(), response.toString());
439-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
438+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
440439
}
441440

442441
@Test
@@ -455,7 +454,7 @@ public void testListPushNotificationConfigs() {
455454
RestHandler.HTTPRestResponse response = handler.listTaskPushNotificationConfigurations(callContext, "", MINIMAL_TASK.id(), 0, "");
456455

457456
Assertions.assertEquals(200, response.getStatusCode());
458-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
457+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
459458
Assertions.assertNotNull(response.getBody());
460459
}
461460

@@ -784,7 +783,7 @@ public void testRequiredExtensionProvidedSuccess() {
784783

785784
// Should succeed without error
786785
Assertions.assertEquals(200, response.getStatusCode());
787-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
786+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
788787
Assertions.assertNotNull(response.getBody());
789788
}
790789

@@ -985,7 +984,7 @@ public void testCompatibleVersionSuccess() {
985984

986985
// Should succeed without error
987986
Assertions.assertEquals(200, response.getStatusCode());
988-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
987+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
989988
Assertions.assertNotNull(response.getBody());
990989
}
991990

@@ -1071,7 +1070,7 @@ public void testListTasksProtobufEnumStatus() {
10711070
null, null, null);
10721071

10731072
Assertions.assertEquals(200, response.getStatusCode());
1074-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
1073+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
10751074
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
10761075
}
10771076

@@ -1085,7 +1084,7 @@ public void testListTasksEnumConstantStatus() {
10851084
null, null, null);
10861085

10871086
Assertions.assertEquals(200, response.getStatusCode());
1088-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
1087+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
10891088
Assertions.assertTrue(response.getBody().contains(MINIMAL_TASK.id()));
10901089
}
10911090

@@ -1098,7 +1097,7 @@ public void testListTasksEmptyResultIncludesAllFields() {
10981097
null, null, null);
10991098

11001099
Assertions.assertEquals(200, response.getStatusCode());
1101-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
1100+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
11021101

11031102
String body = response.getBody();
11041103
// Verify all required fields are present (not missing)
@@ -1122,7 +1121,7 @@ void constructorDoesNotResolveAgentCardInstances() {
11221121
private static void assertProblemDetail(RestHandler.HTTPRestResponse response,
11231122
int expectedStatus, String expectedReason, String expectedMessage) {
11241123
Assertions.assertEquals(expectedStatus, response.getStatusCode());
1125-
Assertions.assertEquals(APPLICATION_A2A_JSON, response.getContentType());
1124+
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
11261125
JsonObject body = JsonParser.parseString(response.getBody()).getAsJsonObject();
11271126
Assertions.assertTrue(body.has("error"), "error wrapper should be present");
11281127
JsonObject error = body.getAsJsonObject("error");
@@ -1265,7 +1264,6 @@ public void testExtendedAgentCardWithRouterKnownTenant() {
12651264
RestHandler.HTTPRestResponse response = handler.getExtendedAgentCard(callContext, "acme");
12661265

12671266
Assertions.assertEquals(200, response.getStatusCode());
1268-
// The agent card is discovery over plain HTTP, not an A2A protocol response.
12691267
Assertions.assertEquals(APPLICATION_JSON, response.getContentType());
12701268
Assertions.assertTrue(response.getBody().contains("acme-card"));
12711269
}

0 commit comments

Comments
 (0)