title: Jersey CORS working for GET but not POST
body: <p>My Jersey <a href="http://en.wikipedia.org/wiki/Cross-origin_resource_sharing" rel="noreferrer">CORS</a> request is not functioning for POST, but works for GET requests.  The headers are being mapped to Jersey requests as shown in the below screenshot of a GET request to the same resource.</p>
  
  <p>However, doing a POST to the below method makes me end up with <code>XMLHttpRequest cannot load http://production.local/api/workstation. Origin http://workstation.local:81 is not allowed by Access-Control-Allow-Origin.</code></p>
  
  <p><strong>Here's a screenshot of network activity:</strong>
  <img src="https://i.stack.imgur.com/GHW05.png" alt="enter image description here"></p>
  
  <p><strong>Details on failed POST request:</strong>
  <img src="https://i.stack.imgur.com/8W0t0.png" alt="enter image description here"></p>
  
  <p><strong>Here's my resource:</strong></p>
  
  <pre><code>@Path("/workstation")
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_JSON})
  public class WorkstationResource {
  
      @InjectParam
      WorkstationService workstationService;
  
      @POST
      public WorkstationEntity save (WorkstationEntity workstationEntity) {
          workstationService.save(workstationEntity);
          return workstationEntity;
      }
  
      @GET
      @Path("/getAllActive")
      public Collection&lt;WorkflowEntity&gt; getActive () {
          List&lt;WorkflowEntity&gt; workflowEntities = new ArrayList&lt;WorkflowEntity&gt;();
          for(Workflow workflow : Production.getWorkflowList()) {
              workflowEntities.add(workflow.getEntity());
          }
          return workflowEntities;
      }
  }
  </code></pre>
  
  <p><strong>My CORS filter:</strong></p>
  
  <pre><code>public class ResponseCorsFilter implements ContainerResponseFilter {
  
      @Override
      public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
  
          Response.ResponseBuilder responseBuilder = Response.fromResponse(response.getResponse());
          responseBuilder
                  .header("Access-Control-Allow-Origin", "*")
                  .header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
  
          String reqHead = request.getHeaderValue("Access-Control-Request-Headers");
  
          if(null != reqHead &amp;&amp; !reqHead.equals(null)){
              responseBuilder.header("Access-Control-Allow-Headers", reqHead);
          }
  
          response.setResponse(responseBuilder.build());
  
          return response;
      }
  }
  </code></pre>
  
  <p>My Jersey configuration in my Main class:</p>
  
  <pre><code>//add jersey servlet support
  ServletRegistration jerseyServletRegistration = ctx.addServlet("JerseyServlet", new SpringServlet());
  jerseyServletRegistration.setInitParameter("com.sun.jersey.config.property.packages", "com.production.resource");
  jerseyServletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.production.resource.ResponseCorsFilter");
  jerseyServletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE.toString());
  jerseyServletRegistration.setInitParameter("com.sun.jersey.config.feature.DisableWADL", Boolean.TRUE.toString());
  jerseyServletRegistration.setLoadOnStartup(1);
  jerseyServletRegistration.addMapping("/api/*");
  </code></pre>