Question

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).

Was it helpful?

Solution

A possible solution can be returning a javax.ws.rs.core.Response object. Using the javax.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.

OTHER TIPS

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;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top