Hi,
I have 2 Java Application ( App1 , App2 ) deployed in a Tomcat Server.
both this Application has one REST(http) Service.
Say, SR1: http://192.168.0.1:8080/App1/rest/customer
SR2: http://192.168.0.1:8080/App2/rest/customer
And, the concept of this if you call this SR1, it will redirect the request to SR2.
CORS for this Server is activated.
- < filter >
- < filter-name > CorsFilter </ filter-name >
- < filter-class > org.apache.catalina.filters.CorsFilter </ filter-class >
- < init-param >
- < param-name > cors.allowed.origins </ param-name >
- < param-value > * </ param-value >
- </ init-param >
- < init-param >
- < param-name > cors.allowed.methods </ param-name >
- < param-value > GET,POST,HEAD,OPTIONS,PUT </ param-value >
- </ init-param >
- < init-param >
- < param-name > cors.allowed.headers </ param-name >
- < param-value > Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers </ param-value >
- </ init-param >
- < init-param >
- < param-name > cors.exposed.headers </ param-name >
- < param-value > Access-Control-Allow-Origin,Access-Control-Allow-Credentials </ param-value >
- </ init-param >
- < init-param >
- < param-name > cors.support.credentials </ param-name >
- < param-value > true </ param-value >
- </ init-param >
- < init-param >
- < param-name > cors.preflight.maxage </ param-name >
- < param-value > 10 </ param-value >
- </ init-param >
- </ filter >
- < filter-mapping >
- < filter-name > CorsFilter </ filter-name >
- < url-pattern > /* </ url-pattern >
- </ filter-mapping >
Now, I'm calling this SR1 using Jquery Ajax from Chrome. And the request is redirecting to SR2 to properly.
ISSUE:
But, the issue is when I'm calling SR1 with a header in my request, then first, OPTION call to SR1 is happening fine. Actual REQUEST is also going to SR1 properly, getting the redirection URL from there, but then it's unable to go to SR2.
ERROR MESSAGE:
MY CODE:
- $.ajax({ url: " http://192.168.0.1:8080/App1/rest/customer", dataType: 'APPLICATION/JSON', type: "GET", beforeSend: function(xhr){xhr.setRequestHeader('X-Requested-With', 'test-value');}, success: function() { alert('Success!'); } });
Question:
Now, the question is, how to call this service, which is redirecting, from ajax jquery along with a header? Just to clarify, the 1st service is going to need this header, not the redirected service.
Thank you!
Anijit