SAP / cloud-sdk-java

Use the SAP Cloud SDK for Java to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
21 stars 9 forks source link

Local mode - Service bindings loaded twice - Cannot get destination #483

Open cgaillydetaurines opened 1 week ago

cgaillydetaurines commented 1 week ago

Hi Colleagues,

I am trying to run my application locally but I cannot reach destination service because bindings are loaded twice from my "default-env.json" file, and DestinationServiceAdapter class does not accept having several bindings.

image


In the ServiceBindingMerger, the bindings are doubled:

image


My supposition is loaded first by SapVcapServicesServiceBindingAccessor class

image


And a second time by VcapServiceParser from cap.

image

Appreciate your help, Clément.


newtork commented 1 week ago

What does your local environment variable look like? VCAP_SERVICES

What does the local CAP env file look like? default-env.json

Please hide any unrelated / sensitive data.

cgaillydetaurines commented 1 week ago

Hi Alexander:

I have no VCAP_SERVICES env var setup on my machine.

My default-env.json:

image


If needed, we can setup a call, I can attach easily a debugger to my env.

Tx, Clément.

KavithaSiva commented 1 week ago

I have sent an MR for 27th June for a screensharing session.

newtork commented 1 week ago

After screensharing, investigation and discussion also with CAP, we concluded:

cds bind shall not be used in combination with default-env.json

Please approach CAP colleagues directly for a suggestion on how to start the application then.


Context:

Suggested workaround (may not be used for production): ```java final List accessors = ServiceBindingAccessor.getInstancesViaServiceLoader(); accessors.removeIf(accessor -> accessor instanceof SapVcapServicesServiceBindingAccessor); final ServiceBindingMerger bindingMerger = new ServiceBindingMerger(accessors, ServiceBindingMerger.KEEP_EVERYTHING); DefaultServiceBindingAccessor.setInstance(new SimpleServiceBindingCache(bindingMerger)); ```