![](https://community.sap.com/html/assets/img_tile-default.png)
Create Destination
Instance Creation
Service Plan Selection
Bind Application
Choose Application
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>scp-cf</artifactId>
<version>3.46.0</version>
</dependency>
package com.sap.renegotiation.sbo.controllers;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpClientAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination;
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@RestController
public class DestinationController {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@GetMapping("/getProducts")
public String getProducts() {
String DESTINATION_NAME = "Northwind_Products"; //in productive code, use constants file to
//retrieve destination name
try {
/* get the destination information from a facade provided by cloud platform */
HttpDestination destination =
DestinationAccessor.getDestination(DESTINATION_NAME).asHttp();
HttpClient client = HttpClientAccessor.getHttpClient(destination);
HttpResponse httpResponse = null;
try {
httpResponse = client.execute(new HttpGet());
/* Retrieve response data once the request is successful */
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) {
log.info("IOException: " + e.getMessage());
return "IOException: " + e.getMessage();
}
} catch (DestinationNotFoundException e) {
/* Destination is not found with specified name */
log.info("DestinationNotFoundException: " + e.getMessage());
return "DestinationNotFoundException: " + e.getMessage();
} catch (DestinationAccessException e) {
/* Destination cannot be accessed */
log.info("DestinationAccessException: " + e.getMessage());
return "DestinationAccessException: " + e.getMessage();
}
return null;
}
}
Response Data
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
18 | |
17 | |
11 | |
11 | |
10 | |
10 | |
10 | |
10 | |
7 | |
7 |