Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A2aproject A2a java DefaultRequestHandler

From Leeroopedia
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:

  1. Message validation and parsing
  2. Task creation or retrieval from `TaskStore`
  3. Event queue creation via `QueueManager`
  4. Asynchronous execution of `AgentExecutor.execute()` in a background thread pool
  5. 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

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment