Reputation: 1
I tried to use the SAP Cloud SDK to consume an OData in the S/4HANA system. The application has been deployed to the Cloud Foundry evenironemnt, but I saw the error message below:
'com.sap.cloud.sdk.cloudplatform.connectivity.exception.HttpClientInstantiationException: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Unable to create an HttpClient from the provided destination. The destination is supposed to target an on-premise system but lacks the correct proxy configuration. Please check the application logs for further details.'
Destination in the BTP subaccount was created with Basic Authorization. enter image description here
The Destination Service in the Cloud Foundry space: enter image description here The Destination Service is binded to the Java application. enter image description here
The application POM: enter image description here
The project's POM, I used the latest version sdk-bom. enter image description here
The JAVA class:
import com.google.gson.Gson;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.net.http.HttpClient;
import java.util.List;
import com.sap.cloud.environment.servicebinding.api.DefaultServiceBindingAccessor;
import com.sap.cloud.environment.servicebinding.api.DefaultServiceBindingBuilder;
import com.sap.cloud.environment.servicebinding.api.ServiceBinding;
import com.sap.cloud.environment.servicebinding.api.ServiceIdentifier;
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
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.HttpDestination;
import com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationLoader;
import com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationHeaderProvider;
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
import com.sap.cloud.sdk.datamodel.odata.client.exception.ODataException;
import com.sap.cloud.sdk.datamodel.odata.helper.Order;
import com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.opapipurchasereqprocesssrv0001.PurchaseRequisition;
import com.sap.cloud.sdk.s4hana.datamodel.odata.services.DefaultOPAPIPURCHASEREQPROCESSSRV0001Service;
import java.util.*;
@RestController
@RequestMapping( "/purchaserequisitions" )
public class PurchaseRequisitionController {
private static final Logger logger = LoggerFactory.getLogger(PurchaseRequisitionController.class);
//private static final String DESTINATION_NAME = "S21";
@RequestMapping( method = RequestMethod.GET , produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getPurchaseRequisition() {
try {
//final Destination destination = DestinationAccessor.getDestination(DESTINATION_NAME)
//DefaultServiceBindingAccessor.setInstance(() -> List.of(binding));
Destination destination = DestinationAccessor.getDestination("S21");
HttpDestination httpDestination = destination.asHttp();
final List<PurchaseRequisition> purchaseRequisitions = new DefaultOPAPIPURCHASEREQPROCESSSRV0001Service() .getAllPurchaseRequisition()
.top(10) .executeRequest(httpDestination);
return ResponseEntity.ok( new Gson().toJson(purchaseRequisitions) );
} catch (final DestinationAccessException e) {
logger.error(e.getMessage(), e);
return ResponseEntity.internalServerError().body("Failed to fetch destination.");
} catch (final ODataException e) {
logger.error(e.getMessage(), e);
return ResponseEntity.internalServerError().body(e.toString());
} catch (final Exception e) {
logger.error(e.getMessage(), e);
return ResponseEntity.internalServerError().body(e.toString());
}
}
}
The mainifest.yml used in the project:
---
applications:
- name: S4HANA
memory: 150M
timeout: 300
random-route: true
path: application/target/S4HANA-application.jar
buildpacks:
- sap_java_buildpack
env:
TARGET_RUNTIME: main
SPRING_PROFILES_ACTIVE: 'cloud'
JBP_CONFIG_SAPJVM_MEMORY_SIZES: 'metaspace:128m..'
JBP_CONFIG_COMPONENTS: 'jres: [''com.sap.xs.java.buildpack.jre.SAPMachineJRE'']'
JBP_CONFIG_SAP_MACHINE_JRE: '{ use_offline_repository: false, version: 17.0.5 }'
Upvotes: 0
Views: 182
Reputation: 1124
Based on your description it seems that you are missing the connectivity
service.
This also needs to bind against your application, in addition to the destination service, to be able to connect to your on-premise system via the cloud connector.
Upvotes: 0