Interface CallContextFactory
- All Known Implementing Classes:
QuarkusCallContextFactory
public interface CallContextFactory
Factory interface for creating
ServerCallContext from gRPC request context.
This interface provides an extension point for customizing how ServerCallContext
instances are created in gRPC applications. The default implementation in GrpcHandler
extracts standard information (user, metadata, headers, peer info, protocol version), but
applications can provide their own implementation to add custom context data.
Default Behavior
When no CDI bean implementing this interface is provided, GrpcHandler
creates contexts with:
- User authentication from security context
- gRPC metadata (headers)
- Method name and peer information
- A2A protocol version from
A2A-Versionheader - Required extensions from
A2A-Extensionsheader - Response observer for gRPC streaming
Custom Implementation Example
@ApplicationScoped
public class CustomCallContextFactory implements CallContextFactory {
@Override
public <V> ServerCallContext create(StreamObserver<V> responseObserver) {
// Extract custom data from gRPC context
Context grpcContext = Context.current();
Metadata metadata = GrpcContextKeys.METADATA_KEY.get(grpcContext);
String orgId = metadata.get(
Metadata.Key.of("x-organization-id", Metadata.ASCII_STRING_MARSHALLER)
);
Map<String, Object> state = new HashMap<>();
state.put("organization", orgId);
state.put("grpc_response_observer", responseObserver);
return new ServerCallContext(
extractUser(),
state,
extractExtensions(grpcContext),
extractVersion(grpcContext)
);
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreate(io.grpc.stub.StreamObserver<V> responseObserver) Creates aServerCallContextfrom gRPC request context.
-
Method Details
-
create
Creates aServerCallContextfrom gRPC request context.This method is called for each incoming gRPC request to create the context that will be passed to the
RequestHandlerand eventually to theAgentExecutor.Implementations should extract information from the current
ContextusingGrpcContextKeysto access metadata, method name, peer info, and A2A protocol headers.- Type Parameters:
V- the response type for the gRPC method- Parameters:
responseObserver- the gRPC response stream observer- Returns:
- a new ServerCallContext with extracted authentication, metadata, and headers
-