On Fri, Oct 31, 2008 at 7:46 AM, Ciancetta, Jesse E. <[EMAIL PROTECTED]>wrote:
> Hi,
>
> I am trying to run Partuza using the Java Shindig server and have run into
> an issue. The problem occurs whenever I try to add a new gadget to my page
> -- I end up getting back an error from Shindig saying "Malformed JSON
> request". I traced the issue back to the doPost method of the RpcServlet
> and found two different problems:
>
> 1) Since the code in the doPost method is reading the data directly from
> the input stream of the request, I think it needs to URL decode it before it
> tries to use it.
>
> 2) It seems like there is a mismatch between what Partuza is sending and
> what Shindig is expecting. Partuza is sending the JSON using name-value
> pairs, and Shindig seems to expect the JSON to be the only thing the in body
> of the POST body.
Yes, Shindig is expecting that you post text/json, not
x-form/www-urlencoded. They're two very different things. Why do you think
you need to send a request parameter with this data? I wrote the metadata
handler and it's always been this way, and it's intentional.
>
>
> This is an example of what the RpcServlet ends up trying to create a new
> JSONObject with:
>
>
> request=%7B%22context%22%3A%7B%22country%22%3A%22US%22%2C%22language%22%3A%22en%22%2C%22view%22%3A%22default%22%2C%22container%22%3A%22partuza%22%7D%2C%22gadgets%22%3A%5B%7B%22url%22%3A%22http%3A%5C%2F%5C%
> 2Fwww.labpixies.com
> %5C%2Fcampaigns%5C%2Fmaps%5C%2Fmaps.xml%22%2C%22moduleId%22%3A%221%22%7D%5D%7D
>
> which causes the JSONObject constructor to throw an exception.
>
> If I replace this code in the doPost method:
>
> ServletInputStream is = request.getInputStream();
> byte[] body = IOUtils.toByteArray(is);
> if (body.length != length) {
> logger.info("Wrong size. Length: " + length + " real: " +
> body.length);
> response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
> return;
> }
>
> with this:
>
> byte[] body = request.getParameter("request").getBytes();
>
> everything works fine (since getParameter does the decoding for me, and I
> end up with just the JSON data).
>
> So my question is this -- how do I figure out who's right with regards to
> how the data should be sent? Should the data be send as the value of the
> "request" parameter (like Partuza is doing), or should the JSON be the only
> thing in the POST body (like Shindig seems to expect)? I tried to find a
> specification that would give me the answer, but all I came up with is this:
>
> http://code.google.com/apis/gadgets/docs/spec.html
>
> which doesn't get into enough detail to answer the question.
>
> Thanks,
>
> --Jesse
>