0

I have a very frustrating problem. I have a my put servive in jersy and I call it via axios. Here is my code for jersy:

@PUT
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response update(@PathParam("id") int id, String jsonRequest) {
    return new UpdateController().updateUser(id, jsonRequest);
}

Here is how I call it in the front end:

axios.put(putURL, newUserPreferences)
        .then(response => {
        .
        .

So if I call it with the avobe put request I get the following error code:

Failed to load puturl...: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3003' is therefore not allowed access. The response had HTTP status code 403.

Can anyone help why it is happening?

Hamed Minaee
  • 2,480
  • 4
  • 35
  • 63
  • https://stackoverflow.com/q/28065963/2587435 – Paul Samsotha Oct 02 '17 at 23:22
  • @peeskillet thanks so I added cores in the web.xml and all methods works except put. When I use put I get Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3003' is therefore not allowed access. The response had HTTP status code 403. – Hamed Minaee Oct 03 '17 at 00:15
  • Here is what I added in my web.xml: CorsFilter org.apache.catalina.filters.CorsFilter CorsFilter /* – Hamed Minaee Oct 03 '17 at 00:15
  • @peeskillet please see my update – Hamed Minaee Oct 03 '17 at 00:19
  • You need more configuration. Please read the docs https://tomcat.apache.org/tomcat-7.0-doc/config/filter.html#CORS_Filter – Paul Samsotha Oct 03 '17 at 00:19
  • @peeskillet Right your answer is right. Thanx. The issue was configuration – Hamed Minaee Oct 03 '17 at 00:52

0 Answers0