@@ -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+ }
0 commit comments