sandervanloock / HTMobieL

Thesis repos voor htmobiel.wordpress.com
2 stars 1 forks source link

save expense to backend #4

Closed miteyema closed 11 years ago

miteyema commented 11 years ago

We have to send the expense form in raw JSON format to the backend. jQuery en Sencha suffer from the same problem when saving the expense to the backend. We both get the following error response:

OPTIONS http://localhost:8888/resources/expenseService/saveExpense 415 (Unsupported Media Type).

Normally it was only Sencha that sends OPTIONS requests, but now jQuery does too because the contentType is set to application/json. We found a very recent discussion (sept 2012) on Stackoverflow regarding this issue for jQuery: http://stackoverflow.com/questions/12320467/jquery-cors-content-type-options. We followed the code and suggestions to add new Access-Control headers in the OPTIONS response from the backend:

Access-Control-Allow-Origin: * Access-Control-Allow-Methods: POST Access-Control-Allow-Headers: Content-Type

We added those headers and ran the GAE locally. When we try to save the expense and look in the console of Eclipse, we see the following error:

Jan 10, 2013 8:22:49 AM com.sun.jersey.spi.container.ContainerRequest getEntity SEVERE: A message body reader for Java type, class com.capgemini.expense.model.ExpenseRequest, and MIME media type, application/octet-stream, was not found

Because of this error, GAE replies to the frontend with the 415 error.

miteyema commented 11 years ago

Backend changed, now the following error is shown: XMLHttpRequest cannot load http://kulcapexpenseapp.appspot.com/resources/expenseService/saveExpense. Request header field Content-Type is not allowed by Access-Control-Allow-Headers.

miteyema commented 11 years ago

The solution is to allow the Content-Type in the headers of the OPTIONS request (see also http://stackoverflow.com/questions/12320467/jquery-cors-content-type-options).

This works offline, but apparently not online. Maybe GAE was not redeployed?

miteyema commented 11 years ago

GAE was not redeployed