I've followed the official documentation in order to create my own occaddon webservice layer : https://help.sap.com/viewer/e5d7cec9064f453b84235dc582b886da/1905/en-US/8b96a80f8669101482d4f3c1e27b4eb6.html and created the "dummy" controller :
package org.training.trainingoccaddon.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value = "/{baseSiteId}/newResource")
public class ExtendedCustomersController {
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public String getNewResource() {
return "newSampleResource";
}
}
However, when I try to access to
https://localhost:9002/rest/v2/{baseSiteId}/newResource
It redirects me to hac.
I've created my new occ addon added to localextensions.xml Performed ant addoninstall -Daddonnames="occaddon" -DaddonStorefront.ycommercewebservices="ycommercewebservices"
Rebuit the application with ant clean all && hybrisserver debug
But It doesn't work. Am I missing something?
Also, how can I setup swagger?
I am assuming you are using SAP Commerce 1905, also that you not have added any custom 'ycommercewebservices' extension.
Missing ycommercewebservices extension
Since you are redirected to the HAC your 'ycommercewebservices' extension is not loaded correctly. Normally it should throw an error from the 'ycommercewebservices' extension itself instead of redirecting to the HAC.
The extension should be at least present in the 'localextension.xml'. You can verify loaded extensions in the HAC
e.g. https://localhost:9002/platform/extensions
The next thing you could check if your addon was added as dependency in the 'ycommercewebservices' extension by checking the 'extensioninfo.xml' in its directory. Also double check if a 'project.properties' file was generated in your custom occaddon extension. If something is wrong here you should review your 'ant addoninstall' command.
Swagger Setup
Swagger works out of the box and you can decorate your classes with the annotations as documented on here https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X.
You can visit the swagger ui on the ycommercewebservices extension
e.g. https://localhost:9002/rest/v2/swagger-ui.html