Question

I have a Java service running on my main OS(Windows7 Pro.) and I can access it throu broswer at http://localhost:8080/.... It returns valid JSON reposnse.

I also have a SPA written in angularjs, that is located on my virtual machine where I created a Virtual-Host for it(for more comfortable access). Virtual machine OS is Ubuntu Server 12.04.X LTS.

Since those environments are in network terms separated from each other, I was trying to access Java service through my local machine IP address X.X.X.X:8080(pinging through terminal did send response). Since normal $http usage didn't work I tried solution suggested in this answer How to load a cross-domain JSON with $http in angularjs 1.0.8 as it does with 1.2.0, but either it is too old or something else is wrong, but when I try to do same it just doesn't work. In console I see only following

XMLHttpRequest cannot load http://X.X.X.X:8080/library/api/books. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://dev.xxx' is therefore not allowed access.

Était-ce utile?

La solution

Thanks everyone for their input. Can't say was my solution correct or not, but I got result I was expection.

I combined info found here Filter requests for CORS with answer from this question Java / Jetty: How to Add Filter to Embedded Jetty. I wasn't sure how to add a filter, that would listen for request and set response headers accordingly.

Hope that solution will help to those who might come in contact with same situation.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top