How can I apply CORS in Apache Wink? What I basically need is adding an Access-Control-Allow-Origin: *
header to every response send from Wink (where we will replace the *
for the allowed origins).
How to handle CORS in Apache Wink?
921 Views Asked by Jos de Jong At
2
There are 2 best solutions below
0

Late answer, but can be useful for future readers. Use the following code when you send the response back:
Response
.status(200)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization")
.header("Access-Control-Allow-Credentials", "true")
.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD")
.header("Access-Control-Max-Age", "1209600")
.entity(yourJsonResponse)
.build();
Response is of type : javax.ws.rs.core.Response;
A possible solution can be returning a
javax.ws.rs.core.Response
object. Using thejavax.ws.rs.core.Response.ResponseBuilder
you can add headers to the response.Update:
Another solution is to add a Servlet Filter (javax.servlet.Filter) on top of Wink that will add the headers to all responses.
Btw, in JAX-RS 2 it's possible to add Filters and Interceptors.