Skip to content

Commit 10d7b86

Browse files
ronantakizawaehsavoie
authored andcommitted
fix: implement gemini suggestions
1 parent 514d890 commit 10d7b86

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public Task onGetTask(TaskQueryParams params, ServerCallContext context) throws
117117

118118
@Override
119119
public List<Task> onListTasks(TaskListParams params, ServerCallContext context) throws JSONRPCError {
120-
LOGGER.debug("onListTasks");
120+
LOGGER.debug("onListTasks with params: {}", params);
121121
return taskStore.listAll();
122122
}
123123

spec/src/main/java/io/a2a/spec/TaskListParams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public record TaskListParams(Map<String, Object> metadata) {
1515
public TaskListParams() {
1616
this(null);
1717
}
18-
}
18+
}

transport/httprest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@
5050
</dependency>
5151

5252
</dependencies>
53-
53+
5454
</project>

transport/httprest/src/main/java/io/a2a/httprest/handler/HTTPRestHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@ public class HTTPRestHandler {
5050
private static final Pattern LIST_PUSH_NOTIFICATION_CONFIG_PATTERN = Pattern.compile("^/v1/tasks/([^/]+)/pushNotificationConfigs$");
5151
private static final Pattern DELETE_PUSH_NOTIFICATION_CONFIG_PATTERN = Pattern.compile("^/v1/tasks/([^/]+)/pushNotificationConfigs/([^/]+)$");
5252

53+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().registerModule(new JavaTimeModule());
54+
5355
private AgentCard agentCard;
5456
private RequestHandler requestHandler;
55-
private ObjectMapper objectMapper;
5657

5758
protected HTTPRestHandler() {
58-
this.objectMapper = new ObjectMapper();
59-
this.objectMapper.registerModule(new JavaTimeModule());
59+
// For CDI
6060
}
6161

6262
@Inject
6363
public HTTPRestHandler(@PublicAgentCard AgentCard agentCard, RequestHandler requestHandler) {
6464
this.agentCard = agentCard;
6565
this.requestHandler = requestHandler;
66-
this.objectMapper = new ObjectMapper();
67-
this.objectMapper.registerModule(new JavaTimeModule());
6866
}
6967

7068
public HTTPRestResponse handleRequest(String method, String path, String body, ServerCallContext context) {
@@ -183,6 +181,9 @@ private HTTPRestResponse handlePostRequest(String path, String body, ServerCallC
183181
}
184182
String taskId = listPushConfigMatcher.group(1);
185183
TaskPushNotificationConfig config = parseRequestBody(body, TaskPushNotificationConfig.class);
184+
if (!taskId.equals(config.taskId())) {
185+
throw new InvalidParamsError("Task ID in URL path does not match task ID in request body.");
186+
}
186187
TaskPushNotificationConfig result = requestHandler.onSetTaskPushNotificationConfig(config, context);
187188
return createSuccessResponse(201, result);
188189
}
@@ -215,15 +216,15 @@ private <T> T parseRequestBody(String body, Class<T> valueType) throws JSONRPCEr
215216
if (body == null || body.trim().isEmpty()) {
216217
throw new InvalidParamsError("Request body is required");
217218
}
218-
return objectMapper.readValue(body, valueType);
219+
return OBJECT_MAPPER.readValue(body, valueType);
219220
} catch (Exception e) {
220221
throw new InvalidParamsError("Failed to parse request body: " + e.getMessage());
221222
}
222223
}
223224

224225
private HTTPRestResponse createSuccessResponse(int statusCode, Object data) {
225226
try {
226-
String jsonBody = data != null ? objectMapper.writeValueAsString(data) : null;
227+
String jsonBody = data != null ? OBJECT_MAPPER.writeValueAsString(data) : null;
227228
return new HTTPRestResponse(statusCode, "application/json", jsonBody);
228229
} catch (Exception e) {
229230
return createErrorResponse(500, new InternalError("Failed to serialize response: " + e.getMessage()));
@@ -233,7 +234,7 @@ private HTTPRestResponse createSuccessResponse(int statusCode, Object data) {
233234
private HTTPRestResponse createErrorResponse(int statusCode, JSONRPCError error) {
234235
try {
235236
HTTPRestErrorResponse errorResponse = new HTTPRestErrorResponse(error.getClass().getSimpleName(), error.getMessage());
236-
String jsonBody = objectMapper.writeValueAsString(errorResponse);
237+
String jsonBody = OBJECT_MAPPER.writeValueAsString(errorResponse);
237238
return new HTTPRestResponse(statusCode, "application/json", jsonBody);
238239
} catch (Exception e) {
239240
String fallbackJson = "{\"error\":\"InternalError\",\"message\":\"Failed to serialize error response\"}";
@@ -313,4 +314,4 @@ public HTTPRestErrorResponse(String error, String message) {
313314
public String getError() { return error; }
314315
public String getMessage() { return message; }
315316
}
316-
}
317+
}

transport/httprest/src/main/resources/META-INF/beans.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
55
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
66
bean-discovery-mode="all">
7-
</beans>
7+
</beans>

transport/httprest/src/test/java/io/a2a/httprest/handler/HTTPRestHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,4 @@ public void testHttpStatusCodeMapping() {
328328
response = handler.handleRequest("PATCH", "/v1/card", null, callContext);
329329
Assertions.assertEquals(405, response.getStatusCode());
330330
}
331-
}
331+
}

0 commit comments

Comments
 (0)