cancel
Showing results for 
Search instead for 
Did you mean: 

CAP JAVA: read to External service entity values

former_member731459
Discoverer

Hello experts,

I'm learning CAP Java and trying to connect to an external C4C service and I want to read a entity values on C4C service. I followed this example here.

I've added the following code to my cds service:

using {Customer as external  } from './external/Customer.csn';
service CustomerService{
    @readonly
    entity IndividualCustomerCollection as projection on external.IndividualCustomerCollection {
        key ObjectID, CustomerID, ExternalID, ExternalSystem, RoleCode, FirstName, LastName
    };
}

I created DestinationConfiguration like this. After that i have added the following code to event handler:

    @Autowired
    @Qualifier("Customer")
    RemoteService remote;

    @On(event = CdsService.EVENT_READ, entity = "CustomerService.IndividualCustomerCollection")
    public List<IndividualCustomerCollection> readProducts() {
        CqnSelect select = Select.from(IndividualCustomerCollection_.class);
        List<IndividualCustomerCollection> collection = remote.run(select).listOf(IndividualCustomerCollection.class);
        return collection;
    }

However, when I try to GET /CustomerService/IndividualCustomerCollection.I get the following error:

com.sap.cds.services.impl.ContextualizedServiceException: The remote OData service responded with status code '404' (service 'Customer', event 'READ', entity 'Customer.IndividualCustomerCollection')
        at com.sap.cds.services.impl.ServiceImpl.dispatch(ServiceImpl.java:223) ~[cds-services-impl-1.14.3.jar:na]
        at com.sap.cds.services.impl.ServiceImpl.emit(ServiceImpl.java:151) ~[cds-services-impl-1.14.3.jar:na]
        at com.sap.cds.services.ServiceDelegator.emit(ServiceDelegator.java:52) ~[cds-services-api-1.14.3.jar:na]
        at com.sap.cds.services.utils.services.AbstractCdsService.run(AbstractCdsService.java:53) ~[cds-services-utils-1.14.3.jar:na]
        at com.sap.cds.services.utils.services.AbstractCdsService.run(AbstractCdsService.java:43) ~[cds-services-utils-1.14.3.jar:na]
        at com.sap.cap.bookstore.handlers.CustomerService.readProducts(CustomerService.java:77) ~[classes/:na]
        at com.sap.cds.services.impl.handlerregistry.HandlerRegistryTools$DescribedHandler.process(HandlerRegistryTools.java:165) ~[cds-services-impl-1.14.3.jar:na]

Could someone please help how can i read external service values?

I am very new to the CAP Java, so perhaps the solution may be very obvious and simple. Please be kind to me.

Accepted Solutions (0)

Answers (3)

Answers (3)

thanhtrungtran142
Discoverer

I'm facing the same issue. Is it resolve?

0 Kudos

I guess we need void type methods as we are using events in CAP,Check this once

 @On(event = CdsService.EVENT_READ, entity = "CustomerService.IndividualCustomerCollection")
    public void readProducts() {..}
kibriya_inamdar
Discoverer
0 Kudos

Hi, I'm facing the same issue. Can you add a comment about how to solve this issue? Thank you in advance