CORS Response Filter not invoked Resteasy / JAX-RS 2.0
<p>I am trying to implement a CORS response filer to allow cross-domain reference from my JavaScript front-end. I am using <code>Wildfly 10.0.final</code> which comes with Resteasy that is <code>JAX-RS 2.0</code> compliment if I understand correctly.</p>

<p>EDIT: added @Provider to the CorsResponseFilter, and as a singleton to the RestServiceConfig.</p>

<p>What do I need to do to get my CorsResponseFilter invoked?</p>

<p>PS. Read these posts, but they didn't help solving the problem.</p>

<p><a href="https://stackoverflow.com/questions/23670885/containerrequestfilter-containerresponsefilter-dosent-get-called">ContainerRequestFilter ContainerResponseFilter dosent get called</a></p>

<p><a href="https://stackoverflow.com/questions/25440321/resourceconfig-and-application">ResourceConfig and Application</a></p>

<p>CorsResponseFilter.java</p>

<pre><code>@Provider
public class CorsResponseFilter implements ContainerResponseFilter {

@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

    MultivaluedMap&lt;String, Object&gt; headers = responseContext.getHeaders();
    headers.add("Access-Control-Allow-Origin", "*");
    //headers.add("Access-Control-Allow-Origin", "http://podcastpedia.org"); //allows CORS requests only coming from podcastpedia.org       
    headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    headers.add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia");        
    headers.add("Access-Control-Max-Age", "1209600");
}
</code></pre>

<p>}</p>

<p>RestServiceConfig.java</p>

<pre><code>public class RestServiceConfig extends Application {

    private final Set&lt;Object&gt; singletons = new HashSet&lt;&gt;();

    public RestServiceConfig() {
        singletons.add(new CorsResponseFilter());  
        singletons.add(new ApplicationService());
        singletons.add(new TweetObsService());
    }

    @Override
    public Set&lt;Object&gt; getSingletons() {
        return singletons;
    }
}
</code></pre>

<p>web.xml</p>

<pre><code>...
&lt;listener&gt;
    &lt;listener-class&gt;
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    &lt;/listener-class&gt;
&lt;/listener&gt;

&lt;servlet&gt;
    &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    &lt;/servlet-class&gt;
    &lt;init-param&gt;
        &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt;
        &lt;param-value&gt;org.mycorp.myapp.service.RestServiceConfig&lt;/param-value&gt;
    &lt;/init-param&gt;
    &lt;init-param&gt;
        &lt;param-name&gt;com.sun.jersey.spi.container.ContainerResponseFilters&lt;/param-name&gt;
        &lt;param-value&gt;org.clearbyte.obs.service.CorsResponseFilter&lt;/param-value&gt;
    &lt;/init-param&gt;
&lt;/servlet&gt;
&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/service/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
&lt;context-param&gt;
    &lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
    &lt;param-value&gt;/service&lt;/param-value&gt;
&lt;/context-param&gt;

...
</code></pre>

<p>Wildfly log console</p>

<pre><code>13:56:01,672 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] RESTEASY002225: Deploying javax.ws.rs.core.Application: class org.clearbyte.obs.service.RestServiceConfig
13:56:01,672 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] RESTEASY002200: Adding class resource org.clearbyte.obs.service.TweetObsService from Application class org.clearbyte.obs.service.RestServiceConfig
13:56:01,672 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] RESTEASY002200: Adding class resource org.clearbyte.obs.service.ApplicationService from Application class org.clearbyte.obs.service.RestServiceConfig
</code></pre>