Skip to Content

Count Element in SAP Cloud Platform SDK for Service Development

Hello,

I have been following these tutorials for Cloud Service Development(link), but I been struggling with this one issue, and really hope someone can help me out.

Issue: Service response does not contain a Count element?

…/odata/v2/EPMSampleService/Products?$select=Category,Price&$inlinecount=allpages

Result:

My Code for Service Class:

//Getting Data
ODataQueryResult result = ODataQueryBuilder
  .withEntity("/sap/opu/odata/IWBEP/GWSAMPLE_BASIC", "ProductSet")
  .select("ProductID", "Name", "Description", "Category", "Price")
  .inlineCount()
  .build()
  .execute(DESTINATION_NAME);

count = result.getInlineCount();
result.setInlineCount(count);

//Returning Data
final List<ProductEntity> v2ProductList = result.asList(ProductEntity.class);
queryResponse = QueryResponse.setSuccess().setData(v2ProductList).response();
return queryResponse;

Any help or hints would me much appreciated.
Thank you,
Rob

nocount.jpg (34.1 kB)
Add comment
10|10000 characters needed characters exceeded

1 Answer

  • Posted on Jan 13 at 04:31 PM

    Hi Rob Gauthier, I am a rookie on SCP, I hope you have successfully achieved your project, I would like to know if you can provide me with an example project of ODATA consumption. I am developing my project,

    This is my code:

    @Setter 
    @Getter 
    public class ODataEntity { 
    
    @ElementName("Land1") @JsonProperty("Land1") @Key 
    private String Land1; 
    
    @ElementName("Landx") @JsonProperty("Landx") 
    private String Landx; 
    
    @ElementName("Natio") @JsonProperty("Natio") 
    private String Natio; 
    
    } 
    public class ODataService {
        private static final Logger logger = LoggerFactory.getLogger(ODataService.class);
    public List<ODataEntity> doGet(){ 
    logger.info("Class: ODataService -> Method: doGet: "); System.getenv("destinations"); 
    
    //final ErpHttpDestination destination = DestinationAccessor.getDestination("SAP_Gateway").asHttp().decorate(DefaultErpHttpDestination::new);       
    
    try { 
    ODataQueryResult result = ODataQueryBuilder 
    
    .withEntity("/sap/opu/odata/IWBEP/GWSAMPLE_BASIC", "VH_CountrySet") 
    .select("Land1", "Landx", "Natio")
    .build()
    .execute("SAP_Gateway"); 
    
    final List<ODataEntity> oDataEntityList = result.asList(ODataEntity.class); 
    
    logger.info("doGet: " + Arrays.deepToString(oDataEntityList.toArray())); 
    
    return oDataEntityList; 
    
    } catch (final ODataException e) { logger.error(e.getMessage(), e); return null; } 
    
    }

    but I get the following Error:

    2020 01 13 15:10:16#+00#ERROR#com.sap.cloud.sdk.odatav2.connectivity.ODataQuery##P2000546367#https-jsse-nio-8041-exec-3#na#p2000546367trial#iprovideriprovider#web#p2000546367trial#na#na#na#na#Could not connect to destination service [No Access] :com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException: No destination for name 'SAP_Gateway' could be found in any of the registered loaders. |
    2020 01 13 15:10:16#+00#ERROR#com.sap.cloud.sdk.odatav2.connectivity.ODataQuery##P2000546367#https-jsse-nio-8041-exec-3#na#p2000546367trial#iprovideriprovider#web#p2000546367trial#na#na#na#na#Could not connect to destination service [No Access] : [Ljava.lang.StackTraceElement;@437bb240 |
    2020 01 13 15:10:16#+00#ERROR#com.csti.buenaventura.iprovider.zlicitacion.sap.odata.test1.ODataService##P2000546367#https-jsse-nio-8041-exec-3#na#p2000546367trial#iprovideriprovider#web#p2000546367trial#na#na#na#na#Unable to execute the OData operation : Failed to execute OData request. com.sap.cloud.sdk.odatav2.connectivity.ODataException: Unable to execute the OData operation : Failed to execute OData request.
    	at com.sap.cloud.sdk.odatav2.connectivity.ODataQuery.internalExecute(ODataQuery.java:271)
    	at com.sap.cloud.sdk.odatav2.connectivity.ODataQuery.execute(ODataQuery.java:180)
    	at com.sap.cloud.sdk.odatav2.connectivity.ODataQuery.execute(ODataQuery.java:229)
    	at com.csti.buenaventura.iprovider.zlicitacion.sap.odata.test1.ODataService.doGet(ODataService.java:61)
    	at com.csti.buenaventura.iprovider.zlicitacion.sap.odata.BusinessPartnerServlet.doGet(BusinessPartnerServlet.java:62)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at com.sap.core.communication.server.CertValidatorFilter.doFilter(CertValidatorFilter.java:155)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.lambda$doFilter$1(RequestAccessorFilter.java:71)
    	at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute$0(AbstractThreadContextExecutor.java:317)
    	at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:247)
    	at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:319)
    	at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:71)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:97)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:128)
    	at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:66)
    	at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:103)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    	at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:121)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    	at com.sap.core.connectivity.jco.session.ext.RequestTracker.invoke(RequestTracker.java:55)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
    	at com.sap.cloud.runtime.impl.bridge.security.AbstractAuthenticator.invoke(AbstractAuthenticator.java:206)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    	at com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:182)
    	at com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:97)
    	at com.sap.js.statistics.tomcat.valve.RequestTracingValve.callNextValve(RequestTracingValve.java:113)
    	at com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:59)
    	at com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    	at java.lang.Thread.run(Thread.java:836)
    Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException: No destination for name 'SAP_Gateway' could be found in any of the registered loaders.
    	at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationLoaderChain.tryGetDestination(DestinationLoaderChain.java:74)
    	at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationLoader.tryGetDestination(DestinationLoader.java:36)
    	at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.tryGetDestination(DestinationAccessor.java:138)
    	at com.sap.cloud.sdk.odatav2.connectivity.ODataQuery.getHttpClient(ODataQuery.java:233)
    	at com.sap.cloud.sdk.odatav2.connectivity.ODataQuery.internalExecute(ODataQuery.java:250)
    	... 61 common frames omitted
    Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException: No destination for name 'SAP_Gateway' could be found in any of the registered loaders.
    	... 66 common frames omitted
    |
    
    
    

    destination.png (40.1 kB)
    Add comment
    10|10000 characters needed characters exceeded