Hi Rimi,
You are returning Response.ok().build(). Any headers you set above
this line get ignored because you're not applying them to the object you
are returning. You should do this instead:
return Response.ok().header("Allow-Control-Allow-Methods",
"POST,GET,OPTIONS").build();
Gili
On 27/03/2011 4:38 AM, Rimi [via Jersey] wrote:
> Hi,
>
> Can you please explain what you mean by "we'd need to be able to do
> HTTP OPTIONS "mixing" (there is already an open JAX-RS issue against
> this)"?
>
>
> I am trying to set "Access-Control-Allow-Origin" and other headers and
> return it from OPTIONS method. However, I don't see that this method
> is invoked. Here is my code:
>
> @OPTIONS
> @Path("testme")
> public Response testt(@Context HttpServletResponse servlerResponse) {
> servlerResponse.addHeader("Allow-Control-Allow-Methods",
> "POST,GET,OPTIONS");
> servlerResponse.addHeader("Access-Control-Allow-Credentials",
> "true");
> servlerResponse.addHeader("Access-Control-Allow-Origin", "*");
> servlerResponse.addHeader("Access-Control-Allow-Headers",
> "Content-Type,X-Requested-With");
> servlerResponse.addHeader("Access-Control-Max-Age", "60");
> return Response.ok().build();
> }
>
> @POST
> @Path("testme")
> public String testme(@Context HttpServletResponse servlerResponse) {
> servlerResponse.addHeader("Allow-Control-Allow-Methods",
> "POST,GET,OPTIONS");
> servlerResponse.addHeader("Access-Control-Allow-Credentials",
> "true");
> servlerResponse.addHeader("Access-Control-Allow-Origin", "*");
> servlerResponse.addHeader("Access-Control-Allow-Headers",
> "Content-Type,X-Requested-With");
> servlerResponse.addHeader("Access-Control-Max-Age", "60");
> return "str";
> }
>
>
> thank you
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the
> discussion below:
> http://jersey.576304.n2.nabble.com/Access-Control-Allow-Origin-tp6060693p6211931.html
>
> To unsubscribe from Access-Control-Allow-Origin, click here
> <http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6060693&code=Y293d29jQGJicy5kYXJrdGVjaC5vcmd8NjA2MDY5M3wxNTc0MzIxMjQ3>.
>
--
View this message in context: http://jersey.576304.n2.nabble.com/Access-Control-Allow-Origin-tp6060693p6212384.html
Sent from the Jersey mailing list archive at Nabble.com.