1

The Restangular works fine with post() or get(), but if I want to delete something, then I got the following error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access.

I tried the solution on this site:

How to enable Cross domain requests on JAX-RS web services?

@Provider
public class CORSFilter implements ContainerResponseFilter {

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

        cres.getHeaders().add("Access-Control-Allow-Origin", "*");
        cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
        cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
        cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
        cres.getHeaders().add("Access-Control-Max-Age", "1209600");
    }

}

But then I got the following error:

The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:8888, *', but only one is allowed. Origin 'http://localhost:8888' is therefore not allowed access.

I don't quite understand what does this error mean and how could I fix it? Thanks!

The localhost:8888 is defined in Gulp.

Community
  • 1
  • 1
Manuela
  • 1,379
  • 3
  • 16
  • 25

2 Answers2

0

The 'Access-Control-Allow-Origin' header must just be 'http://localhost:8888'

It is explained well in the second answer in the thread:
Why is jquery's .ajax() method not sending my session cookie?

Community
  • 1
  • 1
Pim Verkerk
  • 1,066
  • 7
  • 12
0

We added these codes in our web.xml and it solves the problem:

<init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET, POST, HEAD, PUT, DELETE</param-value>
</init-param>
Manuela
  • 1,379
  • 3
  • 16
  • 25