on 2018 Sep 27 3:55 PM
Hello,
I had a simple requirement to display data from Rest API(northwind) in a CloudFoundry application. But off course the actual work is never as simple as it sounds 🙂 These are the steps I have performed, and hoping someone can help.
ODataQuery testQuery = ODataQueryBuilder
.withEntity("/V2/Northwind/Northwind.svc", "Products")
.select("ProductID", "ProductName")
.skip(1)
.top(5)
.inlineCount()
.build();
ODataQueryResult result = testQuery.execute(“CF_NORTHWIND”);
Error in log:
"ERROR","categories":[],"msg":"Could not connect to destination service [No Access] :Failed to get destinations of subaccount: Failed to get access token for destination service. If your application is not running on Cloud Foundry, for example, when deploying to a local container, consider declaring the \"destinations\" environment variable to configure destinations." }
I have gone over the Official Help document numerous times, but I can’t seem to figure out what is missing.
I’ve also read that I have to create a instance of Destination and Xsuaa service at the App level. I’m not how these instances link to the SubAccount Destination?
Can someone please advise on what I could be missing? Any help would be appreciated.
Thank you,
Rob.
Request clarification before answering.
Hi Rob,
Let me clarify some stuff before I answer how to create the destination:
The template Cloud Platform Business Application template refers to CAP [Cloud Application Programming Model] - which is an MTA project ready to be used for Cloud development. CAP takes as principle the fact that you will build an application from scratch. In other words, it means that you will be developing the data model, database artifacts, services and user interface. That's one of the reasons you take the advantage of CDS artifacts - so you can describe the data model and services for the internal generators. They will create runtime artifacts such as java classes, edmx, etc. The idea is to start from a design time artifact and later focus on what's important - business coding.
CAP also uses heavily the SDK for service development - which is the library you are using to try to consume the OData Service. This library can be used in any Java project. You could, if wanted, start your development on your favorite IDE instead of WebIDE. There is a great blog series on the SAP Community related to this SDK and I think you may like it. The end-result may as well be deployed on a CF account.
There is also the S/4HANA SDK blog series that I am linking here because it also allows you to build an OData client to call the OData services from an S/4HANA system.
Now, I am not saying you can't use this template to consume an OData service. It is just that it may add complexity to your experiment. In other words, I find it odd that you are using cds artifacts to call an odata service. Unless you are trying to call an odata v2 and provide a service interface in odata v4. Still, this seems to me an odd path to take to do something simple as calling an odata service from Java in CF.
Maybe it would be a good idea to start with the first blog series, creating applications locally before you feel confortable with deployment on SCP. Moreover, playing with CAP, in my humble opinion should be considered as last step in the learning process.
Now, if you just want a quick answer, here is what's happening. The code you are using is performing a request to an OData service and it is passing as destination the name "CF_NORTHWIND". However, you don't have that destination set on your CF space for your application. A destination is simply an environment variable that your application must be able to find.
To start testing you could simply issue the following command to your cf instance (assuming your app name is odataapp):
cf set-env odataapp destinations '[{name: "CF_NORTHWIND", url: "https://services.odata.org"}]'After you have it set, test the application again. If it works, you may want to set it permanently by using the destination service. This explained in detail on step 4 of the S/4HANA SDK blog series. Search for the following session "Using the Destination Service on SAP Cloud Platform Cloud Foundry"
Hope this clarifies!
Best regards,
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.