CORS does not work with jQuery and Java

I'm getting a little stuck trying to call the Java RESTFUL API using jQuery.

Debugging I found that both OPTIONS and GET methods are called, but when the GET method ends on the server, json is not retrieved and an error occurs in broswer.

REQUEST OPTIONS

OPTIONS /PTGServices/ptgapi/v1/clients/1/ngos HTTP/1.1 Host: localhost:8080 Connection: keep-alive Cache-Control: max-age=0 Access-Control-Request-Method: GET Origin: http://localhost:8181 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36 Access-Control-Request-Headers: accept, cache-control, x-custom-1, x-custom-2, authorization Accept: */* Referer: http://localhost:8181/jquerysample/local/index.html Accept-Encoding: gzip,deflate,sdch Accept-Language: es-ES,es;q=0.8,en;q=0.6 

RESPONSE OPTIONS

 HTTP/1.1 204 Sin Contenido Server: Apache-Coyote/1.1 Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: http://localhost:8181 Access-Control-Allow-Methods: GET, POST, PUT Access-Control-Allow-Headers: Authorization,Cache-control,Content-Type,Origin,X-requested-with,X-custom-1,X-custom-2,WithCredentials Access-Control-Max-Age: 60 Date: Mon, 20 Jan 2014 14:49:25 GMT 

GET REQUEST

 Accept:*/* Authorization:Basic dXNlcjp1c2Vy Cache-Control:no-cache Origin:http://localhost:8181 Referer:http://localhost:8181/jquerysample/local/index.html User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36 X-custom-1:value1 X-custom-2:value2 

In Chrome, this GET request displays an orange warning indicating: "WARNING: preliminary headers are displayed" and there is no GET response

There are no warnings in Firefox, but the answer is also empty.

After some research, I found this post indicating that both answers (OPTIONS and GET) should have Allow-Control headers, so I placed them but still didn't work ...

http://kodemaniak.de/2010/07/cross-domain-ajax-with-restlet-and-jquery/

Some idea?

Thanks!

Update 1:

I found that this could be a problem with Spring Integration, "because when I get Access-Allow- * headers, it displays in" X-Access-Allow- * "

+8
javascript jquery ajax spring-integration cors
source share
1 answer

Antonio, you must configure DefaultHttpHeaderMapper using userDefinedHeaderPrefix = null or an empty String . By default, this is really X- .

JIRA ticket on this: https://jira.springsource.org/browse/INT-1722

0
source share

All Articles