on 2024 Feb 13 8:57 PM
Hi community,
I am currently trying to call a remote OData service from a CAP Java application, following the documentation below.
https://cap.cloud.sap/docs/guides/using-services#mock-remote-service-as-odata-service-java
I am attempting to run it locally using the method "Mock Remote Service as OData Service," but I am encountering a 404 error.
I run the application with the following command:
mvn spring-boot:run -Dspring-boot.run.profiles=default,mocked
When I send a request, I get the following error:
The remote OData service responded with status code '404' (service 'CatalogService', event 'READ', entity 'CatalogService.Books')
Additionally, when I run the service with the mvn spring-boot:run command, I am able to retrieve mock data. If you have any insight into the cause of the error, please let me know.
The code is located in the "mock-remote-service" branch of the following GitHub repository.
https://github.com/miyasuta/cap-java-remote-consumer/tree/mock_remote_service
Implementation details:
Service definition:
using { CatalogService as external } from './external/CatalogService';
service BooksService {
@readonly
entity Books as projection on external.Books;
}
Event handler implementation:
@Component
@ServiceName(BooksService_.CDS_NAME)
public class BooksServiceHandler implements EventHandler{
@Autowired
@Qualifier(CatalogService_.CDS_NAME)
CqnService catalog;
Logger logger = LoggerFactory.getLogger(BooksServiceHandler.class);
@On(event = CqnService.EVENT_READ, entity = Books_.CDS_NAME)
public Result readBooks(CdsReadEventContext context) {
logger.info("read handler called");
return catalog.run(context.getCqn());
}
}
application.yaml configuration:
spring:
config.activate.on-profile: mocked
cds:
application.services:
CatalogService-mocked:
model: CatalogService
serve:
path: CatalogService
remote.services:
CatalogService:
destination:
name: "catalogservice-mocked"
I implemented the DestinationConfiguration.java based on the following Git repository.
Services including mocks are now hosted with prefix "/odata/v4". So you need to add this to the url for the destination or as a suffix for the "remote.service".
spring:
config.activate.on-profile: mocked
cds:
application.services:
CatalogService-mocked:
model: CatalogService
serve:
path: CatalogService
remote.services:
CatalogService:
destination:
name: "catalogservice-mocked"
suffix: "/odata/v4"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
63 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.