Problem with delete change request via atomHandler

May 11, 2012 at 2:12 PM

Hi Alex,

I use now datajs to do change requests with atom/XML requests as you described in the last thread (I use the ODataAtomHandler now). Now I ran into the problem when doing delete requests.

The server responds with 204 and has no content and no content type set in the response. That's ok. But in that case datajs calls the error handler because it crashed in the

var handlerRead = function (handler, parseCallback, response, context) {

if (!response || !response.headers) {
return false;
}

var cType = getContentType(response);
var version = getDataServiceVersion(response) || "";
var body = response.body;

if (!assigned(body)) {
return false;
}

 if (handlerAccepts(handler, cType)) { <-- crash here because no ctype
var readContext = createReadWriteContext(cType, version, context, handler);
readContext.response = response;
response.data = parseCallback(handler, body, readContext);
return response.data !== undefined;
}

return false;

}

function.

 It works when using the defaultHandler but not the atomHandler.

When I add an additional check:

if (!response || !response.headers || !response.body) {
return false;
}

 it works fine and the successHandler is called correctly.

The default handler code doesn't call this function at all because there is a check before in this function:

odata.defaultHandler = {
read: function (response, context) {
/// <summary>Reads the body of the specified response by delegating to JSON and ATOM handlers.</summary>
/// <param name="response">Response object.</param>
/// <param name="context">Operation context.</param>

if (response && assigned(response.body) && response.headers["Content-Type"]) {
dispatchHandler("read", response, context);
}
},

 where the readHandler isn't called at all when there is no response body/content type.

Could you please check that? I was trying that with the normal

http://services.odata.org/%28S%28readwrite%29%29/OData/OData.svc/

server.

 

Thanks!

Joe

 

May 11, 2012 at 10:29 PM

Hi Joe,

   Thanks for reporting this I will take a look into it. What strikes me is that the lines:

   if (!assigned(body)) {
      return false;
   } 

   Should prevent the handler form taking any more action with the response.  Can you share a trace of the request and the response?  I'm intrigued to see why body is not null or undefined.

   For the time being I think you can do the following in your web app initialization to unblock you, if you want to use the atomHandler:   

OData.atomHandler.read = (function () {
    var atomReadFunction = OData.atomHandler.read;
    return function (response, context) {
        if (response.headers["Content-Type"]) {
            return atomReadFunction.call(OData.atomHandler, response, context);
        }
    }
})();

Regards,

Alex Trigo

May 14, 2012 at 9:09 AM

Hi Alex,

thanks!

here is the trace. I also debugged and the response.body is "" so  !assigned(body) is false.

var body = response.body;

if (!assigned(body)) {
return false;
}

{
"startedDateTime": "2012-05-14T09:03:41.009Z",
"time": 206,
"request": {
"method": "DELETE",
"url": "http://services.odata.org/(S(ldwmozatefmdqx1gcyjqt000))/OData/OData.svc/Products(6)",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Origin",
"value": "http://localhost:8080"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,sdch"
},
{
"name": "Accept-Language",
"value": "en-US,en;q=0.8"
},
{
"name": "Connection",
"value": "keep-alive"
},
{
"name": "MaxDataServiceVersion",
"value": "2.0"
},
{
"name": "Accept-Charset",
"value": "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
},
{
"name": "Host",
"value": "localhost:8080"
},
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19"
},
{
"name": "Accept",
"value": "application/atom+xml,application/atomsvc+xml,application/xml"
},
{
"name": "Referer",
"value": "http://localhost:8080/test/ODataWrite.html"
},
{
"name": "DataServiceVersion",
"value": "2.0"
}
],
"queryString": [],
"cookies": [],
"headersSize": 626,
"bodySize": 0
},
"response": {
"status": 204,
"statusText": "No Content",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Date",
"value": "Mon, 14 May 2012 09:03:41 GMT"
},
{
"name": "X-AspNet-Version",
"value": "4.0.30319"
},
{
"name": "X-Powered-By",
"value": "ASP.NET"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Server",
"value": "Microsoft-IIS/7.5"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "DataServiceVersion",
"value": "1.0;"
}
],
"cookies": [],
"content": {
"size": 0,
"mimeType": "text/plain",
"compression": 0
},
"redirectURL": "",
"headersSize": 218,
"bodySize": 0
},
"cache": {},
"timings": {
"blocked": 0,
"dns": -1,
"connect": -1,
"send": 0,
"wait": 200,
"receive": 6,
"ssl": -1
},
"pageref": "page_7"
}