@@ -50,21 +50,19 @@ public class HTTPRestHandler {
50
50
private static final Pattern LIST_PUSH_NOTIFICATION_CONFIG_PATTERN = Pattern .compile ("^/v1/tasks/([^/]+)/pushNotificationConfigs$" );
51
51
private static final Pattern DELETE_PUSH_NOTIFICATION_CONFIG_PATTERN = Pattern .compile ("^/v1/tasks/([^/]+)/pushNotificationConfigs/([^/]+)$" );
52
52
53
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ().registerModule (new JavaTimeModule ());
54
+
53
55
private AgentCard agentCard ;
54
56
private RequestHandler requestHandler ;
55
- private ObjectMapper objectMapper ;
56
57
57
58
protected HTTPRestHandler () {
58
- this .objectMapper = new ObjectMapper ();
59
- this .objectMapper .registerModule (new JavaTimeModule ());
59
+ // For CDI
60
60
}
61
61
62
62
@ Inject
63
63
public HTTPRestHandler (@ PublicAgentCard AgentCard agentCard , RequestHandler requestHandler ) {
64
64
this .agentCard = agentCard ;
65
65
this .requestHandler = requestHandler ;
66
- this .objectMapper = new ObjectMapper ();
67
- this .objectMapper .registerModule (new JavaTimeModule ());
68
66
}
69
67
70
68
public HTTPRestResponse handleRequest (String method , String path , String body , ServerCallContext context ) {
@@ -183,6 +181,9 @@ private HTTPRestResponse handlePostRequest(String path, String body, ServerCallC
183
181
}
184
182
String taskId = listPushConfigMatcher .group (1 );
185
183
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
+ }
186
187
TaskPushNotificationConfig result = requestHandler .onSetTaskPushNotificationConfig (config , context );
187
188
return createSuccessResponse (201 , result );
188
189
}
@@ -215,15 +216,15 @@ private <T> T parseRequestBody(String body, Class<T> valueType) throws JSONRPCEr
215
216
if (body == null || body .trim ().isEmpty ()) {
216
217
throw new InvalidParamsError ("Request body is required" );
217
218
}
218
- return objectMapper .readValue (body , valueType );
219
+ return OBJECT_MAPPER .readValue (body , valueType );
219
220
} catch (Exception e ) {
220
221
throw new InvalidParamsError ("Failed to parse request body: " + e .getMessage ());
221
222
}
222
223
}
223
224
224
225
private HTTPRestResponse createSuccessResponse (int statusCode , Object data ) {
225
226
try {
226
- String jsonBody = data != null ? objectMapper .writeValueAsString (data ) : null ;
227
+ String jsonBody = data != null ? OBJECT_MAPPER .writeValueAsString (data ) : null ;
227
228
return new HTTPRestResponse (statusCode , "application/json" , jsonBody );
228
229
} catch (Exception e ) {
229
230
return createErrorResponse (500 , new InternalError ("Failed to serialize response: " + e .getMessage ()));
@@ -233,7 +234,7 @@ private HTTPRestResponse createSuccessResponse(int statusCode, Object data) {
233
234
private HTTPRestResponse createErrorResponse (int statusCode , JSONRPCError error ) {
234
235
try {
235
236
HTTPRestErrorResponse errorResponse = new HTTPRestErrorResponse (error .getClass ().getSimpleName (), error .getMessage ());
236
- String jsonBody = objectMapper .writeValueAsString (errorResponse );
237
+ String jsonBody = OBJECT_MAPPER .writeValueAsString (errorResponse );
237
238
return new HTTPRestResponse (statusCode , "application/json" , jsonBody );
238
239
} catch (Exception e ) {
239
240
String fallbackJson = "{\" error\" :\" InternalError\" ,\" message\" :\" Failed to serialize error response\" }" ;
@@ -313,4 +314,4 @@ public HTTPRestErrorResponse(String error, String message) {
313
314
public String getError () { return error ; }
314
315
public String getMessage () { return message ; }
315
316
}
316
- }
317
+ }
0 commit comments