Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
2  
You need to enable cross origin resource sharing (CORS) on your java service. –  Anthony Chu Feb 13 at 21:59
    
Tried to enable it as it is explained here cxf.apache.org/docs/jax-rs-cors.html, but didn't help in anyway. –  Eugene Feb 13 at 23:28
1  
Make sure you have added the CORS interceptor to your jax-rs server. CORS works if you follow the Apache CXF instructions to the letter. –  Geoff Genz Feb 14 at 0:11

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.