5959import java .util .concurrent .atomic .AtomicReference ;
6060
6161import io .a2a .util .Utils ;
62+ import org .jspecify .annotations .Nullable ;
6263
6364public class JSONRPCTransport implements ClientTransport {
6465
@@ -73,8 +74,8 @@ public class JSONRPCTransport implements ClientTransport {
7374
7475 private final A2AHttpClient httpClient ;
7576 private final String agentUrl ;
76- private final List <ClientCallInterceptor > interceptors ;
77- private AgentCard agentCard ;
77+ private final @ Nullable List <ClientCallInterceptor > interceptors ;
78+ private @ Nullable AgentCard agentCard ;
7879 private boolean needsExtendedCard = false ;
7980
8081 public JSONRPCTransport (String agentUrl ) {
@@ -85,8 +86,8 @@ public JSONRPCTransport(AgentCard agentCard) {
8586 this (null , agentCard , agentCard .url (), null );
8687 }
8788
88- public JSONRPCTransport (A2AHttpClient httpClient , AgentCard agentCard ,
89- String agentUrl , List <ClientCallInterceptor > interceptors ) {
89+ public JSONRPCTransport (@ Nullable A2AHttpClient httpClient , @ Nullable AgentCard agentCard ,
90+ String agentUrl , @ Nullable List <ClientCallInterceptor > interceptors ) {
9091 this .httpClient = httpClient == null ? new JdkA2AHttpClient () : httpClient ;
9192 this .agentCard = agentCard ;
9293 this .agentUrl = agentUrl ;
@@ -95,7 +96,7 @@ public JSONRPCTransport(A2AHttpClient httpClient, AgentCard agentCard,
9596 }
9697
9798 @ Override
98- public EventKind sendMessage (MessageSendParams request , ClientCallContext context ) throws A2AClientException {
99+ public EventKind sendMessage (MessageSendParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
99100 checkNotNullParam ("request" , request );
100101 SendMessageRequest sendMessageRequest = new SendMessageRequest .Builder ()
101102 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -119,7 +120,7 @@ public EventKind sendMessage(MessageSendParams request, ClientCallContext contex
119120
120121 @ Override
121122 public void sendMessageStreaming (MessageSendParams request , Consumer <StreamingEventKind > eventConsumer ,
122- Consumer <Throwable > errorConsumer , ClientCallContext context ) throws A2AClientException {
123+ @ Nullable Consumer <Throwable > errorConsumer , @ Nullable ClientCallContext context ) throws A2AClientException {
123124 checkNotNullParam ("request" , request );
124125 checkNotNullParam ("eventConsumer" , eventConsumer );
125126 SendStreamingMessageRequest sendStreamingMessageRequest = new SendStreamingMessageRequest .Builder ()
@@ -131,7 +132,7 @@ public void sendMessageStreaming(MessageSendParams request, Consumer<StreamingEv
131132 PayloadAndHeaders payloadAndHeaders = applyInterceptors (SendStreamingMessageRequest .METHOD ,
132133 sendStreamingMessageRequest , agentCard , context );
133134
134- AtomicReference <CompletableFuture <Void >> ref = new AtomicReference <>();
135+ final AtomicReference <CompletableFuture <Void >> ref = new AtomicReference <>();
135136 SSEEventListener sseEventListener = new SSEEventListener (eventConsumer , errorConsumer );
136137
137138 try {
@@ -151,7 +152,7 @@ public void sendMessageStreaming(MessageSendParams request, Consumer<StreamingEv
151152 }
152153
153154 @ Override
154- public Task getTask (TaskQueryParams request , ClientCallContext context ) throws A2AClientException {
155+ public Task getTask (TaskQueryParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
155156 checkNotNullParam ("request" , request );
156157 GetTaskRequest getTaskRequest = new GetTaskRequest .Builder ()
157158 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -174,7 +175,7 @@ public Task getTask(TaskQueryParams request, ClientCallContext context) throws A
174175 }
175176
176177 @ Override
177- public Task cancelTask (TaskIdParams request , ClientCallContext context ) throws A2AClientException {
178+ public Task cancelTask (TaskIdParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
178179 checkNotNullParam ("request" , request );
179180 CancelTaskRequest cancelTaskRequest = new CancelTaskRequest .Builder ()
180181 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -198,7 +199,7 @@ public Task cancelTask(TaskIdParams request, ClientCallContext context) throws A
198199
199200 @ Override
200201 public TaskPushNotificationConfig setTaskPushNotificationConfiguration (TaskPushNotificationConfig request ,
201- ClientCallContext context ) throws A2AClientException {
202+ @ Nullable ClientCallContext context ) throws A2AClientException {
202203 checkNotNullParam ("request" , request );
203204 SetTaskPushNotificationConfigRequest setTaskPushNotificationRequest = new SetTaskPushNotificationConfigRequest .Builder ()
204205 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -223,7 +224,7 @@ public TaskPushNotificationConfig setTaskPushNotificationConfiguration(TaskPushN
223224
224225 @ Override
225226 public TaskPushNotificationConfig getTaskPushNotificationConfiguration (GetTaskPushNotificationConfigParams request ,
226- ClientCallContext context ) throws A2AClientException {
227+ @ Nullable ClientCallContext context ) throws A2AClientException {
227228 checkNotNullParam ("request" , request );
228229 GetTaskPushNotificationConfigRequest getTaskPushNotificationRequest = new GetTaskPushNotificationConfigRequest .Builder ()
229230 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -249,7 +250,7 @@ public TaskPushNotificationConfig getTaskPushNotificationConfiguration(GetTaskPu
249250 @ Override
250251 public List <TaskPushNotificationConfig > listTaskPushNotificationConfigurations (
251252 ListTaskPushNotificationConfigParams request ,
252- ClientCallContext context ) throws A2AClientException {
253+ @ Nullable ClientCallContext context ) throws A2AClientException {
253254 checkNotNullParam ("request" , request );
254255 ListTaskPushNotificationConfigRequest listTaskPushNotificationRequest = new ListTaskPushNotificationConfigRequest .Builder ()
255256 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -274,7 +275,7 @@ public List<TaskPushNotificationConfig> listTaskPushNotificationConfigurations(
274275
275276 @ Override
276277 public void deleteTaskPushNotificationConfigurations (DeleteTaskPushNotificationConfigParams request ,
277- ClientCallContext context ) throws A2AClientException {
278+ @ Nullable ClientCallContext context ) throws A2AClientException {
278279 checkNotNullParam ("request" , request );
279280 DeleteTaskPushNotificationConfigRequest deleteTaskPushNotificationRequest = new DeleteTaskPushNotificationConfigRequest .Builder ()
280281 .jsonrpc (JSONRPCMessage .JSONRPC_VERSION )
@@ -297,7 +298,7 @@ public void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationC
297298
298299 @ Override
299300 public void resubscribe (TaskIdParams request , Consumer <StreamingEventKind > eventConsumer ,
300- Consumer <Throwable > errorConsumer , ClientCallContext context ) throws A2AClientException {
301+ @ Nullable Consumer <Throwable > errorConsumer , @ Nullable ClientCallContext context ) throws A2AClientException {
301302 checkNotNullParam ("request" , request );
302303 checkNotNullParam ("eventConsumer" , eventConsumer );
303304 checkNotNullParam ("errorConsumer" , errorConsumer );
@@ -330,7 +331,7 @@ public void resubscribe(TaskIdParams request, Consumer<StreamingEventKind> event
330331 }
331332
332333 @ Override
333- public AgentCard getAgentCard (ClientCallContext context ) throws A2AClientException {
334+ public AgentCard getAgentCard (@ Nullable ClientCallContext context ) throws A2AClientException {
334335 A2ACardResolver resolver ;
335336 try {
336337 if (agentCard == null ) {
@@ -370,8 +371,8 @@ public void close() {
370371 // no-op
371372 }
372373
373- private PayloadAndHeaders applyInterceptors (String methodName , Object payload ,
374- AgentCard agentCard , ClientCallContext clientCallContext ) {
374+ private PayloadAndHeaders applyInterceptors (String methodName , @ Nullable Object payload ,
375+ @ Nullable AgentCard agentCard , @ Nullable ClientCallContext clientCallContext ) {
375376 PayloadAndHeaders payloadAndHeaders = new PayloadAndHeaders (payload , getHttpHeaders (clientCallContext ));
376377 if (interceptors != null && ! interceptors .isEmpty ()) {
377378 for (ClientCallInterceptor interceptor : interceptors ) {
@@ -416,7 +417,7 @@ private <T extends JSONRPCResponse<?>> T unmarshalResponse(String response, Type
416417 return value ;
417418 }
418419
419- private Map <String , String > getHttpHeaders (ClientCallContext context ) {
420+ private @ Nullable Map <String , String > getHttpHeaders (@ Nullable ClientCallContext context ) {
420421 return context != null ? context .getHeaders () : null ;
421422 }
422423}
0 commit comments