I have a JSF application that communicates with an SQL database and has some data. The user can access and modify the data through the GUI components we have added in the xhtml pages of the project.
Now I want to add the possibility to read the data, and execute some existing java methods by having the user accessing certain URL:s, for instance through postman or an external app.
I only need GET requests, but I need to also enable some kind of authentication, whether it be basic authentication or bearer token.
How is this done through JSF? I tried seaching through the guides, but it only mentioned how to consume data from a REST API in your JSF application. I have looked into the RemoteEndPoint and PushEndpoint annotations, and tried creating the following class:
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
@PushEndpoint("/testapi/{id}")
public class APIEndpoint {
@OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String data) {
return data;
}
}
But calling website-url/testapi/1 returned the error message:
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
And the same was the case for several similar combinations of URLs. What is the best way to do this?