1. Get the VCAP_SERVICES: Navigate to BTP
+ * > agent-approuter > environment variables and copy the VCAP_SERVICES part
+ * starting with {"identity".
+ *
+ *
2. Get the JSON_WEB_TOKEN: Copy your password while logging into Cloud Identity. Make a Bruno request to
+ * https://ma.accounts400.ondemand.com/oauth2/token with the following URL encoded body:
+ *
+ *
+ * grant_type=client_credentials + * &client_id=<approuter-client-id> + * &client_secret=<approuter-client-secret> + * &username=<your-email> + * &password=<Cloud-Indentity-password> + *+ */ +class AgentToolIntegrationLayerTest { + + private static final String VCAP_SERVICES = +""" +"""; + + private static final String JSON_WEB_TOKEN = +""" +"""; + + String payload = +""" +{ + "message": { + "role": "user", + "parts": [ + { + "kind": "data", + "data": { + "userQuery": "Plan a travel itinerary for me for Berlin" + } + } + ], + "kind": "message" + } +} +"""; + + @BeforeEach + void prepareInboundAccessToken() { + DefaultServiceBindingAccessor.setInstance( + new SapVcapServicesServiceBindingAccessor( + Collections.singletonMap("VCAP_SERVICES", VCAP_SERVICES)::get)); + AuthTokenAccessor.setAuthTokenFacade( + () -> Try.success(new AuthToken(JWT.decode(JSON_WEB_TOKEN)))); + } + + @Test + @SneakyThrows + void testAgentToolIntegrationLayer() { + var options = + ServiceBindingDestinationOptions.forService(IDENTITY_AUTHENTICATION) + .withOption( + AuthenticationServiceOptions.withTargetUri( + "https://gen-ai-hub-sdk-8pengs8d.eu12.sapdas.cloud.sap")) + .withOption(IasOptions.withApplicationName("Agent2Joule")) + .onBehalfOf(OnBehalfOf.NAMED_USER_CURRENT_TENANT) + .build(); + + var destination = ServiceBindingDestinationLoader.defaultLoaderChain().getDestination(options); + + String atilUrl = + "/api/content/v1/capabilities/com.sap.ai.sdk/my_assistant_capability/scenarios/plan_travel/v1/message:send?assistant=my_assistant_i563080"; + var httpPost = new HttpPost(atilUrl); + httpPost.setEntity(new StringEntity(payload, APPLICATION_JSON.withCharset((String) null))); + httpPost.setHeader( + "x-callback-target", "https://echo-server.cfapps.eu12-001.hana.ondemand.com"); + httpPost.setHeader("x-global-user-id", "01361f5a-9ca7-4593-9c54-2425a127edff"); + httpPost.setHeader("Accept-Language", "en"); + + var response = + ApacheHttpClient5Accessor.getHttpClient(destination) + .execute(httpPost, new BasicHttpClientResponseHandler()); + System.out.println(response); + } +}