Skip to content

Commit cd1eaf6

Browse files
committed
Fixing streaming tests with http client
Signed-off-by: Emmanuel Hugonnet <[email protected]>
1 parent 660ca7d commit cd1eaf6

File tree

7 files changed

+135
-179
lines changed

7 files changed

+135
-179
lines changed

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JSONRPCTransportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public void testA2AClientGetTaskPushNotificationConfig() throws Exception {
310310

311311
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
312312
TaskPushNotificationConfig taskPushNotificationConfig = client.getTaskPushNotificationConfiguration(
313-
new GetTaskPushNotificationConfigParams("de38c76d-d54c-436c-8b9f-4c2703648d64", null,
313+
new GetTaskPushNotificationConfigParams("de38c76d-d54c-436c-8b9f-4c2703648d64", "c295ea44-7543-4f78-b524-7a38915ad6e4",
314314
new HashMap<>()), null);
315315
PushNotificationConfig pushNotificationConfig = taskPushNotificationConfig.pushNotificationConfig();
316316
assertNotNull(pushNotificationConfig);

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JsonMessages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,15 @@ public class JsonMessages {
391391
"jsonrpc":"2.0",
392392
"method":"GetTaskPushNotificationConfig",
393393
"params":{
394-
"name":"tasks/de38c76d-d54c-436c-8b9f-4c2703648d64"
394+
"name":"tasks/de38c76d-d54c-436c-8b9f-4c2703648d64/pushNotificationConfigs/c295ea44-7543-4f78-b524-7a38915ad6e4"
395395
}
396396
}""";
397397

398398
static final String GET_TASK_PUSH_NOTIFICATION_CONFIG_TEST_RESPONSE = """
399399
{
400400
"jsonrpc": "2.0",
401401
"result": {
402-
"name": "tasks/de38c76d-d54c-436c-8b9f-4c2703648d64/pushNotificationConfigs/10",
402+
"name": "tasks/de38c76d-d54c-436c-8b9f-4c2703648d64/pushNotificationConfigs/c295ea44-7543-4f78-b524-7a38915ad6e4",
403403
"pushNotificationConfig": {
404404
"url": "https://example.com/callback",
405405
"authentication": {

reference/jsonrpc/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import io.a2a.spec.SubscribeToTaskRequest;
6868
import io.a2a.spec.UnsupportedOperationError;
6969
import io.a2a.transport.jsonrpc.handler.JSONRPCHandler;
70-
import io.a2a.util.Utils;
7170
import io.quarkus.security.Authenticated;
7271
import io.quarkus.vertx.web.Body;
7372
import io.quarkus.vertx.web.ReactiveRoutes;
@@ -275,17 +274,12 @@ private static String serializeResponse(JSONRPCResponse<?> response) {
275274
if (response instanceof JSONRPCErrorResponse error) {
276275
return JSONRPCUtils.toJsonRPCErrorResponse(error.getId(), error.getError());
277276
}
278-
if(response.getError() != null) {
279-
System.out.println("------------------------------------------------------------");
280-
System.out.println("We have an error " + response.getError());
281-
System.out.println("------------------------------------------------------------");
277+
if (response.getError() != null) {
282278
return JSONRPCUtils.toJsonRPCErrorResponse(response.getId(), response.getError());
283279
}
284-
285280
// Convert domain response to protobuf message and serialize
286281
com.google.protobuf.MessageOrBuilder protoMessage = convertToProto(response);
287-
return JSONRPCUtils.toJsonRPCResultResponse(response.getId(), protoMessage
288-
);
282+
return JSONRPCUtils.toJsonRPCResultResponse(response.getId(), protoMessage);
289283
}
290284

291285
private static com.google.protobuf.MessageOrBuilder convertToProto(JSONRPCResponse<?> response) {
@@ -389,14 +383,12 @@ public Buffer apply(Object o) {
389383
ReactiveRoutes.ServerSentEvent<?> ev = (ReactiveRoutes.ServerSentEvent<?>) o;
390384
long id = ev.id() != -1 ? ev.id() : count.getAndIncrement();
391385
String e = ev.event() == null ? "" : "event: " + ev.event() + "\n";
392-
String data = ev.data() instanceof JSONRPCResponse
393-
? serializeResponse((JSONRPCResponse<?>) ev.data())
394-
: Utils.toJsonString(ev.data());
386+
String data = serializeResponse((JSONRPCResponse<?>) ev.data());
387+
System.out.println("Sending message " + data);
395388
return Buffer.buffer(e + "data: " + data + "\nid: " + id + "\n\n");
396389
}
397-
String data = o instanceof JSONRPCResponse
398-
? serializeResponse((JSONRPCResponse<?>) o)
399-
: Utils.toJsonString(o);
390+
String data = serializeResponse((JSONRPCResponse<?>) o);
391+
System.out.println("Sending message " + data);
400392
return Buffer.buffer("data: " + data + "\nid: " + count.getAndIncrement() + "\n\n");
401393
}
402394
}), rc);

spec-grpc/src/main/java/io/a2a/grpc/utils/JSONRPCUtils.java

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,6 @@ protected static void parseRequestBody(JsonElement jsonRpc, com.google.protobuf.
294294

295295
public static void parseJsonString(String body, com.google.protobuf.Message.Builder builder) throws JSONRPCError {
296296
try {
297-
System.out.println("****************************************");
298-
System.out.println("Converting to " + builder.toString());
299-
System.out.println(body);
300-
System.out.println("****************************************");
301297
JsonFormat.parser().merge(body, builder);
302298
} catch (InvalidProtocolBufferException e) {
303299
log.log(Level.SEVERE, "Error parsing JSON request body: {0}", body);
@@ -350,14 +346,10 @@ public static String toJsonRPCRequest(String requestId, String method, com.googl
350346
if (method != null) {
351347
output.name("method").value(method);
352348
}
353-
String resultValue = JsonFormat.printer().print(builder);
349+
String resultValue = JsonFormat.printer().omittingInsignificantWhitespace().print(builder);
354350
output.name("params").jsonValue(resultValue);
355351
output.endObject();
356-
String jsonPayload = result.toString();
357-
System.out.println("**********************");
358-
System.out.println(jsonPayload);
359-
System.out.println("**********************");
360-
return jsonPayload;
352+
return result.toString();
361353
} catch (IOException ex) {
362354
throw new RuntimeException(ex);
363355
}
@@ -374,7 +366,7 @@ public static String toJsonRPCResultResponse(Object requestId, com.google.protob
374366
output.name("id").value(number);
375367
}
376368
}
377-
String resultValue = JsonFormat.printer().print(builder);
369+
String resultValue = JsonFormat.printer().omittingInsignificantWhitespace().print(builder);
378370
output.name("result").jsonValue(resultValue);
379371
output.endObject();
380372
return result.toString();
@@ -408,40 +400,4 @@ public static String toJsonRPCErrorResponse(Object requestId, JSONRPCError error
408400
throw new RuntimeException(ex);
409401
}
410402
}
411-
412-
/**
413-
*
414-
* public static String toJsonRPCString(String id, com.google.protobuf.Message.Builder builder) {
415-
* try (StringWriter result = new StringWriter()) {
416-
* JsonObjectBuilder json = Json.createObjectBuilder();
417-
* json.add("jsonrpc", "2.0");
418-
* json.add("id", id);
419-
* json.add("result", Json.createObjectBuilder(Json.createParser(new
420-
* StringReader(JsonFormat.printer().print(builder))).getObject()));
421-
* Json.createWriter(result).writeObject(json.build());
422-
* return result.toString();
423-
* } catch (IOException ex) {
424-
* throw new RuntimeException(ex);
425-
* }
426-
* }
427-
*
428-
* public static String toJsonRPCString(String id, JSONRPCError error) {
429-
* try (StringWriter result = new StringWriter()) {
430-
* JsonObjectBuilder errorBuilder = Json.createObjectBuilder();
431-
* errorBuilder.add("code", error.getCode());
432-
* errorBuilder.add("message", error.getMessage());
433-
* if (error.getData() != null) {
434-
* errorBuilder.add("data", error.getData().toString());
435-
* }
436-
* JsonObjectBuilder json = Json.createObjectBuilder();
437-
* json.add("jsonrpc", "2.0");
438-
* json.add("id", id);
439-
* json.add("error", errorBuilder);
440-
* Json.createWriter(result).writeObject(json.build());
441-
* return result.toString();
442-
* } catch (IOException ex) {
443-
* throw new RuntimeException(ex);
444-
* }
445-
* }
446-
*/
447403
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ public record TaskPushNotificationConfig(String taskId, PushNotificationConfig p
2828
public TaskPushNotificationConfig {
2929
Assert.checkNotNullParam("taskId", taskId);
3030
Assert.checkNotNullParam("pushNotificationConfig", pushNotificationConfig);
31+
Assert.checkNotNullParam("configId", pushNotificationConfig.id());
3132
}
3233
}

0 commit comments

Comments
 (0)