Error making REST call with AngularJS

0

I'm using $ http from angular to make REST calls on my server, however I'm having a problem:

In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

I have tried several things, but nothing has solved me, does anyone know how to solve?

My Code:

.factory('CotacaoService', ['$http', function($http){
var cotacao = [];
$http({
  method: 'GET',
  url: 'http://192.168.254.8:8084/CotacaoREST/recursos/cotacoes/1/991'
}).then(function successCallback(response) {
    cotacao = response.data;
  }, function errorCallback(response) {
    console.log(response);
  });
return cotacao;

}]);

    
asked by anonymous 23.02.2016 / 13:17

1 answer

0

Try to create a filter to work with CORS:

import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

@Provider
public class CORSFilter implements ContainerResponseFilter {

    @Override
    public void filter(ContainerRequestContext request,
            ContainerResponseContext response) throws IOException {
        response.getHeaders().add("Access-Control-Allow-Origin", "*");
        response.getHeaders().add("Access-Control-Allow-Headers",
                "origin, content-type, accept, authorization");
        response.getHeaders().add("Access-Control-Allow-Credentials", "true");
        response.getHeaders().add("Access-Control-Allow-Methods",
                "GET, POST, PUT, DELETE, OPTIONS, HEAD");
    }
}

Source: link

Another solution would be .

    
23.02.2016 / 15:54