none
Process a batch of requests results in unexpected JSON response

    Question

  • When using the batch capability to send multiple requests at once, the callback capability is not firing in the samples (Group Subscription) and resulting in an error on parsing the JSON response.  Is there a work-around in the transport.js to handle the set of responses?
    Monday, April 08, 2013 5:34 PM

Answers

  • I'm not seeing the question mark preceding the response text elsewhere.  I think I may have had a bug in my JavaScript code somewhere because it is working now.

    The piece that was likely throwing me off is that the Transport.js this.handleCallback does handle the callback for this.sendBatch() before the callback defined in the sendBatch request.  It throws the error because the overall response is not JSON formatted and has not been parsed within Batch.js and Mime.js.  The error thrown in Transport.js does not impact the rest of the JavaScript from occurring.

    Wednesday, April 10, 2013 8:24 PM

All replies

  • A few questions:

    • How many requests does it appear to be sending when you receive the error?
    • What does the request body look like for the batch request? (Fiddler trace would be helpful)
    • What does the response body look like for the batch request? (Fiddler trace would be helpful)

    Is there a work-around in the transport.js to handle the set of responses? - Transport is intended to send a single request to the server whereas batch wraps multiple (up to ~30) and sends it to the server.  My guess is you are probably receiving an error response to at least one of the requests wrapped in the batch and it is not properly handling decoding it (most likely the response is not json when it attempts to do a JSON.parse(responseText) etc).

    Tuesday, April 09, 2013 12:37 PM
  • I get the error within the transport.js no matter how many items are in the batch (2-30).  It appears that the handleCallback method in transport.js is responding to these callbacks even if it isn't defined in the handler.  The error is thrown when doing the JSON.parse because the content isn't in a JSON format (see the response body below).

    I do have my code working now with the batch (still throwing the handleCallback error) but the rest of the page is responding appropriately.


    My request body looks like:

    --50489596-1328-4c8c-9065-5e8f514e07df
    Content-Type: application/http; msgtype=request
    GET /ucwa/oauth/v1/applications/103790365469/people/contacts?groupId=Etah6cLhDq72o1wPuJTauhyAiwZqeTNvmmtYt3LGBsY= HTTP/1.1
    Host: [lyncserver]
    Accept: application/json

    --50489596-1328-4c8c-9065-5e8f514e07df
    Content-Type: application/http; msgtype=request
    POST /ucwa/oauth/v1/applications/103790365469/people/presenceSubscriptions?groupId=Etah6cLhDq72o1wPuJTauhyAiwZqeTNvmmtYt3LGBsY=&duration=11 HTTP/1.1
    Host: [lyncserver]
    Accept: application/json

    --50489596-1328-4c8c-9065-5e8f514e07df--

    The response body looks like:

    --95768d3a-8e1d-4ef7-94d9-a6b17d933f2c
    Content-Type: application/http; msgtype=response

    HTTP/1.1 200 OK
    Cache-Control: no-cache
    Content-Type: application/json; charset=utf-8

    ?{"_links":{"self":{"href":"/ucwa/oauth/v1/applications/103790365469/people/contacts?groupId=Etah6cLhDq72o1wPuJTauhyAiwZqeTNvmmtYt3LGBsY="}},"_embedded":{"contact":[]},"rel":"groupContacts"}
    --95768d3a-8e1d-4ef7-94d9-a6b17d933f2c
    Content-Type: application/http; msgtype=response

    HTTP/1.1 201 Created
    Cache-Control: no-cache
    Content-Type: application/json; charset=utf-8

    ?{"id":"Etah6cLhDq72o1wPuJTauhyAiwZqeTNvmmtYt3LGBsY=","_links":{"self":{"href":"/ucwa/oauth/v1/applications/103790365469/people/presenceSubscriptions/Etah6cLhDq72o1wPuJTauhyAiwZqeTNvmmtYt3LGBsY="},"memberships":{"href":"/ucwa/oauth/v1/applications/103790365469/people/presenceSubscriptionMemberships?presenceSubscriptionId=Etah6cLhDq72o1wPuJTauhyAiwZqeTNvmmtYt3LGBsY%3d"}},"rel":"presenceSubscription"}
    --95768d3a-8e1d-4ef7-94d9-a6b17d933f2c--

    Tuesday, April 09, 2013 8:35 PM
  • Each response is preceded by a question mark: ?{"key": "value"}.  Are you seeing this sort of behavior in any of your other response(s)?

    Can you post what browser string is?  (Check out something like IP Chicken and copy the string after Browser)

    You will want to track down (in JavaScript) what is causing this as I believe that excluding the question mark may fix up the response body and the Json parsing.  You could track it down by debugging Batch.js and looking for this.sendBatch().  Inside there you can find where it is iterating over the results and executing callbacks.

    • Edited by ShelbyZ Wednesday, April 10, 2013 4:58 PM wrong train of thought...
    Wednesday, April 10, 2013 12:17 PM
  • I'm not seeing the question mark preceding the response text elsewhere.  I think I may have had a bug in my JavaScript code somewhere because it is working now.

    The piece that was likely throwing me off is that the Transport.js this.handleCallback does handle the callback for this.sendBatch() before the callback defined in the sendBatch request.  It throws the error because the overall response is not JSON formatted and has not been parsed within Batch.js and Mime.js.  The error thrown in Transport.js does not impact the rest of the JavaScript from occurring.

    Wednesday, April 10, 2013 8:24 PM