I just used ajax to access my rest service by cxf, but some issues was
happened :
In my cxf I just set CORSInterceptor as below:
public void handleMessage(Message message) throws Fault {
Map<String, List<String>> headers =
Headers.getSetProtocolHeaders(message);
try {
//Access-Control-Allow-Origin:*
Access-Control-Allow-Methods:POST,GET
headers.put("Access-Control-Allow-Origin", Arrays.asList("*"));
headers.put("Access-Control-Allow-Methods", Arrays.asList("POST",
"GET", "PUT"));
headers.put("Access-Control-Allow-Headers",
Arrays.asList("Content-Type", "Session-Id"));
} catch (Exception ce) {
throw new Fault(ce);
}
}
In my ajax it successfully access rs if I don't set request header as blew:
$.ajax({
type:'get',
async:'true',
url: all_url,
beforeSend:function(request){console.log('loading...');},
success:function(data){
},
error:function(){
console.log("Server is busy, Please try later[getAlarmList
exception]");
}
});
anyway, if I add request header like this:
$.ajax({
type:'get',
async:'true',
url: all_url,
beforeSend:function(request){console.log('loading...');request.setRequestHeader("Session-Id",
"NBA ACTION");},
success:function(data){
},
error:function(){
console.log("Server is busy, Please try later[getAlarmList
exception]");
}
});
i am facing this error "No 'Access-Control-Allow-Origin' header is present
on the requested resource. Origin 'localhost URL' is therefore not allowed
access."
So, i doubt why using request.setRequestHeader cause this issues, is
anything restricted by use custom http header to access cross-domain?
--
View this message in context:
http://cxf.547215.n5.nabble.com/About-cxf-CORS-with-setRequestHeader-or-without-setRequestHeader-tp5744552.html
Sent from the cxf-user mailing list archive at Nabble.com.