I don't think you need to send a request parameter with the data -- Partuza
does. That's what it does right now. I could see that there was a mismatch,
but I wasn't sure who had it right (Partuza or Shindig). In the
fetch_gadget_metadata function in the applications.php file, Partuza sets the
JSON into the POST body like this:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'request=' . urlencode($request));
I'll update my local copy of the Partuza code to send text/json instead of
x-form/www-urlencoded so it works properly with Java Shindig, and I'll send a
message to the Partuza developers list asking them to do the same (although I
suspect that the PHP version of the RpcServlet is built to expect
x-form/www-urlencoded, so they'll probably have to change that too).
But this brings me back to my original question -- in order to be able to swap
out PHP Shindig for Java Shindig, they obviously need to handle requests for
metadata the same way. I tried to find a specification that would tell me how
the request is supposed to be made, 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. Is there a more
detailed specification somewhere that I missed?
Thanks again,
--Jesse
-----Original Message-----
From: Kevin Brown [mailto:[EMAIL PROTECTED]
Sent: Friday, October 31, 2008 3:27 PM
To: [email protected]
Subject: Re: Partuza with Java Shindig
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
>