Skip to content

Commit 03a806d

Browse files
committed
Don't use annotations in the GrpcHandler
1 parent 5e373ce commit 03a806d

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
package io.a2a.server.grpc.quarkus;
22

3+
import jakarta.enterprise.inject.Instance;
34
import jakarta.inject.Inject;
45

56
import io.a2a.server.PublicAgentCard;
67
import io.a2a.grpc.handler.GrpcHandler;
8+
import io.a2a.server.requesthandlers.CallContextFactory;
79
import io.a2a.server.requesthandlers.RequestHandler;
810
import io.a2a.spec.AgentCard;
911
import io.quarkus.grpc.GrpcService;
1012

1113
@GrpcService
1214
public class QuarkusGrpcHandler extends GrpcHandler {
1315

16+
@Inject
17+
Instance<CallContextFactory> callContextFactory;
18+
1419
@Inject
1520
public QuarkusGrpcHandler(@PublicAgentCard AgentCard agentCard, RequestHandler requestHandler) {
1621
super(agentCard, requestHandler);
1722
}
23+
24+
@Override
25+
protected CallContextFactory getCallContextFactory() {
26+
if (callContextFactory != null && !callContextFactory.isUnsatisfied()) {
27+
return callContextFactory.get();
28+
}
29+
return null;
30+
}
1831
}

transport/grpc/src/main/java/io/a2a/grpc/handler/GrpcHandler.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
import static io.a2a.grpc.utils.ProtoUtils.FromProto;
44
import 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;
107
import java.util.List;
8+
import java.util.Map;
119
import java.util.concurrent.CompletableFuture;
1210
import java.util.concurrent.Flow;
1311

12+
import jakarta.inject.Inject;
13+
1414
import com.google.protobuf.Empty;
1515
import io.a2a.grpc.A2AServiceGrpc;
1616
import io.a2a.grpc.StreamResponse;
17-
import io.a2a.server.PublicAgentCard;
1817
import io.a2a.server.ServerCallContext;
1918
import io.a2a.server.auth.UnauthenticatedUser;
2019
import io.a2a.server.auth.User;
@@ -46,10 +45,6 @@
4645
import io.grpc.Status;
4746
import io.grpc.stub.StreamObserver;
4847

49-
import java.util.HashMap;
50-
import java.util.Map;
51-
52-
@ApplicationScoped
5348
public 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

Comments
 (0)