<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.6.4">
</HEAD>
<BODY>
Hi,<BR>
<BR>
The OPTIONS request method which handles the preflight request is correct but CORS headers should be added at the POST method response headers as well. I've performed the below changes and it worked. The changes are marked with bold.<BR>
<BR>
In addition change the clientIdentifier to alias in the request body.<BR>
<BR>
<B>private Response makeCORS(ResponseBuilder rb) {</B><BR>
<B>&nbsp;&nbsp;&nbsp; rb.header(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;)</B><BR>
<B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .header(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, OPTIONS, PUT, DELETE&quot;)</B><BR>
<B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .header(&quot;Access-Control-Allow-Headers&quot;, &quot;accept, origin, ag-mobile-variant, content-type&quot;);</B><BR>
<B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </B><BR>
<B>&nbsp;&nbsp;&nbsp; return rb.build();</B><BR>
<B>}</B><BR>
&nbsp;&nbsp;&nbsp; <BR>
@POST<BR>
@Consumes(MediaType.APPLICATION_JSON)<BR>
public Response registerInstallation(<BR>
&nbsp;&nbsp;&nbsp; MobileVariantInstanceImpl entity,<BR>
&nbsp;&nbsp;&nbsp; @Context HttpServletRequest request) {<BR>
<BR>
...<BR>
<BR>
return <B>makeCORS</B>(Response.ok(<B>&quot;[]&quot;</B>));<BR>
}<BR>
<BR>
<BR>
On Wed, 2013-06-19 at 11:52 +0200, Matthias Wessendorf wrote:
<BLOCKQUOTE TYPE=CITE>
    Hi,
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    trying to add CORS, to the Server (using RestEasy), I did this:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <A HREF="https://github.com/aerogear/aerogear-unified-push-server/commit/7ccb2e7fb">https://github.com/aerogear/aerogear-unified-push-server/commit/7ccb2e7fb</A>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    (and some more variations.... (e.g. see the comment out &quot;Access-Control-Allow-Origin&quot;, where I am returing the EXACT Origin))
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    Here is a JavaScript sample:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <A HREF="http://jsfiddle.net/JY6n4/">http://jsfiddle.net/JY6n4/</A><BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    Just click on the &quot;Register a device&quot; button, and see the errors in the console....
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    So, I am always (with the above jsFiddle) getting:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    Origin <A HREF="http://fiddle.jshell.net/">http://fiddle.jshell.net</A> is not allowed by Access-Control-Allow-Origin. <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    regardless if I use &quot;*&quot; or &quot;<A HREF="http://fiddle.jshell.net">http://fiddle.jshell.net</A>&quot; (explicit Origin), on the &quot;Access-Control-Allow-Origin&quot;. &nbsp; &nbsp; I always thought that &quot;*&quot; is a wildcard.... allowing everybody and their mother to access the server.&nbsp;
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    BTW.
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    This happens with jQuery _and_ vanilla.js (XHR)..... So....... I am really overasked, but ... is it possible that the response is correct (at least the setup / my src), but that RestEasy has any problems with that stuff ??<BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    A few more eyes are highly appreciated on this &quot;issue&quot;.
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    thanks!!
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    Matthias
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
<PRE>
_______________________________________________
aerogear-dev mailing list
<A HREF="mailto:aerogear-dev@lists.jboss.org">aerogear-dev@lists.jboss.org</A>
<A HREF="https://lists.jboss.org/mailman/listinfo/aerogear-dev">https://lists.jboss.org/mailman/listinfo/aerogear-dev</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>