Skip to content

Commit d7227f7

Browse files
kabirehsavoie
andauthored
fix: Add Javadoc for rest transport server-side components (a2aproject#678)
Fixes: a2aproject#480 --------- Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com> Co-authored-by: Emmanuel Hugonnet <ehugonne@redhat.com>
1 parent ad22286 commit d7227f7

8 files changed

Lines changed: 940 additions & 14 deletions

File tree

reference/rest/src/main/java/io/a2a/server/rest/quarkus/A2AServerRoutes.java

Lines changed: 365 additions & 12 deletions
Large diffs are not rendered by default.

reference/rest/src/main/java/io/a2a/server/rest/quarkus/CallContextFactory.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,61 @@
33
import io.a2a.server.ServerCallContext;
44
import io.vertx.ext.web.RoutingContext;
55

6+
/**
7+
* Factory interface for creating {@link ServerCallContext} from Vert.x routing context.
8+
*
9+
* <p>This interface provides an extension point for customizing how {@link ServerCallContext}
10+
* instances are created in Quarkus REST applications. The default implementation in
11+
* {@link A2AServerRoutes} extracts standard information (user, headers, tenant, protocol version),
12+
* but applications can provide their own implementation to add custom context data.
13+
*
14+
* <h2>Default Behavior</h2>
15+
* <p>When no CDI bean implementing this interface is provided, {@link A2AServerRoutes}
16+
* creates contexts with:
17+
* <ul>
18+
* <li>User authentication from Quarkus Security</li>
19+
* <li>HTTP headers map</li>
20+
* <li>Tenant ID from URL path</li>
21+
* <li>A2A protocol version from {@code X-A2A-Version} header</li>
22+
* <li>Required extensions from {@code X-A2A-Extensions} header</li>
23+
* </ul>
24+
*
25+
* <h2>Custom Implementation Example</h2>
26+
* <pre>{@code
27+
* @ApplicationScoped
28+
* public class CustomCallContextFactory implements CallContextFactory {
29+
* @Override
30+
* public ServerCallContext build(RoutingContext rc) {
31+
* // Extract custom data from routing context
32+
* String orgId = rc.request().getHeader("X-Organization-ID");
33+
*
34+
* Map<String, Object> state = new HashMap<>();
35+
* state.put("organization", orgId);
36+
* state.put("requestId", UUID.randomUUID().toString());
37+
*
38+
* return new ServerCallContext(
39+
* extractUser(rc),
40+
* state,
41+
* extractExtensions(rc),
42+
* extractVersion(rc)
43+
* );
44+
* }
45+
* }
46+
* }</pre>
47+
*
48+
* @see ServerCallContext
49+
* @see A2AServerRoutes#createCallContext(RoutingContext, String)
50+
*/
651
public interface CallContextFactory {
52+
/**
53+
* Builds a {@link ServerCallContext} from a Vert.x routing context.
54+
*
55+
* <p>This method is called for each incoming HTTP request to create the context
56+
* that will be passed to the {@link io.a2a.server.requesthandlers.RequestHandler}
57+
* and eventually to the {@link io.a2a.server.agentexecution.AgentExecutor}.
58+
*
59+
* @param rc the Vert.x routing context containing request data
60+
* @return a new ServerCallContext with extracted authentication, headers, and metadata
61+
*/
762
ServerCallContext build(RoutingContext rc);
863
}

reference/rest/src/main/java/io/a2a/server/rest/quarkus/QuarkusRestTransportMetadata.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,30 @@
33
import io.a2a.server.TransportMetadata;
44
import io.a2a.spec.TransportProtocol;
55

6+
/**
7+
* Transport metadata implementation for Quarkus REST.
8+
*
9+
* <p>This class provides transport protocol identification for the Quarkus REST
10+
* reference implementation. It reports {@link TransportProtocol#HTTP_JSON} as
11+
* the transport protocol, indicating that this implementation uses HTTP with
12+
* JSON payloads for the A2A protocol.
13+
*
14+
* <p>The transport metadata is used by the framework for:
15+
* <ul>
16+
* <li>Logging and monitoring (identifying which transport handled a request)</li>
17+
* <li>Protocol negotiation and version compatibility checks</li>
18+
* <li>Metrics and telemetry (transport-specific performance tracking)</li>
19+
* </ul>
20+
*
21+
* @see TransportMetadata
22+
* @see TransportProtocol
23+
*/
624
public class QuarkusRestTransportMetadata implements TransportMetadata {
25+
/**
26+
* Returns the transport protocol identifier.
27+
*
28+
* @return {@code "http+json"} indicating HTTP transport with JSON encoding
29+
*/
730
@Override
831
public String getTransportProtocol() {
932
return TransportProtocol.HTTP_JSON.asString();

reference/rest/src/main/java/io/a2a/server/rest/quarkus/package-info.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,65 @@
1+
/**
2+
* Quarkus REST reference implementation for the A2A protocol.
3+
*
4+
* <p>This package provides a ready-to-use Quarkus-based REST transport implementation
5+
* that maps HTTP endpoints to A2A protocol operations. It serves as both a reference
6+
* implementation and a production-ready solution for deploying A2A agents over HTTP/REST.
7+
*
8+
* <h2>Key Components</h2>
9+
* <ul>
10+
* <li>{@link A2AServerRoutes} - Vert.x route definitions mapping HTTP paths to A2A operations</li>
11+
* <li>{@link CallContextFactory} - Extensible factory for creating {@link io.a2a.server.ServerCallContext}</li>
12+
* <li>{@link QuarkusRestTransportMetadata} - Transport protocol metadata implementation</li>
13+
* </ul>
14+
*
15+
* <h2>Architecture</h2>
16+
* <pre>
17+
* HTTP Request (Quarkus/Vert.x)
18+
* ↓
19+
* A2AServerRoutes (@Route methods)
20+
* ↓
21+
* RestHandler (transport/rest)
22+
* ↓
23+
* RequestHandler (server-common)
24+
* ↓
25+
* AgentExecutor (user implementation)
26+
* </pre>
27+
*
28+
* <h2>Supported Endpoints</h2>
29+
* <ul>
30+
* <li>{@code POST /message:send} - Send message (blocking)</li>
31+
* <li>{@code POST /message:stream} - Send message (streaming SSE)</li>
32+
* <li>{@code GET /tasks} - List tasks</li>
33+
* <li>{@code GET /tasks/{taskId}} - Get task by ID</li>
34+
* <li>{@code POST /tasks/{taskId}:cancel} - Cancel task</li>
35+
* <li>{@code POST /tasks/{taskId}:subscribe} - Subscribe to task updates (SSE)</li>
36+
* <li>{@code GET /.well-known/agent-card.json} - Get agent card</li>
37+
* </ul>
38+
*
39+
* <h2>Multi-tenancy Support</h2>
40+
* <p>All endpoints support optional tenant prefixes in the URL path:
41+
* <ul>
42+
* <li>{@code /message:send} - Default tenant (empty string)</li>
43+
* <li>{@code /tenant-123/message:send} - Tenant "tenant-123"</li>
44+
* </ul>
45+
*
46+
* <h2>Usage</h2>
47+
* <p>Add this module as a dependency to your Quarkus project:
48+
* <pre>{@code
49+
* <dependency>
50+
* <groupId>io.github.a2asdk</groupId>
51+
* <artifactId>a2a-java-sdk-reference-rest</artifactId>
52+
* <version>${a2a.version}</version>
53+
* </dependency>
54+
* }</pre>
55+
*
56+
* <p>Provide CDI beans for {@link io.a2a.spec.AgentCard} and
57+
* {@link io.a2a.server.agentexecution.AgentExecutor}, and the REST endpoints
58+
* will be automatically registered.
59+
*
60+
* @see io.a2a.transport.rest.handler
61+
* @see io.a2a.server.requesthandlers
62+
*/
163
@NullMarked
264
package io.a2a.server.rest.quarkus;
365

transport/rest/src/main/java/io/a2a/transport/rest/context/RestContextKeys.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
/**
44
* Shared REST context keys for A2A protocol data.
55
*
6-
* These keys provide access to REST context information,
7-
* enabling rich context access in service method implementations.
6+
* <p>These keys provide access to REST context information stored in
7+
* {@link io.a2a.server.ServerCallContext}, enabling rich context access
8+
* in service method implementations and middleware.
9+
*
10+
* <h2>Usage Example</h2>
11+
* <pre>{@code
12+
* public void processRequest(ServerCallContext context) {
13+
* String tenant = context.get(RestContextKeys.TENANT_KEY);
14+
* String method = context.get(RestContextKeys.METHOD_NAME_KEY);
15+
* Map<String, String> headers = context.get(RestContextKeys.HEADERS_KEY);
16+
* }
17+
* }</pre>
18+
*
19+
* @see io.a2a.server.ServerCallContext
820
*/
921
public final class RestContextKeys {
1022

0 commit comments

Comments
 (0)