Class A2AExtensionsInterceptor

java.lang.Object
org.a2aproject.sdk.server.grpc.quarkus.A2AExtensionsInterceptor
All Implemented Interfaces:
io.grpc.ServerInterceptor

@ApplicationScoped public class A2AExtensionsInterceptor extends Object implements io.grpc.ServerInterceptor
gRPC server interceptor that captures request metadata and context information, providing equivalent functionality to Python's grpc.aio.ServicerContext.

This interceptor executes before service methods are invoked, extracting A2A protocol headers and request metadata from the gRPC call and storing them in the gRPC Context for access by GrpcHandler and agent implementations.

Captured Information

  • A2A Protocol Version: a2a-version header
  • A2A Extensions: a2a-extensions header
  • Complete Metadata: All request headers via Metadata
  • Method Name: gRPC method being invoked
  • Peer Information: Client connection details

Context Storage

All captured information is stored in the gRPC Context using keys from GrpcContextKeys:

CDI Integration

This interceptor is registered as an @ApplicationScoped CDI bean and automatically applied to gRPC services through Quarkus gRPC's @RegisterInterceptor annotation.

Python Equivalence

This interceptor provides functionality equivalent to Python's grpc.aio.ServicerContext, enabling Java handlers to access the same rich context information available in Python implementations:

  • context.invocation_metadata() → Metadata
  • context.method() → Method name via GRPC_METHOD_NAME_KEY
  • context.peer() → Peer info via PEER_INFO_KEY
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <ReqT,RespT>
    io.grpc.ServerCall.Listener<ReqT>
    interceptCall(io.grpc.ServerCall<ReqT,RespT> serverCall, io.grpc.Metadata metadata, io.grpc.ServerCallHandler<ReqT,RespT> serverCallHandler)
    Intercepts incoming gRPC calls to capture metadata and context information.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • A2AExtensionsInterceptor

      public A2AExtensionsInterceptor()
  • Method Details

    • interceptCall

      public <ReqT,RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(io.grpc.ServerCall<ReqT,RespT> serverCall, io.grpc.Metadata metadata, io.grpc.ServerCallHandler<ReqT,RespT> serverCallHandler)
      Intercepts incoming gRPC calls to capture metadata and context information.

      This method extracts A2A protocol headers and request metadata, stores them in the gRPC Context, and proceeds with the call in the enhanced context.

      Extraction Process:

      1. Extract a2a-version header from metadata
      2. Extract a2a-extensions header from metadata
      3. Capture complete Metadata object
      4. Capture gRPC method name from ServerCall
      5. Map gRPC method to A2A protocol method name
      6. Extract peer information from server call attributes
      7. Create enhanced Context with all captured information
      8. Proceed with call in enhanced context
      Specified by:
      interceptCall in interface io.grpc.ServerInterceptor
      Type Parameters:
      ReqT - the request message type
      RespT - the response message type
      Parameters:
      serverCall - the gRPC server call
      metadata - the request metadata (headers)
      serverCallHandler - the next handler in the interceptor chain
      Returns:
      a listener for the server call