13

I am a bit stuck trying to make a call to my Java RESTFUL API with jQuery.

Debugging I have found both OPTIONS and GET method are called but when GET method finishes in the server, json is not retrieved and an error raises in the broswer.

OPTIONS REQUEST

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

OPTIONS RESPONSE

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 shows an orange warning indicating : 'CAUTION: provisional headers are shown' and there are no GET response

In Firefox, there are no warning but the response is empty too.

After some researching, I found this post indicating both responses (OPTIONS and GET) must have the Allow-Control headers, so I put it but still not work...

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

Some idea?

Thanks!

Update 1:

I have found it can be an Spring Integration "issue", since when I retrieve Access-Allow-* headers, it is being mapping into "X-Access-Allow-*"

Antonio Acevedo
  • 1,480
  • 3
  • 21
  • 39

1 Answers1

0

Antonio, you should configure DefaultHttpHeaderMapper with userDefinedHeaderPrefix = null or empty String. By default it is really X-.

The JIRA ticket on the matter: https://jira.springsource.org/browse/INT-1722

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Hello, Antonio! It would be better to finish this question somehow. We are going to reconsider the `X-` bahavior, BTW: https://jira.spring.io/browse/INT-3903 – Artem Bilan Jan 12 '16 at 15:09