Handling cross domain preflight AJAX OPTIONS requests with Spring MVC 4 -


this simple answer, can't seem work. in cross-domain, preflight ajax request, client first makes options request set of headers figure out remote server accepts.

right now, every spring controller post interface create, have create options interface, this:

 @requestmapping(method = requestmethod.options, value = "/addwebservice")     public responseentity addwebserviceoptions() {         return new responseentity(httpstatus.no_content);     }  @requestmapping(method = requestmethod.post, value = "/addwebservice")     public ajaxresponse<webservice> addwebservice(principal principal, @requestbody webservice webservice) throws userserviceexception { ... } 

i read somewhere can make 1 simple method doesn't have mapping specific path handle options requests, this:

@requestmapping(method = requestmethod.options)     public responseentity handle() {         return new responseentity(httpstatus.no_content);     } 

however, when add method, every request submit states can't find mapping requested resource.

is there way handle options requests in single method without having create 1 every interface create?

for interested, simple adding request mapping of "/*". can remove other options methods controllers , handle preflight options requests single method:

@requestmapping(method = requestmethod.options, value = "/*") @responsebody public responseentity handleoptions() {     return new responseentity(httpstatus.no_content); } 

also worth noting, had add security config allow requests make options call without receiving 403 error (and allow websockets connect properly):

http         .authorizerequests()         .antmatchers(httpmethod.options, "/**").permitall()         .antmatchers("/stomp/**").permitall()         .antmatchers("/**").hasrole("user"); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -