I want to call an Integration Suite IFlow from the SAP CAP Java App.
and I am using BTP Destination for this.
So Basically, I have defined the endpoints of iFlow and creds in the Destination, binded the Destination with the deployed application.
I followed this blog: Consuming external OData service from CAP Java application
My Java Code:
package customer.integration_suite.handlers;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import com.sap.cds.services.handler.EventHandler;
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpClientAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@RestController
public class IntegrationSuiteConnection implements EventHandler {
@GetMapping("/integration-suite")
public String connectToIntegrationSuite() {
String DESTINATION_NAME = "IntegrationSuite";
try {
Destination destination = DestinationAccessor.getDestination(DESTINATION_NAME);
HttpClient client = HttpClientAccessor.getHttpClient(destination);
HttpResponse httpResponse = null;
try{
httpResponse = client.execute(new HttpGet());
if (httpResponse.getStatusLine().getStatusCode() == 200) {
BufferedReader reader = new BufferedReader(
new InputStreamReader(httpResponse.getEntity().getContent()));
StringBuilder result = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
result.append(line);
}
reader.close();
return result.toString();
}
} catch (IOException e) {
return "IOException: " + e.getMessage();
}
} catch (DestinationNotFoundException | DestinationAccessException e) {
return e.getMessage();
}
return null;
}
}
My iFlow is returning just a simple String.
But on hitting the url : https://81fff548trial-dev-integration-suite.cfapps.us10-001.hana.ondemand.com/integration-suite, i am not getting the desired result.
I am getting this on the browser: Failed to get destination.
Please help me to resolve this.
Also, I wanted to know to know, is this even the right way to call an iFlow from the CAP app?
Please let me know about this too.
Thanks,
Abhinav
Request clarification before answering.
In the blog post you mentioned, the code to get a destination is as follows:
HttpDestination destination = DestinationAccessor.getDestination(DESTINATION_NAME).asHttp();Whereas your code is:
Destination destination = DestinationAccessor.getDestination(DESTINATION_NAME);Can this make a difference?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
While there might be options to simplify the code when it comes to the response handling (I'm less familiar with Java), conceptually this should work.
As long as your application (also in hybrid mode) is bound to the Destination service, and the correct destination name is used it should be able to find it. Then it's about making sure your endpoint to the iflow is correct as the url you posted seems incorrect to me.
Double check the exposed endpoint mentioned in the deployed iflow: the url will probably follow a syntax similar to: https://<tenant>.it-cpi018-rt.cfapps.eu10-003.hana.ondemand.com/http/<endpoint>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Willem,
The url is correct because the message that i am getting, Failed to get destination., is coming from the catch block only.
catch (DestinationNotFoundException | DestinationAccessException e) {
return e.getMessage();
}
But even after correctly binding my app with the destination, it is not finding it.
**The url that you have mentioned is of the iFlow which i want to hit from the cap app.I have mentioned the iflow url in the destination correctly.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 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.