You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Martin Hoeller <ma...@xss.co.at> on 2012/11/14 14:42:18 UTC

problems converting sample archetype to common-container

Hi!

Some time ago I supplied a patch for a sample maven archetype [0]. Ryan
mentioned that the archetype should rather use the common container
instead of the actually used (obsolete) one.

I'm now trying to convert the archetype to use shindigs common-container
but I'm having some troubles...

I use this code for loading gadgets:

CommonContainer.preloadGadgets(gadgetUrls, function(result) {
  for (var gadgetURL in result) {
    if(!result[gadgetURL].error) {
      window.buildGadget(result, gadgetURL);
      curId++;
    }
  }
});

However, preloadGadgets does an RPC call for gadget metadata and receives
a 400 BAD_REQUEST as result :(
The content of the response is "Malformed JSON request."

Debuging showed that this was the data posted to the RPC Servlet:

[
 {"method":"gadgets.metadata",
  "id":"gadgets.metadata",
  "params":
  {
    "ids": [ "http://localhost:8080/myFirstGadget.xml",
             "http://www.labpixies.com/campaigns/todo/todo.xml"],
    "fields": ["iframeUrls",
               "modulePrefs.*",
               "needsTokenRefresh",
               "userPrefs.*",
               "views.preferredHeight",
               "views.preferredWidth",
               "expireTimeMs",
               "responseTimeMs",
               "rpcServiceIds",
               "tokenTTL"],
    "language":"de",
    "country":"DE",
    "userId":"@viewer",
    "groupId":"@self"
  }
 }
]

This data is generated by some shindig JavaScript code. Does anybody have
any idea what I'm doing wrong? I just want to use common-container to
display two gadgets. Can this be so hard?

Many thanks in advance,
- martin

[0] https://issues.apache.org/jira/browse/SHINDIG-1482

Re: problems converting sample archetype to common-container

Posted by Martin Hoeller <ma...@xss.co.at>.
On 15 Nov 2012, Martin Hoeller wrote:
> On 15 Nov 2012, Martin Hoeller wrote:
> > On 14 Nov 2012, Ryan Baxter wrote:
> > 
> > > If I had to guess that error is coming from RpcServlet.process. But it
> > > looks like you would only get that is your JSON was invalid.  I ran the
> > > JSON in your email through a validator and it looks correct, so I am not
> > > really sure.  You might want to set a breakpoint in RpcServlet.process and
> > > see if you see anything else.
> > 
> > An exception is thrown in the first line of the RpcServlet.process method:
> > 
> >       JSONObject req = new JSONObject(body);
> > 
> > The message of the exception says
> > 
> > org.json.JSONException: A JSONObject text must begin with '{' at
> >  character 1 of [{"method":"gadgets.metadata","id":"gadgets.metadata",
> > "params" ... "groupId":"@self"}}]
> 
> I did some more debugging and according to Firebug, the working
> example shipped with Shindig sends a request that is almost identical!
> 
> So I'm confused why the RpcServlet can interpret the posted data
> one time while it cannot handle it another time with no significant
> change.
> 
> Both requests have JSON data starting with '[{"method":...'.
> 
> I'm still debuging and post back when I know more...

Ok, found the cause of the problem: the failing request was directed to
the wrong Servlet. It seems I was mixing up configurations from the
various examples I found and thus the request went to the RpcServlet
instead of to the JsonRpcsServlet.

Thanks for your help anyway,
- martin

Re: problems converting sample archetype to common-container

Posted by Martin Hoeller <ma...@xss.co.at>.
On 15 Nov 2012, Martin Hoeller wrote:

> On 14 Nov 2012, Ryan Baxter wrote:
> 
> > If I had to guess that error is coming from RpcServlet.process. But it
> > looks like you would only get that is your JSON was invalid.  I ran the
> > JSON in your email through a validator and it looks correct, so I am not
> > really sure.  You might want to set a breakpoint in RpcServlet.process and
> > see if you see anything else.
> 
> An exception is thrown in the first line of the RpcServlet.process method:
> 
>       JSONObject req = new JSONObject(body);
> 
> The message of the exception says
> 
> org.json.JSONException: A JSONObject text must begin with '{' at
>  character 1 of [{"method":"gadgets.metadata","id":"gadgets.metadata",
> "params" ... "groupId":"@self"}}]

I did some more debugging and according to Firebug, the working
example shipped with Shindig sends a request that is almost identical!

So I'm confused why the RpcServlet can interpret the posted data
one time while it cannot handle it another time with no significant
change.

Both requests have JSON data starting with '[{"method":...'.

I'm still debuging and post back when I know more...

- martin

Re: problems converting sample archetype to common-container

Posted by Martin Hoeller <ma...@xss.co.at>.
On 14 Nov 2012, Ryan Baxter wrote:

> If I had to guess that error is coming from RpcServlet.process. But it
> looks like you would only get that is your JSON was invalid.  I ran the
> JSON in your email through a validator and it looks correct, so I am not
> really sure.  You might want to set a breakpoint in RpcServlet.process and
> see if you see anything else.

An exception is thrown in the first line of the RpcServlet.process method:

      JSONObject req = new JSONObject(body);

The message of the exception says

