3838import io .a2a .spec .SetTaskPushNotificationConfigRequest ;
3939import io .a2a .util .Utils ;
4040import java .io .IOException ;
41+ import java .util .Collections ;
4142import java .util .List ;
4243import java .util .logging .Logger ;
4344import java .util .Map ;
4445import java .util .concurrent .CompletableFuture ;
4546import java .util .concurrent .atomic .AtomicReference ;
4647import java .util .function .Consumer ;
48+ import org .jspecify .annotations .Nullable ;
4749
4850public class RestTransport implements ClientTransport {
4951
5052 private static final Logger log = Logger .getLogger (RestTransport .class .getName ());
5153 private final A2AHttpClient httpClient ;
5254 private final String agentUrl ;
53- private final List <ClientCallInterceptor > interceptors ;
55+ private @ Nullable final List <ClientCallInterceptor > interceptors ;
5456 private AgentCard agentCard ;
5557 private boolean needsExtendedCard = false ;
5658
57- public RestTransport (String agentUrl ) {
58- this (null , null , agentUrl , null );
59- }
60-
6159 public RestTransport (AgentCard agentCard ) {
6260 this (null , agentCard , agentCard .url (), null );
6361 }
6462
65- public RestTransport (A2AHttpClient httpClient , AgentCard agentCard ,
66- String agentUrl , List <ClientCallInterceptor > interceptors ) {
63+ public RestTransport (@ Nullable A2AHttpClient httpClient , AgentCard agentCard ,
64+ String agentUrl , @ Nullable List <ClientCallInterceptor > interceptors ) {
6765 this .httpClient = httpClient == null ? new JdkA2AHttpClient () : httpClient ;
6866 this .agentCard = agentCard ;
6967 this .agentUrl = agentUrl .endsWith ("/" ) ? agentUrl .substring (0 , agentUrl .length () - 1 ) : agentUrl ;
7068 this .interceptors = interceptors ;
7169 }
7270
7371 @ Override
74- public EventKind sendMessage (MessageSendParams messageSendParams , ClientCallContext context ) throws A2AClientException {
72+ public EventKind sendMessage (MessageSendParams messageSendParams , @ Nullable ClientCallContext context ) throws A2AClientException {
7573 checkNotNullParam ("messageSendParams" , messageSendParams );
7674 io .a2a .grpc .SendMessageRequest .Builder builder = io .a2a .grpc .SendMessageRequest .newBuilder (ProtoUtils .ToProto .sendMessageRequest (messageSendParams ));
7775 PayloadAndHeaders payloadAndHeaders = applyInterceptors (io .a2a .spec .SendMessageRequest .METHOD , builder , agentCard , context );
@@ -94,7 +92,7 @@ public EventKind sendMessage(MessageSendParams messageSendParams, ClientCallCont
9492 }
9593
9694 @ Override
97- public void sendMessageStreaming (MessageSendParams messageSendParams , Consumer <StreamingEventKind > eventConsumer , Consumer <Throwable > errorConsumer , ClientCallContext context ) throws A2AClientException {
95+ public void sendMessageStreaming (MessageSendParams messageSendParams , Consumer <StreamingEventKind > eventConsumer , Consumer <Throwable > errorConsumer , @ Nullable ClientCallContext context ) throws A2AClientException {
9896 checkNotNullParam ("request" , messageSendParams );
9997 checkNotNullParam ("eventConsumer" , eventConsumer );
10098 checkNotNullParam ("messageSendParams" , messageSendParams );
@@ -119,7 +117,7 @@ public void sendMessageStreaming(MessageSendParams messageSendParams, Consumer<S
119117 }
120118
121119 @ Override
122- public Task getTask (TaskQueryParams taskQueryParams , ClientCallContext context ) throws A2AClientException {
120+ public Task getTask (TaskQueryParams taskQueryParams , @ Nullable ClientCallContext context ) throws A2AClientException {
123121 checkNotNullParam ("taskQueryParams" , taskQueryParams );
124122 GetTaskRequest .Builder builder = GetTaskRequest .newBuilder ();
125123 builder .setName ("tasks/" + taskQueryParams .id ());
@@ -154,7 +152,7 @@ public Task getTask(TaskQueryParams taskQueryParams, ClientCallContext context)
154152 }
155153
156154 @ Override
157- public Task cancelTask (TaskIdParams taskIdParams , ClientCallContext context ) throws A2AClientException {
155+ public Task cancelTask (TaskIdParams taskIdParams , @ Nullable ClientCallContext context ) throws A2AClientException {
158156 checkNotNullParam ("taskIdParams" , taskIdParams );
159157 CancelTaskRequest .Builder builder = CancelTaskRequest .newBuilder ();
160158 builder .setName ("tasks/" + taskIdParams .id ());
@@ -173,7 +171,7 @@ public Task cancelTask(TaskIdParams taskIdParams, ClientCallContext context) thr
173171 }
174172
175173 @ Override
176- public TaskPushNotificationConfig setTaskPushNotificationConfiguration (TaskPushNotificationConfig request , ClientCallContext context ) throws A2AClientException {
174+ public TaskPushNotificationConfig setTaskPushNotificationConfiguration (TaskPushNotificationConfig request , @ Nullable ClientCallContext context ) throws A2AClientException {
177175 checkNotNullParam ("request" , request );
178176 CreateTaskPushNotificationConfigRequest .Builder builder = CreateTaskPushNotificationConfigRequest .newBuilder ();
179177 builder .setConfig (ProtoUtils .ToProto .taskPushNotificationConfig (request ))
@@ -195,7 +193,7 @@ public TaskPushNotificationConfig setTaskPushNotificationConfiguration(TaskPushN
195193 }
196194
197195 @ Override
198- public TaskPushNotificationConfig getTaskPushNotificationConfiguration (GetTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
196+ public TaskPushNotificationConfig getTaskPushNotificationConfiguration (GetTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
199197 checkNotNullParam ("request" , request );
200198 GetTaskPushNotificationConfigRequest .Builder builder = GetTaskPushNotificationConfigRequest .newBuilder ();
201199 builder .setName (String .format ("/tasks/%1s/pushNotificationConfigs/%2s" , request .id (), request .pushNotificationConfigId ()));
@@ -225,7 +223,7 @@ public TaskPushNotificationConfig getTaskPushNotificationConfiguration(GetTaskPu
225223 }
226224
227225 @ Override
228- public List <TaskPushNotificationConfig > listTaskPushNotificationConfigurations (ListTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
226+ public List <TaskPushNotificationConfig > listTaskPushNotificationConfigurations (ListTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
229227 checkNotNullParam ("request" , request );
230228 ListTaskPushNotificationConfigRequest .Builder builder = ListTaskPushNotificationConfigRequest .newBuilder ();
231229 builder .setParent (String .format ("/tasks/%1s/pushNotificationConfigs" , request .id ()));
@@ -255,7 +253,7 @@ public List<TaskPushNotificationConfig> listTaskPushNotificationConfigurations(L
255253 }
256254
257255 @ Override
258- public void deleteTaskPushNotificationConfigurations (DeleteTaskPushNotificationConfigParams request , ClientCallContext context ) throws A2AClientException {
256+ public void deleteTaskPushNotificationConfigurations (DeleteTaskPushNotificationConfigParams request , @ Nullable ClientCallContext context ) throws A2AClientException {
259257 checkNotNullParam ("request" , request );
260258 io .a2a .grpc .DeleteTaskPushNotificationConfigRequestOrBuilder builder = io .a2a .grpc .DeleteTaskPushNotificationConfigRequest .newBuilder ();
261259 PayloadAndHeaders payloadAndHeaders = applyInterceptors (io .a2a .spec .DeleteTaskPushNotificationConfigRequest .METHOD , builder ,
@@ -281,7 +279,7 @@ public void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationC
281279
282280 @ Override
283281 public void resubscribe (TaskIdParams request , Consumer <StreamingEventKind > eventConsumer ,
284- Consumer <Throwable > errorConsumer , ClientCallContext context ) throws A2AClientException {
282+ Consumer <Throwable > errorConsumer , @ Nullable ClientCallContext context ) throws A2AClientException {
285283 checkNotNullParam ("request" , request );
286284 io .a2a .grpc .TaskSubscriptionRequest .Builder builder = io .a2a .grpc .TaskSubscriptionRequest .newBuilder ();
287285 builder .setName ("tasks/" + request .id ());
@@ -306,7 +304,7 @@ public void resubscribe(TaskIdParams request, Consumer<StreamingEventKind> event
306304 }
307305
308306 @ Override
309- public AgentCard getAgentCard (ClientCallContext context ) throws A2AClientException {
307+ public AgentCard getAgentCard (@ Nullable ClientCallContext context ) throws A2AClientException {
310308 A2ACardResolver resolver ;
311309 try {
312310 if (agentCard == null ) {
@@ -346,8 +344,8 @@ public void close() {
346344 // no-op
347345 }
348346
349- private PayloadAndHeaders applyInterceptors (String methodName , MessageOrBuilder payload ,
350- AgentCard agentCard , ClientCallContext clientCallContext ) {
347+ private PayloadAndHeaders applyInterceptors (String methodName , @ Nullable MessageOrBuilder payload ,
348+ AgentCard agentCard , @ Nullable ClientCallContext clientCallContext ) {
351349 PayloadAndHeaders payloadAndHeaders = new PayloadAndHeaders (payload , getHttpHeaders (clientCallContext ));
352350 if (interceptors != null && !interceptors .isEmpty ()) {
353351 for (ClientCallInterceptor interceptor : interceptors ) {
@@ -383,7 +381,7 @@ private A2AHttpClient.PostBuilder createPostBuilder(String url, PayloadAndHeader
383381 return postBuilder ;
384382 }
385383
386- private Map <String , String > getHttpHeaders (ClientCallContext context ) {
387- return context != null ? context .getHeaders () : null ;
384+ private Map <String , String > getHttpHeaders (@ Nullable ClientCallContext context ) {
385+ return context != null ? context .getHeaders () : Collections . emptyMap () ;
388386 }
389387}
0 commit comments