Ichiro,

I took some more time to read back through your message trace,  and
probably I was on the wrong foot.

I understand you are trying to use JSON inside a JSPWiki-plugin (based on '
RPCSamplePlugin')


Looking more in detail to the RPCSamplePlugin and the JSONRPCManager,  I
was puzzled about the actual use case:
   A (server) plugin is rendering some content, based on a (client) JSON
RPC which calls to the back to the server to retrieve content ??.

The way this is done is by injecting javascript into the page, which then
calls (asynchronously) back to the server to retrieve some data .



There are a number of issues with the current code base of JSPWiki :

- the execution of the injected jsonrpc javascript should always happen
AFTER the DOM has been fully loaded (including the loading of the
javascript libraries) ;
However the emitJSONCall() (part of JSONRPCManager) injects javascript
which try to directly invoke a document.write() with the results of an !
asynchronous jsonrpc call.
=> this needs to be fixed;  or rather removed (see later)

- the implementation of JSONRPCManager needs to be refactored based on the
Wiki.jsonrpc() rather then on the jsonrpc.js library. BTW, this library is
not shipped as part of jspwiki.  Actually the method requestJSON() is
obsolete, as all the client-side support for JSON-RPC is available in
Wiki.jsonrpc() so not additional js library needs to be invoked.

=> seems some old lose ends which need cleaning  (probably just removing
requestJSON and emitJSONCall should do -- to be checked)


* * *

Apart from the needed refactoring, how could a jsonrpc call be used in a
jspwiki plugin :

During the generation of the PLUGIN content,  the plugin can inject
javascript in the page  (direct <script> injection or via
the TemplateManager.addResourceRequest(..) )

That injected javascript should always wait for the DOM to be loaded. This
can be done like this :

        window.addEvent('domready',  function(){  /*do your thing */ });  )
.

The injected javascript can simply invoke any JSON-RPC :

       Wiki.jsonrpc( 'method', params, callback-function);


The above should of course happen AFTER the loading of the
jspwiki-common.js, which provides the Wiki.jsonrpc implementation.


Br,
dirk






On Thu, Feb 13, 2014 at 10:59 AM, Ichiro Furusato <ichiro.furus...@gmail.com
> wrote:

> Hi Dirk,
>
> Yup, that's what I meant by 'instrumented' the JSONRPCManager. The wiki log
> has my comments:
>
>     JSONRPCManager.registerGlobalObject() id='blah' class:
> 'net.neocortext.wiki.plugin.json.JsonTest$JSONRPCTarget' hashcode:
> 974083980
>     JsonTest() registered 'blah' with JSONRPCBridge.
>
> So it *seems* to be registering... I was thinking that perhaps it was a
> different
> instance of the JSONRPCManager so I even checked its hashcode.
>
> Ichiro
>
>
> On Thu, Feb 13, 2014 at 9:58 PM, Dirk Frederickx
> <dirk.frederi...@gmail.com>wrote:
>
> > Ichiro,
> >
> > The json error indicates that the command "blah.response" is not found.
> >  Maybe the JSON registerGlobalObject was not called?
> > Can you put a log just before/after the registerGlobalObject() to check
> > whether it gets invoked ?
> >
> > dirk
> >
> >
> > On Thu, Feb 13, 2014 at 9:41 AM, Ichiro Furusato
> > <ichiro.furus...@gmail.com>wrote:
> >
> > > Hi Dirk,
> > >
> > > My JSONRPCTarget is your MyJSONBlahSample. I'm quite literally doing
> > > exactly
> > > what you suggested. Here's my registration:
> > >
> > >     JSONRPCManager.registerGlobalObject("blah",new JSONRPCTarget());
> > >
> > > and my implementing class (i.e., an inner class, just the way it's done
> > in
> > > SearchManager with its JSONSearch inner class):
> > >
> > >     public class JSONRPCTarget implements RPCCallable
> > >     {
> > >         public String getResponse( String echo, int count )
> > >         {
> > >             return "response: echo='"+echo+"'; count='"+count+"'";
> > >         }
> > >     }
> > >
> > > My JavaScript call is:
> > >
> > >  Wiki.jsonrpc( 'blah.response', [qv,5], function(result,exception) {
> > >               tout.innerHTML = "x:"+result;
> > >             });
> > >
> > > The response (when printing the result) is: "[object Object]" and the
> > JSON
> > > Response
> > > (from FireBug) is:
> > >
> > > {"id":10000,"error":{"code":591,"msg":"method not found (session may
> > > have timed out)"}}"
> > >
> > > This has always been the response I've seen. As I said, I'm flummoxed
> as
> > to
> > > why
> > > I've been unsuccessful in getting this to work. I *can* swap out a call
> > to
> > > findPages
> > > and get a response from the search engine. Just not on anything *I*
> > > register, and
> > > I've instrumented the JSPWiki code in the JSONRPCManager to be sure the
> > > global registration is getting through. It is.
> > >
> > > Ichiro
> > >
> >
>

Reply via email to