org.json.JSONException: A JSONObject text must begin with '{' at
 character 1 of [{"method":"gadgets.metadata","id":"gadgets.metadata",
"params" ... "groupId":"@self"}}]

If I remove the '[' and '[' in the JSON string in the debugger (the array
has only a single element anyways), I got another exception:

org.json.JSONException: JSONObject["context"] not found.

So it seams the actual request is incorrect. Something with a "context"
field is expected but not sent.

Any ideas?

- martin


> On Wed, Nov 14, 2012 at 8:42 AM, Martin Hoeller <ma...@xss.co.at> wrote:
> 
> > Hi!
> >
> > Some time ago I supplied a patch for a sample maven archetype [0]. Ryan
> > mentioned that the archetype should rather use the common container
> > instead of the actually used (obsolete) one.
> >
> > I'm now trying to convert the archetype to use shindigs common-container
> > but I'm having some troubles...
> >
> > I use this code for loading gadgets:
> >
> > CommonContainer.preloadGadgets(gadgetUrls, function(result) {
> >   for (var gadgetURL in result) {
> >     if(!result[gadgetURL].error) {
> >       window.buildGadget(result, gadgetURL);
> >       curId++;
> >     }
> >   }
> > });
> >
> > However, preloadGadgets does an RPC call for gadget metadata and receives
> > a 400 BAD_REQUEST as result :(
> > The content of the response is "Malformed JSON request."
> >
> > Debuging showed that this was the data posted to the RPC Servlet:
> >
> > [
> >  {"method":"gadgets.metadata",
> >   "id":"gadgets.metadata",
> >   "params":
> >   {
> >     "ids": [ "http://localhost:8080/myFirstGadget.xml",
> >              "http://www.labpixies.com/campaigns/todo/todo.xml"],
> >     "fields": ["iframeUrls",
> >                "modulePrefs.*",
> >                "needsTokenRefresh",
> >                "userPrefs.*",
> >                "views.preferredHeight",
> >                "views.preferredWidth",
> >                "expireTimeMs",
> >                "responseTimeMs",
> >                "rpcServiceIds",
> >                "tokenTTL"],
> >     "language":"de",
> >     "country":"DE",
> >     "userId":"@viewer",
> >     "groupId":"@self"
> >   }
> >  }
> > ]
> >
> > This data is generated by some shindig JavaScript code. Does anybody have
> > any idea what I'm doing wrong? I just want to use common-container to
> > display two gadgets. Can this be so hard?
> >
> > Many thanks in advance,
> > - martin
> >
> > [0] https://issues.apache.org/jira/browse/SHINDIG-1482
> >


-- 
Martin Höller                   | martin.hoeller@xss.co.at
*x Software + Systeme           | http://www.xss.co.at/
Karmarschgasse 51/2/20          | Tel: +43-1-6060114-40
A-1100 Vienna, Austria          | Fax: +43-1-6060114-71

Re: problems converting sample archetype to common-container

Posted by Ryan Baxter <rb...@apache.org>.
If I had to guess that error is coming from RpcServlet.process.  But it
looks like you would only get that is your JSON was invalid.  I ran the
JSON in your email through a validator and it looks correct, so I am not
really sure.  You might want to set a breakpoint in RpcServlet.process and
see if you see anything else.


On Wed, Nov 14, 2012 at 8:42 AM, Martin Hoeller <ma...@xss.co.at> wrote:

> Hi!
>
> Some time ago I supplied a patch for a sample maven archetype [0]. Ryan
> mentioned that the archetype should rather use the common container
> instead of the actually used (obsolete) one.
>
> I'm now trying to convert the archetype to use shindigs common-container
> but I'm having some troubles...
>
> I use this code for loading gadgets:
>
> CommonContainer.preloadGadgets(gadgetUrls, function(result) {
>   for (var gadgetURL in result) {
>     if(!result[gadgetURL].error) {
>       window.buildGadget(result, gadgetURL);
>       curId++;
>     }
>   }
> });
>
> However, preloadGadgets does an RPC call for gadget metadata and receives
> a 400 BAD_REQUEST as result :(
> The content of the response is "Malformed JSON request."
>
> Debuging showed that this was the data posted to the RPC Servlet:
>
> [
>  {"method":"gadgets.metadata",
>   "id":"gadgets.metadata",
>   "params":
>   {
>     "ids": [ "http://localhost:8080/myFirstGadget.xml",
>              "http://www.labpixies.com/campaigns/todo/todo.xml"],
>     "fields": ["iframeUrls",
>                "modulePrefs.*",
>                "needsTokenRefresh",
>                "userPrefs.*",
>                "views.preferredHeight",
>                "views.preferredWidth",
>                "expireTimeMs",
>                "responseTimeMs",
>                "rpcServiceIds",
>                "tokenTTL"],
>     "language":"de",
>     "country":"DE",
>     "userId":"@viewer",
>     "groupId":"@self"
>   }
>  }
> ]
>
> This data is generated by some shindig JavaScript code. Does anybody have
> any idea what I'm doing wrong? I just want to use common-container to
> display two gadgets. Can this be so hard?
>
> Many thanks in advance,
> - martin
>
> [0] https://issues.apache.org/jira/browse/SHINDIG-1482
>