Class A2AServerRoutes
This class defines Vert.x Web routes for handling JSON-RPC 2.0 requests over HTTP,
processing them through the JSONRPCHandler, and returning responses in either
standard JSON or Server-Sent Events (SSE) format for streaming operations.
Request Flow
HTTP POST / → invokeJSONRPCHandler()
↓
Parse JSON-RPC request body
↓
Route to handler method (blocking or streaming)
↓
JSONRPCHandler → RequestHandler → AgentExecutor
↓
Response (JSON or SSE stream)
Supported Operations
Non-Streaming (JSON responses):
sendMessage- Send message and wait for completiongetTask- Retrieve task by IDcancelTask- Cancel task executionlistTasks- List tasks with filteringsetTaskPushNotificationConfig- Configure push notificationsgetTaskPushNotificationConfig- Get push notification configlistTaskPushNotificationConfigs- List push notification configsdeleteTaskPushNotificationConfig- Delete push notification configgetExtendedAgentCard- Get extended agent capabilities
Streaming (SSE responses):
sendStreamingMessage- Send message with streaming responsesubscribeToTask- Subscribe to task events
JSON-RPC Request Format
POST /
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": "req-123",
"method": "sendMessage",
"params": {
"message": {
"parts": [{"text": "Hello"}]
}
}
}
Error Handling
Errors are mapped to JSON-RPC 2.0 error responses:
JsonSyntaxException→JSONParseErrorInvalidParamsJsonMappingException→InvalidParamsErrorMethodNotFoundJsonMappingException→MethodNotFoundErrorIdJsonMappingException→InvalidRequestErrorThrowable→InternalError
CDI Integration
This class is a CDI @Singleton that automatically wires:
JSONRPCHandler- Core protocol handlerExecutor- Async execution for streamingCallContextFactory(optional) - Custom context creation
Multi-Tenancy Support
Tenant identification is extracted from the request path:
POST /→ empty tenantPOST /tenant1→ tenant "tenant1"POST /tenant1/→ tenant "tenant1" (trailing slash stripped)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetAgentCard(io.vertx.ext.web.RoutingContext rc) Handles GET requests to the agent card endpoint.voidinvokeJSONRPCHandler(String body, io.vertx.ext.web.RoutingContext rc) Main entry point for all JSON-RPC requests.static voidSets a callback to be invoked when SSE streaming subscription starts.
-
Constructor Details
-
A2AServerRoutes
public A2AServerRoutes()
-
-
Method Details
-
invokeJSONRPCHandler
Main entry point for all JSON-RPC requests.This route handler processes JSON-RPC 2.0 requests, dispatches them to the appropriate handler method based on the request type (streaming vs non-streaming), and returns either a JSON response or an SSE stream.
Request Format:
POST /[tenant] Content-Type: application/json { "jsonrpc": "2.0", "id": "req-123", "method": "sendMessage", "params": { ... } }Non-Streaming Response:
HTTP/1.1 200 OK Content-Type: application/json { "jsonrpc": "2.0", "id": "req-123", "result": { ... } }Streaming Response (SSE):
HTTP/1.1 200 OK Content-Type: text/event-stream id: 0 data: {"jsonrpc":"2.0","id":"req-123","result":{...}} id: 1 data: {"jsonrpc":"2.0","id":"req-123","result":{...}}Error Response:
HTTP/1.1 200 OK Content-Type: application/json { "jsonrpc": "2.0", "id": "req-123", "error": { "code": -32602, "message": "Invalid params" } }Processing Flow:
- Parse JSON-RPC request body using
JSONRPCUtils.parseRequestBody(String, String) - Create
ServerCallContextfrom routing context - Route to streaming or non-streaming handler
- Handle errors with appropriate JSON-RPC error codes
- Return JSON response or start SSE stream
- Parameters:
body- the raw JSON-RPC request bodyrc- the Vert.x routing context containing HTTP request/response- Throws:
A2AError- if request processing fails
- Parse JSON-RPC request body using
-
getAgentCard
Handles GET requests to the agent card endpoint.Returns the agent's capabilities and metadata in JSON format according to the A2A protocol specification. This endpoint is publicly accessible (no authentication).
Includes HTTP caching headers per A2A specification section 8.6:
Cache-Control- with max-age directiveETag- content hash for validationLast-Modified- timestamp when agent card was initialized
Request:
GET /.well-known/agent-card.jsonResponse:
HTTP/1.1 200 OK Content-Type: application/json Cache-Control: public, max-age=3600 ETag: "a1b2c3d4..." Last-Modified: Mon, 17 Mar 2025 10:00:00 GMT { "name": "My Agent", "description": "Agent description", "capabilities": { "streaming": true, "pushNotifications": false }, ... }- Parameters:
rc- the Vert.x routing context- Returns:
- the agent card as a JSON string
- Throws:
JsonProcessingException- if serialization fails- See Also:
-
setStreamingMultiSseSupportSubscribedRunnable
Sets a callback to be invoked when SSE streaming subscription starts.This is a testing hook used to synchronize test execution with streaming setup. In production, this remains null.
- Parameters:
runnable- the callback to invoke on subscription
-