33import static io .a2a .grpc .utils .ProtoUtils .FromProto ;
44import static io .a2a .grpc .utils .ProtoUtils .ToProto ;
55
6- import jakarta .enterprise .context .ApplicationScoped ;
7- import jakarta .enterprise .inject .Instance ;
8- import jakarta .inject .Inject ;
9-
6+ import java .util .HashMap ;
107import java .util .List ;
8+ import java .util .Map ;
119import java .util .concurrent .CompletableFuture ;
1210import java .util .concurrent .Flow ;
1311
12+ import jakarta .inject .Inject ;
13+
1414import com .google .protobuf .Empty ;
1515import io .a2a .grpc .A2AServiceGrpc ;
1616import io .a2a .grpc .StreamResponse ;
17- import io .a2a .server .PublicAgentCard ;
1817import io .a2a .server .ServerCallContext ;
1918import io .a2a .server .auth .UnauthenticatedUser ;
2019import io .a2a .server .auth .User ;
4645import io .grpc .Status ;
4746import io .grpc .stub .StreamObserver ;
4847
49- import java .util .HashMap ;
50- import java .util .Map ;
51-
52- @ ApplicationScoped
5348public class GrpcHandler extends A2AServiceGrpc .A2AServiceImplBase {
5449
5550 private AgentCard agentCard ;
@@ -59,14 +54,11 @@ public class GrpcHandler extends A2AServiceGrpc.A2AServiceImplBase {
5954 // Without this we get intermittent failures
6055 private static volatile Runnable streamingSubscribedRunnable ;
6156
62- @ Inject
63- Instance <CallContextFactory > callContextFactory ;
64-
6557 protected GrpcHandler () {
6658 }
6759
6860 @ Inject
69- public GrpcHandler (@ PublicAgentCard AgentCard agentCard , RequestHandler requestHandler ) {
61+ public GrpcHandler (AgentCard agentCard , RequestHandler requestHandler ) {
7062 this .agentCard = agentCard ;
7163 this .requestHandler = requestHandler ;
7264 }
@@ -317,7 +309,8 @@ public void deleteTaskPushNotificationConfig(io.a2a.grpc.DeleteTaskPushNotificat
317309 }
318310
319311 private <V > ServerCallContext createCallContext (StreamObserver <V > responseObserver ) {
320- if (callContextFactory == null || callContextFactory .isUnsatisfied ()) {
312+ CallContextFactory callContextFactory = getCallContextFactory ();
313+ if (callContextFactory == null ) {
321314 // Default implementation when no custom CallContextFactory is provided
322315 // This handles both CDI injection scenarios and test scenarios where callContextFactory is null
323316 User user = UnauthenticatedUser .INSTANCE ;
@@ -335,10 +328,9 @@ private <V> ServerCallContext createCallContext(StreamObserver<V> responseObserv
335328
336329 return new ServerCallContext (user , state );
337330 } else {
338- CallContextFactory factory = callContextFactory .get ();
339331 // TODO: CallContextFactory interface expects ServerCall + Metadata, but we only have StreamObserver
340332 // This is another manifestation of the architectural limitation mentioned above
341- return factory .create (responseObserver ); // Fall back to basic create() method for now
333+ return callContextFactory .create (responseObserver ); // Fall back to basic create() method for now
342334 }
343335 }
344336
@@ -393,4 +385,7 @@ public static void setStreamingSubscribedRunnable(Runnable runnable) {
393385 streamingSubscribedRunnable = runnable ;
394386 }
395387
388+ protected CallContextFactory getCallContextFactory () {
389+ return null ;
390+ }
396391}
0 commit comments