Implementation:A2aproject A2a java DefaultRequestHandler
| Knowledge Sources | |
|---|---|
| Domains | Server, Request_Orchestration |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete CDI bean that orchestrates the server-side A2A request lifecycle: receiving messages from transport handlers, creating tasks, executing agent logic, and streaming events back to clients.
Description
`DefaultRequestHandler` is the central server-side orchestrator in the A2A Java SDK. It is a CDI `@ApplicationScoped` bean that receives requests from transport handlers (`JSONRPCHandler`, `GrpcHandler`, `RestHandler`) and coordinates the full request lifecycle:
- Message validation and parsing
- Task creation or retrieval from `TaskStore`
- Event queue creation via `QueueManager`
- Asynchronous execution of `AgentExecutor.execute()` in a background thread pool
- Event delivery to the client transport via `EventConsumer` (reactive stream)
The handler injects `AgentExecutor` (from CDI producer), `AgentCard` (from `@PublicAgentCard` producer), `TaskStore`, `QueueManager`, and `PushNotificationConfigStore`. It provides a `Builder` for configuring these dependencies programmatically (primarily for testing).
The handler manages the complete task state machine, from initial submission through terminal states. It handles authentication, multi-tenancy, and protocol version dispatch (v1.0 / v0.3).
Usage
- Server setup: Automatically wired by CDI — no manual instantiation needed in Quarkus applications
- Testing: Use `DefaultRequestHandler.Builder` to configure dependencies for unit/integration tests
- Transport handlers: All three transport handlers (JSON-RPC, gRPC, REST) delegate to this handler
Code Reference
Source Location
- Repository: a2a-java
- File: `server-common/src/main/java/org/a2aproject/sdk/server/requesthandlers/DefaultRequestHandler.java`
- Lines: L196-1740
Signature
@ApplicationScoped
public class DefaultRequestHandler {
// CDI-injected fields:
// AgentExecutor agentExecutor
// AgentCard agentCard (@PublicAgentCard)
// TaskStore taskStore
// QueueManager queueManager
// PushNotificationConfigStore pushConfigStore
// Builder for programmatic configuration
public static class Builder {
public Builder agentExecutor(AgentExecutor executor);
public Builder taskStore(TaskStore store);
public Builder queueManager(QueueManager manager);
// ... additional configuration
public DefaultRequestHandler build();
}
}
Import
import org.a2aproject.sdk.server.requesthandlers.DefaultRequestHandler;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| agentExecutor | AgentExecutor | Yes | Business logic (CDI-injected from producer) |
| agentCard | AgentCard | Yes | Agent capability manifest (@PublicAgentCard) |
| taskStore | TaskStore | Yes | Task persistence (InMemory or JPA) |
| queueManager | QueueManager | Yes | Event queue lifecycle management |
| pushConfigStore | PushNotificationConfigStore | Yes | Push notification config persistence |
Outputs
| Name | Type | Description |
|---|---|---|
| Event streams | EventConsumer → ZeroPublisher | Reactive streams delivered to transport handlers |
| Task state | Task | Persisted in TaskStore, updated through state machine |
| HTTP/SSE responses | via transport handlers | JSON-RPC, gRPC, or REST responses to clients |
Usage Examples
Automatic CDI Wiring (Quarkus)
// In a Quarkus application, DefaultRequestHandler is automatically
// discovered as an @ApplicationScoped bean. Transport handlers inject it:
// JSONRPCHandler injects it:
// @Inject DefaultRequestHandler requestHandler;
// No manual configuration needed — just provide the producers:
@ApplicationScoped
public class AgentExecutorProducer {
@Produces
public AgentExecutor agentExecutor() {
return new MyAgentExecutor();
}
}
Builder for Testing
DefaultRequestHandler handler = DefaultRequestHandler.Builder()
.agentExecutor(myExecutor)
.taskStore(new InMemoryTaskStore())
.queueManager(new InMemoryQueueManager())
.build();
Related Pages
Implements Principle
- Principle:A2aproject_A2a_java_Agent_Executor_Pattern
- Principle:A2aproject_A2a_java_Cloud_Agent_Scaling