title: CORS: AngularJS + Resteasy 3 + Wildfly
body: <p>I am developing an app using AngularJS and Resteasy. As expected I am facing the well known problem of</p>
  
  <p><code>XMLHttpRequest cannot load http://localhost:8080/..... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 403.</code></p>
  
  <p>As seen on other stack overflow posts <a href="https://stackoverflow.com/questions/29388937/problems-resteasy-3-09-corsfilter">[1]</a>, I tried using Resteasy's CorsFilter from a Feature object, but I get: </p>
  
  <pre><code>[33m02:06:57,883 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-1) failed to execute: javax.ws.rs.ForbiddenException: Origin not allowed: http://localhost:3000
      at org.jboss.resteasy.plugins.interceptors.CorsFilter.checkOrigin(CorsFilter.java:194)
      at org.jboss.resteasy.plugins.interceptors.CorsFilter.filter(CorsFilter.java:134)
  </code></pre>
  
  <p>My <strong>CorsFeature</strong> object:</p>
  
  <pre><code>@Provider
  public class CorsFeature implements Feature {
  
      @Override
      public boolean configure(FeatureContext context) {
          CorsFilter corsFilter = new CorsFilter();
          corsFilter.getAllowedOrigins().add("*");
          context.register(corsFilter);
          return true;
      }  
  }
  </code></pre>
  
  <p>In <strong>web.xml</strong> I added:</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;resteasy.providers&lt;/param-name&gt;
      &lt;param-value&gt;org.jboss.resteasy.plugins.interceptors.CorsFilter&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>I see that when I comment this context-param, I don't get the aforementioned Exception and the response status is 200, rather than 403.</p>
  
  <p>In the <strong>angular module config</strong> I added:</p>
  
  <pre><code>$httpProvider.defaults.useXDomain = true;
  delete $httpProvider.defaults.headers.common['X-Requested-With'];
  </code></pre>
  
  <p>I know there is the option of creating a node.js proxy, but I'd like to solve this the hard way.
  Can you please help me overcome this big obstacle in life?</p>
  
  <p>Thanks :)</p>
  
  <p><strong>Later edit:</strong> 
  I managed to accomplish that by annotating the feature class (CorsFeature) si @Component. That way the application context is aware of it.</p>