99import com .sap .ai .sdk .core .common .ClientResponseHandler ;
1010import com .sap .ai .sdk .core .common .ClientStreamingHandler ;
1111import com .sap .cloud .sdk .cloudplatform .connectivity .ApacheHttpClient5Accessor ;
12- import com .sap .cloud .sdk .cloudplatform .connectivity .DefaultHttpDestination ;
1312import com .sap .cloud .sdk .cloudplatform .connectivity .Header ;
1413import com .sap .cloud .sdk .cloudplatform .connectivity .HttpDestination ;
1514import com .sap .cloud .sdk .cloudplatform .connectivity .exception .DestinationAccessException ;
@@ -49,8 +48,9 @@ <T> T execute(
4948 log .debug ("Successfully serialized request into JSON payload" );
5049 val request = new HttpPost (path );
5150 request .setEntity (new StringEntity (json , ContentType .APPLICATION_JSON ));
51+ customHeaders .forEach (h -> request .addHeader (h .getName (), h .getValue ()));
5252
53- val client = getHttpClient (customHeaders );
53+ val client = getHttpClient ();
5454
5555 val handler =
5656 new ClientResponseHandler <>(responseType , OrchestrationError .Synchronous .class , FACTORY )
@@ -75,11 +75,12 @@ Stream<OrchestrationChatCompletionDelta> stream(
7575 @ Nonnull final Object payload ,
7676 @ Nonnull final List <Header > customHeaders ) {
7777 try {
78-
7978 val json = JACKSON .writeValueAsString (payload );
8079 val request = new HttpPost (path );
8180 request .setEntity (new StringEntity (json , ContentType .APPLICATION_JSON ));
82- val client = getHttpClient (customHeaders );
81+ customHeaders .forEach (h -> request .addHeader (h .getName (), h .getValue ()));
82+
83+ val client = getHttpClient ();
8384
8485 return new ClientStreamingHandler <>(
8586 OrchestrationChatCompletionDelta .class , OrchestrationError .Streaming .class , FACTORY )
@@ -96,11 +97,8 @@ Stream<OrchestrationChatCompletionDelta> stream(
9697 }
9798
9899 @ Nonnull
99- private HttpClient getHttpClient (@ Nonnull final List <Header > customHeaders ) {
100- val destination =
101- DefaultHttpDestination .fromDestination (destinationSupplier .get ())
102- .headers (customHeaders )
103- .build ();
100+ private HttpClient getHttpClient () {
101+ val destination = destinationSupplier .get ();
104102 log .debug ("Using destination {} to connect to orchestration service" , destination );
105103 return ApacheHttpClient5Accessor .getHttpClient (destination );
106104 }
0 commit comments