I need cross origin REST call support for my APIs. Currently I have something like this.
@OPTIONS
public Response options() {
return Response.ok()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept")
.header("Access-Control-Allow-Methods", "GET")
.build();
}
@GET
@Path("/algorithms")
@Produces("application/json")
public Response getAllAlgorithms() {
List<MLAlgorithm> mlAlgorithms = MLCoreServiceValueHolder.getInstance().getAlgorithms();
return Response.ok(mlAlgorithms).build();
}
I used a Rest client[1] for firefox to test API calls. When I do an OPTIONS call to the "/api/configs
" API , and check the Response headers, I see only the following.
Status Code: 200 OK
Allow: GET
Content-Length: 0
Date: Mon, 23 Nov 2015 12:17:39 GMT
Server: WSO2 Carbon Server
The first two headers are not set in the response header. I need cross origin support for all APIs in the class. How do I implement this, and what is the issue in the current implementation.
[1] https://addons.mozilla.org/en-US/firefox/addon/restclient/