29
29
import org .apache .commons .lang3 .tuple .Pair ;
30
30
import org .apache .commons .logging .Log ;
31
31
import org .apache .commons .logging .LogFactory ;
32
+ import org .apache .http .client .utils .URIBuilder ;
32
33
import org .apache .solr .client .solrj .util .ClientUtils ;
33
34
import org .json .simple .JSONArray ;
34
35
import org .json .simple .JSONObject ;
@@ -3360,13 +3361,22 @@ public String getOpenAPIDefinition(String apiId, String organization) throws API
3360
3361
public String invokeApiChatExecute (String apiChatRequestId , String apiType , String requestPayload ) throws APIManagementException {
3361
3362
ApiChatConfigurationDTO configDto = ServiceReferenceHolder .getInstance ().getAPIManagerConfigurationService ()
3362
3363
.getAPIManagerConfiguration ().getApiChatConfigurationDto ();
3363
- String resourceWithQueryParam = configDto .getExecuteResource () + "?apiType=" + URLEncoder .encode (apiType , StandardCharsets .UTF_8 );
3364
- if (configDto .isKeyProvided ()) {
3365
- return APIUtil .invokeAIService (configDto .getEndpoint (), configDto .getTokenEndpoint (), configDto .getKey (),
3364
+ try {
3365
+ org .apache .http .client .utils .URIBuilder uriBuilder = new org .apache .http .client .utils .URIBuilder (configDto .getExecuteResource ());
3366
+ uriBuilder .addParameter ("apiType" , apiType );
3367
+ String resourceWithQueryParam = uriBuilder .build ().toString ();
3368
+
3369
+ if (configDto .isKeyProvided ()) {
3370
+ return APIUtil .invokeAIService (configDto .getEndpoint (), configDto .getTokenEndpoint (), configDto .getKey (),
3371
+ resourceWithQueryParam , requestPayload , apiChatRequestId );
3372
+ }
3373
+ return APIUtil .invokeAIService (configDto .getEndpoint (), null , configDto .getAccessToken (),
3366
3374
resourceWithQueryParam , requestPayload , apiChatRequestId );
3375
+ } catch (java .net .URISyntaxException e ) {
3376
+ String errorMessage = "Error constructing URI for API Chat execute resource: " + e .getMessage ();
3377
+ log .error (errorMessage , e );
3378
+ throw new APIManagementException (errorMessage , e );
3367
3379
}
3368
- return APIUtil .invokeAIService (configDto .getEndpoint (), null , configDto .getAccessToken (),
3369
- resourceWithQueryParam , requestPayload , apiChatRequestId );
3370
3380
}
3371
3381
3372
3382
@ Override
@@ -3385,13 +3395,14 @@ public String invokeApiChatPrepare(String apiId, String apiChatRequestId, String
3385
3395
JsonNode openAPIDefinitionJsonNode = objectMapper .readTree (getOpenAPIDefinition (apiId , organization ));
3386
3396
payload .set (APIConstants .OPEN_API , openAPIDefinitionJsonNode );
3387
3397
} else {
3388
- String errorMessage = "Unsupported API type for API Chat: " + apiType ;
3389
- log .error (errorMessage );
3390
- throw new APIManagementException (errorMessage );
3398
+ throw new APIManagementException ("Unsupported API type for API Chat: " + apiType );
3391
3399
}
3392
3400
ApiChatConfigurationDTO configDto = ServiceReferenceHolder .getInstance ().getAPIManagerConfigurationService ()
3393
3401
.getAPIManagerConfiguration ().getApiChatConfigurationDto ();
3394
- String resourceWithQueryParam = configDto .getPrepareResource () + "?apiType=" + URLEncoder .encode (apiType , StandardCharsets .UTF_8 );
3402
+
3403
+ org .apache .http .client .utils .URIBuilder uriBuilder = new org .apache .http .client .utils .URIBuilder (configDto .getPrepareResource ());
3404
+ uriBuilder .addParameter ("apiType" , apiType );
3405
+ String resourceWithQueryParam = uriBuilder .build ().toString ();
3395
3406
3396
3407
if (configDto .isKeyProvided ()) {
3397
3408
return APIUtil .invokeAIService (configDto .getEndpoint (), configDto .getTokenEndpoint (), configDto .getKey (),
@@ -3403,6 +3414,10 @@ public String invokeApiChatPrepare(String apiId, String apiChatRequestId, String
3403
3414
String error = "Error while parsing OpenAPI definition of API ID: " + apiId + " to JSON" ;
3404
3415
log .error (error , e );
3405
3416
throw new APIManagementException (error , e );
3417
+ } catch (java .net .URISyntaxException e ) {
3418
+ String errorMessage = "Error constructing URI for API Chat prepare resource: " + e .getMessage ();
3419
+ log .error (errorMessage , e );
3420
+ throw new APIManagementException (errorMessage , e );
3406
3421
}
3407
3422
}
3408
3423
0 commit comments