[
https://issues.apache.org/jira/browse/SHINDIG-1436?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul Lindner closed SHINDIG-1436.
---------------------------------
part of 2.5.0-beta1 release.
> Shindig does not support returning a JSON array when format 'json' is
> selected on an osapi.http.get request.
> ------------------------------------------------------------------------------------------------------------
>
> Key: SHINDIG-1436
> URL: https://issues.apache.org/jira/browse/SHINDIG-1436
> Project: Shindig
> Issue Type: Bug
> Components: Java
> Affects Versions: 2.0.0
> Reporter: Craig McClanahan
> Assignee: Henry Saputra
> Fix For: 2.5.0-beta1
>
>
> I am trying to use an osapi.http.get request to a JSON service that returns a
> JSON array with a collection of objects, rather than just a single object.
> osapi.http.get({
> href : 'http://www.example.com/customers', // Returns an array of
> customer objects, so the first character in the response will be '['
> format : 'json',
> authz : 'none'
> }).execute(function(response) {
> ...
> });
> Even though I can contact this service successfully with other clients,
> trying to access it via osapi.http.get with Shindig results in a status 406
> response with message "Response not valid JSON" from the transformBody()
> method in HttpRequestHandler.java. In turn, this is because the logic in
> this method tries to create a single JSON object out of the response text:
> /** Format a response as JSON, including additional JSON inserted by
> chained content fetchers. */
> protected Object transformBody(HttpApiRequest request, HttpResponse results)
> throws GadgetException {
> String body = results.getResponseAsString();
> if ("feed".equalsIgnoreCase(request.format)) {
> return processFeed(request, body);
> } else if ("json".equalsIgnoreCase(request.format)) {
> try {
> return new JSONObject(body);
> } catch (JSONException e) {
> // TODO: include data block with invalid JSON
> throw new ProtocolException(HttpServletResponse.SC_NOT_ACCEPTABLE,
> "Response not valid JSON", e);
> }
> }
>
> return body;
> }
> The call to the JSONObject constructor will fail because the body text starts
> with "[" (because it is a JSON array), not "{".
> This behavior is inconsistent with my read of the OpenSocial 1.0
> specification[1], which states that the "content" element of the response may
> contain either a JSON object or a JSON array:
> If @format is "json", the parsed JSON object or array of the response.
> The proposed solution would be to check for the first non-whitespace
> character, and return new JSONArray(body) if it is a '[' character, instead
> of '{'.
> [1]
> http://opensocial-resources.googlecode.com/svn/spec/1.0/Core-Data.xml#rfc.section.2.9
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira