You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jspwiki.apache.org by Ichiro Furusato <ic...@gmail.com> on 2014/01/30 21:56:13 UTC

JSON-RPC support

Hi,

I'm digging into an AJAX-related project that in theory should be using
the org.apache.wiki.rpc.json.JSONRPCManager to register the callback
used in JavaScript (i.e., via requestJSON(WikiContext)).

This obviously is working as the search popup uses it, but the existing
code seems broken. The JSONRPCManager spits out the following bit
of JavaScript:

  "jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");

In my tests using a subclass of the RPCSamplePlugin, the above code
flags two errors in Firebug, namely that the 'jsonrpc' variable hasn't
been declared, and the JSONRpcClient class doesn't seem to exist
anywhere in the JSPWiki code (nor can I find it in a JS library).

Could someone point me to any documentation or examples of how to
use the RPCSamplePlugin, as this doesn't seem to exist on even the
old ecyrd site. Is this broken legacy code or am I just being daft and
can't find something obvious?

If I can manage to get an example of a JSON-RPC WikiPlugin going
we'll share that code as part of our plugin package, which would help
other developers do JSPWiki+AJAX work.

Thanks for any assistance,

Ichiro

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
Ichiro, e.a.,


More digging in json-rpc ...
I did some further investigation, trying to rewrite emitJSONCall to
something workable.

Apparently there are 2 types of rpc's, those  that are registered via
registerGlobalObject(..) and those that are registered via
registerJSONObject(..)

registerGlobalObject
==> { method:"search.findPages", params:[...] }

registerJSONObject
==> { method:"RPCxxxxxxx.function", params:[...] }

For the second case, the "RPCxxxx" is generated at run-time, and bound to
the RPCCallable instance.  So this is a number which continuously changes.
BTW, note that the "params" field has to be of type Array.

* * *

I've patched emitJSONCall(..) so that it now renders  correct JSON RPC
invocation javascript.

=> No more error-code 591 -- message not found ;
As Ichiro rightly pointed out, the json-rpc methods are being properly
registered.

But -- another error is thrown instead ; by WikiJSONAccessor(..)

    code: 490
    msg: "No permission to access this AJAX method!"
    trace: "org.apache.wiki.auth.WikiSecurityException: No permission to
access this AJAX method!


This error is thrown even when I'm logged in as an Administrator.

Anybody a clue why JSPWiki would refuse such ajax calls?



dirk




On Sat, Feb 15, 2014 at 3:09 PM, Ichiro Furusato
<ic...@gmail.com>wrote:

> Hi Harry,
>
> I can't honestly say. But I just added a printout of the list of objects in
> the global
> registry in the JSONRPCManager, and all of my registrations (of plugins as
> well
> as singleton application-level manager objects) are showing up in the
> c_globalObjects
> list. The problem seems to be related to the code that connects the JS call
> to that
> registry.
>
> Ichiro
>
> On Sun, Feb 16, 2014 at 2:12 AM, Harry Metske <harry.metske@gmail.com
> >wrote:
>
> > I am a complete novice in this area, but aren't you running in this same
> > situation as we did before:
> >
> >
> >
> https://issues.apache.org/jira/browse/JSPWIKI-659?focusedCommentId=13552522&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13552522
> >
> > kind regards,
> > Harry
> >
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Harry,

I can't honestly say. But I just added a printout of the list of objects in
the global
registry in the JSONRPCManager, and all of my registrations (of plugins as
well
as singleton application-level manager objects) are showing up in the
c_globalObjects
list. The problem seems to be related to the code that connects the JS call
to that
registry.

Ichiro

On Sun, Feb 16, 2014 at 2:12 AM, Harry Metske <ha...@gmail.com>wrote:

> I am a complete novice in this area, but aren't you running in this same
> situation as we did before:
>
>
> https://issues.apache.org/jira/browse/JSPWIKI-659?focusedCommentId=13552522&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13552522
>
> kind regards,
> Harry
>

Re: JSON-RPC support

Posted by Harry Metske <ha...@gmail.com>.
I am a complete novice in this area, but aren't you running in this same
situation as we did before:

https://issues.apache.org/jira/browse/JSPWIKI-659?focusedCommentId=13552522&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13552522

kind regards,
Harry




On 15 February 2014 14:00, Ichiro Furusato <ic...@gmail.com>wrote:

> Hi Dirk,
>
> I'm not suggesting the issue is mootools vs. jQuery, only that my
> inexperience
> with the former and the difficulty in intermixing them has kept me from
> using my
> own jQuery knowledge (which is still relatively novice-level) to quickly
> debug the
> problem, client-side.
>
> More pertinent to what I agree is the problem is why the global
> registration never
> seems to result in the JSON-RPC calls being successful. After all I've
> tried I'm
> now registering a singleton global object similar to the SearchManager,
> i.e., an
> object that exists prior to the page containing either the plugin or the
> JSP-based
> client-side script being called. And the registration does show up as
> successful
> in the logs. So I agree, this is server-side, but it seems to have more to
> do with
> the client being unable to get *any* response from the server on a
> pre-registered
> RPCCallable object. As I mentioned, until the RPCSamplePlugin can be shown
> to work I think I'm just stabbing in the dark. I don't think (after all of
> our discussion)
> that there's anything remarkable about my code -- it's all as I've
> described
> previously, pretty simple stuff.
>
> Cheers,
>
> Ichiro
>
>
> On Sun, Feb 16, 2014 at 12:30 AM, Dirk Frederickx <
> dirk.frederickx@gmail.com
> > wrote:
>
> > Ichiro,
> >
> > The issue is *not* client-side related ; actually the moo tools rpc-calls
> > are working perfectly; and returning the proper json rpc error codes.
> > So mootools or jquery would not make any difference here.
> > The problem is the registration of the JSONRPC-Callable classes on the
> > server.
> >
> > Perhaps the registration of your JSON-RPC plugin is happening too late
> for
> > the JSONRPC-Manager.sessionCreated() to be picked up ?
> > Maybe a logging of the c_gloablObjects in the JSONRPC-Manager may help to
> > reveal a timing issues.
> >
> > Just my .02 cents,
> >
> >
> > Feel free to share your java and js code on the dev mailbox.
> >
> > dirk
> >
> >
> >
> > On Sat, Feb 15, 2014 at 9:19 AM, Ichiro Furusato
> > <ic...@gmail.com>wrote:
> >
> > > Hi Dirk,
> > >
> > > Yes, you're understanding what I'm trying to do. In addition to the
> > plugin
> > > I've
> > > also been using a bespoke JSP page with scriptlets to prototype ideas
> > > quickly,
> > > as well as a JavaScriptPlugin we wrote years ago as a test bed. (That
> > could
> > > be submitted as a replacement for the JSPWiki plugin of the same name
> if
> > > people are interested.)
> > >
> > > I have tried the 'domready' wrapper you suggested but that didn't seem
> to
> > > make any difference, and given the amount of time I've now spent on
> this
> > I
> > > have to say that I'm likely going to abandon any AJAX-related work in
> the
> > > JSPWiki space until it at some point as moved over to jQuery, and
> > there's a
> > > working RPCSamplePlugin. I've just run out of both steam and time.
> > >
> > > For now I'll probably try using some other approach than the
> > JSONRPCManager
> > > since I just can't get that to work. Perhaps Apache Wink or some kind
> of
> > > lightweight RESTful client-server thing, dunno.
> > >
> > > Thanks very much for all your help,
> > >
> > > Ichiro
> > >
> >
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Dirk,

I'm not suggesting the issue is mootools vs. jQuery, only that my
inexperience
with the former and the difficulty in intermixing them has kept me from
using my
own jQuery knowledge (which is still relatively novice-level) to quickly
debug the
problem, client-side.

More pertinent to what I agree is the problem is why the global
registration never
seems to result in the JSON-RPC calls being successful. After all I've
tried I'm
now registering a singleton global object similar to the SearchManager,
i.e., an
object that exists prior to the page containing either the plugin or the
JSP-based
client-side script being called. And the registration does show up as
successful
in the logs. So I agree, this is server-side, but it seems to have more to
do with
the client being unable to get *any* response from the server on a
pre-registered
RPCCallable object. As I mentioned, until the RPCSamplePlugin can be shown
to work I think I'm just stabbing in the dark. I don't think (after all of
our discussion)
that there's anything remarkable about my code -- it's all as I've
described
previously, pretty simple stuff.

Cheers,

Ichiro


On Sun, Feb 16, 2014 at 12:30 AM, Dirk Frederickx <dirk.frederickx@gmail.com
> wrote:

> Ichiro,
>
> The issue is *not* client-side related ; actually the moo tools rpc-calls
> are working perfectly; and returning the proper json rpc error codes.
> So mootools or jquery would not make any difference here.
> The problem is the registration of the JSONRPC-Callable classes on the
> server.
>
> Perhaps the registration of your JSON-RPC plugin is happening too late for
> the JSONRPC-Manager.sessionCreated() to be picked up ?
> Maybe a logging of the c_gloablObjects in the JSONRPC-Manager may help to
> reveal a timing issues.
>
> Just my .02 cents,
>
>
> Feel free to share your java and js code on the dev mailbox.
>
> dirk
>
>
>
> On Sat, Feb 15, 2014 at 9:19 AM, Ichiro Furusato
> <ic...@gmail.com>wrote:
>
> > Hi Dirk,
> >
> > Yes, you're understanding what I'm trying to do. In addition to the
> plugin
> > I've
> > also been using a bespoke JSP page with scriptlets to prototype ideas
> > quickly,
> > as well as a JavaScriptPlugin we wrote years ago as a test bed. (That
> could
> > be submitted as a replacement for the JSPWiki plugin of the same name if
> > people are interested.)
> >
> > I have tried the 'domready' wrapper you suggested but that didn't seem to
> > make any difference, and given the amount of time I've now spent on this
> I
> > have to say that I'm likely going to abandon any AJAX-related work in the
> > JSPWiki space until it at some point as moved over to jQuery, and
> there's a
> > working RPCSamplePlugin. I've just run out of both steam and time.
> >
> > For now I'll probably try using some other approach than the
> JSONRPCManager
> > since I just can't get that to work. Perhaps Apache Wink or some kind of
> > lightweight RESTful client-server thing, dunno.
> >
> > Thanks very much for all your help,
> >
> > Ichiro
> >
>

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
Ichiro,

The issue is *not* client-side related ; actually the moo tools rpc-calls
are working perfectly; and returning the proper json rpc error codes.
So mootools or jquery would not make any difference here.
The problem is the registration of the JSONRPC-Callable classes on the
server.

Perhaps the registration of your JSON-RPC plugin is happening too late for
the JSONRPC-Manager.sessionCreated() to be picked up ?
Maybe a logging of the c_gloablObjects in the JSONRPC-Manager may help to
reveal a timing issues.

Just my .02 cents,


Feel free to share your java and js code on the dev mailbox.

dirk



On Sat, Feb 15, 2014 at 9:19 AM, Ichiro Furusato
<ic...@gmail.com>wrote:

> Hi Dirk,
>
> Yes, you're understanding what I'm trying to do. In addition to the plugin
> I've
> also been using a bespoke JSP page with scriptlets to prototype ideas
> quickly,
> as well as a JavaScriptPlugin we wrote years ago as a test bed. (That could
> be submitted as a replacement for the JSPWiki plugin of the same name if
> people are interested.)
>
> I have tried the 'domready' wrapper you suggested but that didn't seem to
> make any difference, and given the amount of time I've now spent on this I
> have to say that I'm likely going to abandon any AJAX-related work in the
> JSPWiki space until it at some point as moved over to jQuery, and there's a
> working RPCSamplePlugin. I've just run out of both steam and time.
>
> For now I'll probably try using some other approach than the JSONRPCManager
> since I just can't get that to work. Perhaps Apache Wink or some kind of
> lightweight RESTful client-server thing, dunno.
>
> Thanks very much for all your help,
>
> Ichiro
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Dirk,

Yes, you're understanding what I'm trying to do. In addition to the plugin
I've
also been using a bespoke JSP page with scriptlets to prototype ideas
quickly,
as well as a JavaScriptPlugin we wrote years ago as a test bed. (That could
be submitted as a replacement for the JSPWiki plugin of the same name if
people are interested.)

I have tried the 'domready' wrapper you suggested but that didn't seem to
make any difference, and given the amount of time I've now spent on this I
have to say that I'm likely going to abandon any AJAX-related work in the
JSPWiki space until it at some point as moved over to jQuery, and there's a
working RPCSamplePlugin. I've just run out of both steam and time.

For now I'll probably try using some other approach than the JSONRPCManager
since I just can't get that to work. Perhaps Apache Wink or some kind of
lightweight RESTful client-server thing, dunno.

Thanks very much for all your help,

Ichiro

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
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.furusato@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
> <di...@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
> > <ic...@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
> > >
> >
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
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
<di...@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
> <ic...@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
> >
>

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
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
<ic...@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
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
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

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
Hi Ichiro,

At the server side (java part) you should have something like this:

  ...

 JSONRPCManager.registerGlobalObject( "blah", new MyJSONBlahSample() );



 public class MyJSONBlahSample implements RPCCallable {


      // JSONRPC command => "blah.respond", [qv,5]

      public int getRespond( String firstStringParameter,
intsecondIntParameter ){


           ...


           return 99;   //return some result


      }

 }



At the client side (javascript), all you need is this:


 var qv = 'foo';
    Wiki.jsonrpc( 'blah.respond', [qv,5], function(result,exception) {
         console.log(result);

       ...
    }




The JSONRPCTarget thingie is not needed.

Hope this helps,



dirk




On Wed, Feb 12, 2014 at 11:15 AM, Ichiro Furusato <ichiro.furusato@gmail.com
> wrote:

> Hi Dirk,
>
> Well, I've now spent quite a lot of time trying to get this to work, to no
> avail.
>
> I've tried this within a plugin, then when I was unable to get that to work
> I went
> ahead and spot-modified a JSP to include a direct AJAX call. I was
> successful
> in emulating the existing search.findPages call, but when I transferred
> that same
> method signature to my own code (i.e., in my own package) it failed, with
> the
> same JSON error message I have always seen. I'm registering my own global
> class (which implements RPCCallable in the same way as SearchManager)
> but it just doesn't seem to be able to locate the globally-registered
> object. My
> package is part of the jars available to JSPWiki, as demonstrably other
> plugins
> from that jar work fine. I've even created a new class within the JSPWiki
> package
> hierarchy and tried that from within my JSP/AJAX test bed but still no
> luck.
>
> So I'm at a loss.
>
> To recap what I'm doing (unsuccessfully), I've created a JSONRPCTarget
> class (either within my own or JSPWiki's package hierarchy), which I then
> register via:
>
>     JSONRPCTarget target = new JSONRPCTarget();
>     JSONRPCManager.registerGlobalObject("blah",target);
>
> It contains a method similar to SearchManager#findPages() called respond()
> which returns a List, that I call via
>
>     var qv = 'foo';
>     Wiki.jsonrpc( 'blah.respond', [qv,5], function(result,exception) {
>         if ( !result.list ) {
>                return;
>         }
>        ...
>     }
>
> And it so far always hits that return statement, with the same error
> message:
>
>   {"id":10000,"error":{"code":591,"msg":"method not found (session may have
> timed out)"}}
>
> I thought for awhile that I might be a victim of the intermixing of
> Mootools and
> jQuery, but I've given up trying to use any jQuery within the JSPWiki
> environment
> (which is a problem for our plans for the next few months but that's a
> different
> issue), so this is either some problem with how the registry works or my
> ignorance
> in how this is supposed to work. Given I've tried so many different
> alternatives
> I'm at this point giving up, frustrated. Why this doesn't work remains a
> complete
> mystery to me. I'm obviously missing *something* fundamental here, but I've
> discussed this with a couple of people and none of us understands why this
> isn't
> working.
>
> What I'm wondering is if I could trouble you to look at the RPCSamplePlugin
> and
> see if you could get it to work. In theory it's supposed to be very simple.
> It currently
> uses the registerJSONObject() method in the JSONRPCManager, which is known
> to be broken (as it references the previously discussed, unavailable
> JSONRpcClient).
>
> If it were possible to get the RPCSamplePlugin to work using the global
> registry
> then it could be a functioning sample, something it currently isn't. And I
> could then
> use that as a model for what I'm doing.
>
> Thanks,
>
> Ichiro
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Dirk,

Well, I've now spent quite a lot of time trying to get this to work, to no
avail.

I've tried this within a plugin, then when I was unable to get that to work
I went
ahead and spot-modified a JSP to include a direct AJAX call. I was
successful
in emulating the existing search.findPages call, but when I transferred
that same
method signature to my own code (i.e., in my own package) it failed, with
the
same JSON error message I have always seen. I'm registering my own global
class (which implements RPCCallable in the same way as SearchManager)
but it just doesn't seem to be able to locate the globally-registered
object. My
package is part of the jars available to JSPWiki, as demonstrably other
plugins
from that jar work fine. I've even created a new class within the JSPWiki
package
hierarchy and tried that from within my JSP/AJAX test bed but still no
luck.

So I'm at a loss.

To recap what I'm doing (unsuccessfully), I've created a JSONRPCTarget
class (either within my own or JSPWiki's package hierarchy), which I then
register via:

    JSONRPCTarget target = new JSONRPCTarget();
    JSONRPCManager.registerGlobalObject("blah",target);

It contains a method similar to SearchManager#findPages() called respond()
which returns a List, that I call via

    var qv = 'foo';
    Wiki.jsonrpc( 'blah.respond', [qv,5], function(result,exception) {
        if ( !result.list ) {
               return;
        }
       ...
    }

And it so far always hits that return statement, with the same error
message:

  {"id":10000,"error":{"code":591,"msg":"method not found (session may have
timed out)"}}

I thought for awhile that I might be a victim of the intermixing of
Mootools and
jQuery, but I've given up trying to use any jQuery within the JSPWiki
environment
(which is a problem for our plans for the next few months but that's a
different
issue), so this is either some problem with how the registry works or my
ignorance
in how this is supposed to work. Given I've tried so many different
alternatives
I'm at this point giving up, frustrated. Why this doesn't work remains a
complete
mystery to me. I'm obviously missing *something* fundamental here, but I've
discussed this with a couple of people and none of us understands why this
isn't
working.

What I'm wondering is if I could trouble you to look at the RPCSamplePlugin
and
see if you could get it to work. In theory it's supposed to be very simple.
It currently
uses the registerJSONObject() method in the JSONRPCManager, which is known
to be broken (as it references the previously discussed, unavailable
JSONRpcClient).

If it were possible to get the RPCSamplePlugin to work using the global
registry
then it could be a functioning sample, something it currently isn't. And I
could then
use that as a model for what I'm doing.

Thanks,

Ichiro

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Dirk,

Thanks for that information. I suppose this goes back to that earlier
discussion about
jQuery vs. Mootools in a way. I've got (growing) experience with the former
and none
with the latter, and have been developing this new plugin using jQuery
since that goes
with pretty much all of the other JavaScript work I'm doing, hence some of
my confusion
in working with a blend of the two. If JSPWiki at some point converts over
to jQuery my
attempts at compatibility with Mootools would at that point need to be
updated to jQuery.

We might consider either modifying the JSONRPCManager, either to make it
compatible
with Mootools or at least document that the non-global methods that
reference the
nonexistent JSONRpcClient that won't work. Probably that's a low priority,
admittedly.

For now I'll go ahead and try to implement the AJAX functionality via the
method
you suggest, so thanks again for being so helpful.

Ichiro

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
Ichiro,

There is no need on the client-side to include a special JSONRpcClient
library to get
JSON-RPC to work.  Actually, the mootools library has all the functionality
you
need available, including JSON encoding and decoding and an easy JSON HTTP
Request API.

Invoking an RPC-JSON request in javascript can be done like this:
{{{
Wiki.jsonrpc( method, parms,  callback-function(result) );

Example:
Wiki.jsonrpc( method, parms,  function(result){ console.log(result);  });
}}}}
There is no need to register or initialize anything; all what you need is
done by Wiki.jsonrpc.


The rpc "method" name points to the java class implementing the server side
of the rpc protocol.
Today, JSPWiki supports following methods:
"search.suggestions", "search.findpages"  =>
 org.apache.wiki.search.SearchManager.java
"progressTracker.getProgress" => org.apache.wiki.ui.progress.ProgressManager

Both "managers" use the JSONRPCManager.registerGlobalObject() to register
the respective rpc method names, an the RCPCallable() methods.
(check out the java source-code to see how this is done)

Let me know if this gets you any further,

dirk



On Sat, Feb 1, 2014 at 1:34 PM, Ichiro Furusato
<ic...@gmail.com>wrote:

> Further investigation suggests a reason why the supporting JavaScript
> library
> for the requestJSON(WikiContext) method in the JSONRPCManager is not
> part of the extant code base or supporting libraries.
>
>     "var jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");
>
> In particular, the JSONRpcClient is not found anywhere. What I have found
> is that this class seems to be part of a jQuery-based library found at:
>
>     https://github.com/Textalk/jquery.jsonrpcclient.js
>
> This suggests that perhaps the person who wrote the JSONRPCManager
> might have envisaged its use with a jQuery-based environment rather than
> mootools. In any case, the global features of JSONRPCManager work
> (obviously) but the local ones are unsupported in the JavaScript.
>
> Ichiro
>
>
>
> On Fri, Jan 31, 2014 at 11:11 AM, Dirk Frederickx <
> dirk.frederickx@gmail.com
> > wrote:
>
> > Hi Ichiro,
> >
> > Here are a few quick pointers,  hope it can help your investigation.
> >
> > The jsonrpc invocation  javascript is located in jspwiki-common.js,
> around
> > line 400+
> > {{{
> > $jsonid : 10000,
> > jsonrpc: function(method, params, fn) {
> > new Ajax( Wiki.JsonUrl, {
> > postBody: Json.toString({"id":Wiki.$jsonid++, "method":method,
> > "params":params}),
> > method: 'post',
> > onComplete: function(result){
> > var r = Json.evaluate(result,true);
> > if(r){
> > if(r.result){ fn(r.result) }
> > else if(r.error){ fn(r.error) }
> > }
> > }
> > }).request();
> > }
> > }}}
> >
> > In this snippet, the *Wiki.JsonUrl* is retrieved from this snippet in
> > /template/default/commonheader.jsp
> > {{{
> > <meta name="wikiJsonUrl" content='<%=
> >  WikiContext.findContext(pageContext).getURL( WikiContext.NONE,
> "JSON-RPC"
> > ) %>' /><%--unusual pagename--%>
> > }}}
> > The JSON-parameters consist of a unique-id for each invocation, a method
> > directing to the server RPC java classes, and the method parameters. On
> > reception of the response, the resulting JSON is decoded, an the "result"
> > part is returned.
> >
> >
> >
> > You can find a few examples how to invoke the jsonrpc AJAX interface.
> > EG. the implementation of the 'quick- navigation' dropdown is based on
> > json-rpc.
> >
> > Around line 900+ in jspwiki-common.js, you can find following snippet:
> > {{{
> > Wiki.jsonrpc('search.findPages', [qv,20], function(result){
> > $('searchSpin').hide();
> > if(!result.list) return;
> > var frag = new Element('ul');
> >
> > result.list.each(function(el){
> > new Element('li').adopt(
> > new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page),
> > new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")")
> > ).inject(frag);
> > });
> > $('searchOutput').empty().adopt(frag);
> > Wiki.locatemenu( $('query'), $('searchboxMenu') );
> > });
> > }}}
> >
> > The corresponding server-side code is located in SearchManager.java.
> >
> > EXAMPLE of the RPC request message, looking for the string "test":
>  (check
> > out your browser's NETWORK console)
> > {{{
> >
> >    1. {"id":10000,"method":"search.findPages","params":["test",20]}:
> >
> > }}}
> >
> > EXAMPLE of the RPC response message:
> > {{{
> >
> >
> {"id":10000,"result":{"javaClass":"java.util.ArrayList","list":[{"map":{"page":"InsertPageTest","score":110},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTestSections","score":96},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTest_WithUnderscore","score":82},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiEventListener","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"CSSInWikipages","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchResultIteratorTag","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"IfPlugin","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchPageHelp","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiGardener","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"Wiki.Admin.Security","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"PhotoCollectionPlugin","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"Configuration","score":3},"javaClass":"java.util.HashMap"}]}}
> >
> > }}}
> >
> > Another example is the implementation of the progress bar for the upload
> of
> > attachements.
> > - javascript/client part : in JSPWiki-common.js around line  380+
> > - java/server part : ProgressManager.java
> >
> >
> > I assume by looking at both parts of the interface, you should be able to
> > understand the puzzle.
> >
> >
> >
> > good luck
> > dirk
> >
> >
> >
> >
> > On Thu, Jan 30, 2014 at 9:56 PM, Ichiro Furusato
> > <ic...@gmail.com>wrote:
> >
> > > Hi,
> > >
> > > I'm digging into an AJAX-related project that in theory should be using
> > > the org.apache.wiki.rpc.json.JSONRPCManager to register the callback
> > > used in JavaScript (i.e., via requestJSON(WikiContext)).
> > >
> > > This obviously is working as the search popup uses it, but the existing
> > > code seems broken. The JSONRPCManager spits out the following bit
> > > of JavaScript:
> > >
> > >   "jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");
> > >
> > > In my tests using a subclass of the RPCSamplePlugin, the above code
> > > flags two errors in Firebug, namely that the 'jsonrpc' variable hasn't
> > > been declared, and the JSONRpcClient class doesn't seem to exist
> > > anywhere in the JSPWiki code (nor can I find it in a JS library).
> > >
> > > Could someone point me to any documentation or examples of how to
> > > use the RPCSamplePlugin, as this doesn't seem to exist on even the
> > > old ecyrd site. Is this broken legacy code or am I just being daft and
> > > can't find something obvious?
> > >
> > > If I can manage to get an example of a JSON-RPC WikiPlugin going
> > > we'll share that code as part of our plugin package, which would help
> > > other developers do JSPWiki+AJAX work.
> > >
> > > Thanks for any assistance,
> > >
> > > Ichiro
> > >
> >
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Further investigation suggests a reason why the supporting JavaScript
library
for the requestJSON(WikiContext) method in the JSONRPCManager is not
part of the extant code base or supporting libraries.

    "var jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");

In particular, the JSONRpcClient is not found anywhere. What I have found
is that this class seems to be part of a jQuery-based library found at:

    https://github.com/Textalk/jquery.jsonrpcclient.js

This suggests that perhaps the person who wrote the JSONRPCManager
might have envisaged its use with a jQuery-based environment rather than
mootools. In any case, the global features of JSONRPCManager work
(obviously) but the local ones are unsupported in the JavaScript.

Ichiro



On Fri, Jan 31, 2014 at 11:11 AM, Dirk Frederickx <dirk.frederickx@gmail.com
> wrote:

> Hi Ichiro,
>
> Here are a few quick pointers,  hope it can help your investigation.
>
> The jsonrpc invocation  javascript is located in jspwiki-common.js, around
> line 400+
> {{{
> $jsonid : 10000,
> jsonrpc: function(method, params, fn) {
> new Ajax( Wiki.JsonUrl, {
> postBody: Json.toString({"id":Wiki.$jsonid++, "method":method,
> "params":params}),
> method: 'post',
> onComplete: function(result){
> var r = Json.evaluate(result,true);
> if(r){
> if(r.result){ fn(r.result) }
> else if(r.error){ fn(r.error) }
> }
> }
> }).request();
> }
> }}}
>
> In this snippet, the *Wiki.JsonUrl* is retrieved from this snippet in
> /template/default/commonheader.jsp
> {{{
> <meta name="wikiJsonUrl" content='<%=
>  WikiContext.findContext(pageContext).getURL( WikiContext.NONE, "JSON-RPC"
> ) %>' /><%--unusual pagename--%>
> }}}
> The JSON-parameters consist of a unique-id for each invocation, a method
> directing to the server RPC java classes, and the method parameters. On
> reception of the response, the resulting JSON is decoded, an the "result"
> part is returned.
>
>
>
> You can find a few examples how to invoke the jsonrpc AJAX interface.
> EG. the implementation of the 'quick- navigation' dropdown is based on
> json-rpc.
>
> Around line 900+ in jspwiki-common.js, you can find following snippet:
> {{{
> Wiki.jsonrpc('search.findPages', [qv,20], function(result){
> $('searchSpin').hide();
> if(!result.list) return;
> var frag = new Element('ul');
>
> result.list.each(function(el){
> new Element('li').adopt(
> new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page),
> new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")")
> ).inject(frag);
> });
> $('searchOutput').empty().adopt(frag);
> Wiki.locatemenu( $('query'), $('searchboxMenu') );
> });
> }}}
>
> The corresponding server-side code is located in SearchManager.java.
>
> EXAMPLE of the RPC request message, looking for the string "test":  (check
> out your browser's NETWORK console)
> {{{
>
>    1. {"id":10000,"method":"search.findPages","params":["test",20]}:
>
> }}}
>
> EXAMPLE of the RPC response message:
> {{{
>
> {"id":10000,"result":{"javaClass":"java.util.ArrayList","list":[{"map":{"page":"InsertPageTest","score":110},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTestSections","score":96},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTest_WithUnderscore","score":82},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiEventListener","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"CSSInWikipages","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchResultIteratorTag","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"IfPlugin","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchPageHelp","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiGardener","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"Wiki.Admin.Security","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"PhotoCollectionPlugin","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"Configuration","score":3},"javaClass":"java.util.HashMap"}]}}
>
> }}}
>
> Another example is the implementation of the progress bar for the upload of
> attachements.
> - javascript/client part : in JSPWiki-common.js around line  380+
> - java/server part : ProgressManager.java
>
>
> I assume by looking at both parts of the interface, you should be able to
> understand the puzzle.
>
>
>
> good luck
> dirk
>
>
>
>
> On Thu, Jan 30, 2014 at 9:56 PM, Ichiro Furusato
> <ic...@gmail.com>wrote:
>
> > Hi,
> >
> > I'm digging into an AJAX-related project that in theory should be using
> > the org.apache.wiki.rpc.json.JSONRPCManager to register the callback
> > used in JavaScript (i.e., via requestJSON(WikiContext)).
> >
> > This obviously is working as the search popup uses it, but the existing
> > code seems broken. The JSONRPCManager spits out the following bit
> > of JavaScript:
> >
> >   "jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");
> >
> > In my tests using a subclass of the RPCSamplePlugin, the above code
> > flags two errors in Firebug, namely that the 'jsonrpc' variable hasn't
> > been declared, and the JSONRpcClient class doesn't seem to exist
> > anywhere in the JSPWiki code (nor can I find it in a JS library).
> >
> > Could someone point me to any documentation or examples of how to
> > use the RPCSamplePlugin, as this doesn't seem to exist on even the
> > old ecyrd site. Is this broken legacy code or am I just being daft and
> > can't find something obvious?
> >
> > If I can manage to get an example of a JSON-RPC WikiPlugin going
> > we'll share that code as part of our plugin package, which would help
> > other developers do JSPWiki+AJAX work.
> >
> > Thanks for any assistance,
> >
> > Ichiro
> >
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Dirk,

Just a 'quick' question. Every example I can find uses the
JSONRPCManager.registerGlobalObject()
method, none (except the aforementioned RPCSamplePlugin) use the other
methods such as
registerJSONObject(WikiContext context, RPCCallable c) or
requestJSON(WikiContext context).
Indeed, my supposition is that the latter don't work, given that they
inevitably invoke a instantiation
of JSONRpcClient, which doesn't seem to exist anywhere in any of the
included libraries (at least
that I've been able to find).

I've written up a quick JavaScriptPlugin for testing purposes (which
obviously would be death to any
public wiki) so that I'm able to test out ideas, and it seems that the
"local" functionality (as opposed
to the global) in JSONRPCManager are broken. Is that correct? If so I don't
believe I can use the
AJAX features of it in a WikiPlugin -- I'd have to somehow mimic the caller
IDs and such on my own,
something I'd rather avoid.

Thanks,

Ichiro


On Fri, Jan 31, 2014 at 11:11 AM, Dirk Frederickx <dirk.frederickx@gmail.com
> wrote:

> Hi Ichiro,
>
> Here are a few quick pointers,  hope it can help your investigation.
>
> The jsonrpc invocation  javascript is located in jspwiki-common.js, around
> line 400+
> {{{
> $jsonid : 10000,
> jsonrpc: function(method, params, fn) {
> new Ajax( Wiki.JsonUrl, {
> postBody: Json.toString({"id":Wiki.$jsonid++, "method":method,
> "params":params}),
> method: 'post',
> onComplete: function(result){
> var r = Json.evaluate(result,true);
> if(r){
> if(r.result){ fn(r.result) }
> else if(r.error){ fn(r.error) }
> }
> }
> }).request();
> }
> }}}
>
> In this snippet, the *Wiki.JsonUrl* is retrieved from this snippet in
> /template/default/commonheader.jsp
> {{{
> <meta name="wikiJsonUrl" content='<%=
>  WikiContext.findContext(pageContext).getURL( WikiContext.NONE, "JSON-RPC"
> ) %>' /><%--unusual pagename--%>
> }}}
> The JSON-parameters consist of a unique-id for each invocation, a method
> directing to the server RPC java classes, and the method parameters. On
> reception of the response, the resulting JSON is decoded, an the "result"
> part is returned.
>
>
>
> You can find a few examples how to invoke the jsonrpc AJAX interface.
> EG. the implementation of the 'quick- navigation' dropdown is based on
> json-rpc.
>
> Around line 900+ in jspwiki-common.js, you can find following snippet:
> {{{
> Wiki.jsonrpc('search.findPages', [qv,20], function(result){
> $('searchSpin').hide();
> if(!result.list) return;
> var frag = new Element('ul');
>
> result.list.each(function(el){
> new Element('li').adopt(
> new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page),
> new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")")
> ).inject(frag);
> });
> $('searchOutput').empty().adopt(frag);
> Wiki.locatemenu( $('query'), $('searchboxMenu') );
> });
> }}}
>
> The corresponding server-side code is located in SearchManager.java.
>
> EXAMPLE of the RPC request message, looking for the string "test":  (check
> out your browser's NETWORK console)
> {{{
>
>    1. {"id":10000,"method":"search.findPages","params":["test",20]}:
>
> }}}
>
> EXAMPLE of the RPC response message:
> {{{
>
> {"id":10000,"result":{"javaClass":"java.util.ArrayList","list":[{"map":{"page":"InsertPageTest","score":110},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTestSections","score":96},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTest_WithUnderscore","score":82},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiEventListener","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"CSSInWikipages","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchResultIteratorTag","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"IfPlugin","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchPageHelp","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiGardener","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"Wiki.Admin.Security","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"PhotoCollectionPlugin","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"Configuration","score":3},"javaClass":"java.util.HashMap"}]}}
>
> }}}
>
> Another example is the implementation of the progress bar for the upload of
> attachements.
> - javascript/client part : in JSPWiki-common.js around line  380+
> - java/server part : ProgressManager.java
>
>
> I assume by looking at both parts of the interface, you should be able to
> understand the puzzle.
>
>
>
> good luck
> dirk
>
>
>
>
> On Thu, Jan 30, 2014 at 9:56 PM, Ichiro Furusato
> <ic...@gmail.com>wrote:
>
> > Hi,
> >
> > I'm digging into an AJAX-related project that in theory should be using
> > the org.apache.wiki.rpc.json.JSONRPCManager to register the callback
> > used in JavaScript (i.e., via requestJSON(WikiContext)).
> >
> > This obviously is working as the search popup uses it, but the existing
> > code seems broken. The JSONRPCManager spits out the following bit
> > of JavaScript:
> >
> >   "jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");
> >
> > In my tests using a subclass of the RPCSamplePlugin, the above code
> > flags two errors in Firebug, namely that the 'jsonrpc' variable hasn't
> > been declared, and the JSONRpcClient class doesn't seem to exist
> > anywhere in the JSPWiki code (nor can I find it in a JS library).
> >
> > Could someone point me to any documentation or examples of how to
> > use the RPCSamplePlugin, as this doesn't seem to exist on even the
> > old ecyrd site. Is this broken legacy code or am I just being daft and
> > can't find something obvious?
> >
> > If I can manage to get an example of a JSON-RPC WikiPlugin going
> > we'll share that code as part of our plugin package, which would help
> > other developers do JSPWiki+AJAX work.
> >
> > Thanks for any assistance,
> >
> > Ichiro
> >
>

Re: JSON-RPC support

Posted by Ichiro Furusato <ic...@gmail.com>.
Hi Dirk,

I'm sure it'll take me awhile to figure this out, but thanks very much for
the pointers -- exactly what I was looking for!

Cheers,

Ichiro



On Fri, Jan 31, 2014 at 11:11 AM, Dirk Frederickx <dirk.frederickx@gmail.com
> wrote:

> Hi Ichiro,
>
> Here are a few quick pointers,  hope it can help your investigation.
>
> The jsonrpc invocation  javascript is located in jspwiki-common.js, around
> line 400+
> {{{
> $jsonid : 10000,
> jsonrpc: function(method, params, fn) {
> new Ajax( Wiki.JsonUrl, {
> postBody: Json.toString({"id":Wiki.$jsonid++, "method":method,
> "params":params}),
> method: 'post',
> onComplete: function(result){
> var r = Json.evaluate(result,true);
> if(r){
> if(r.result){ fn(r.result) }
> else if(r.error){ fn(r.error) }
> }
> }
> }).request();
> }
> }}}
>
> In this snippet, the *Wiki.JsonUrl* is retrieved from this snippet in
> /template/default/commonheader.jsp
> {{{
> <meta name="wikiJsonUrl" content='<%=
>  WikiContext.findContext(pageContext).getURL( WikiContext.NONE, "JSON-RPC"
> ) %>' /><%--unusual pagename--%>
> }}}
> The JSON-parameters consist of a unique-id for each invocation, a method
> directing to the server RPC java classes, and the method parameters. On
> reception of the response, the resulting JSON is decoded, an the "result"
> part is returned.
>
>
>
> You can find a few examples how to invoke the jsonrpc AJAX interface.
> EG. the implementation of the 'quick- navigation' dropdown is based on
> json-rpc.
>
> Around line 900+ in jspwiki-common.js, you can find following snippet:
> {{{
> Wiki.jsonrpc('search.findPages', [qv,20], function(result){
> $('searchSpin').hide();
> if(!result.list) return;
> var frag = new Element('ul');
>
> result.list.each(function(el){
> new Element('li').adopt(
> new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page),
> new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")")
> ).inject(frag);
> });
> $('searchOutput').empty().adopt(frag);
> Wiki.locatemenu( $('query'), $('searchboxMenu') );
> });
> }}}
>
> The corresponding server-side code is located in SearchManager.java.
>
> EXAMPLE of the RPC request message, looking for the string "test":  (check
> out your browser's NETWORK console)
> {{{
>
>    1. {"id":10000,"method":"search.findPages","params":["test",20]}:
>
> }}}
>
> EXAMPLE of the RPC response message:
> {{{
>
> {"id":10000,"result":{"javaClass":"java.util.ArrayList","list":[{"map":{"page":"InsertPageTest","score":110},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTestSections","score":96},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTest_WithUnderscore","score":82},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiEventListener","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"CSSInWikipages","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchResultIteratorTag","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"IfPlugin","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchPageHelp","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiGardener","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"Wiki.Admin.Security","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"PhotoCollectionPlugin","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"Configuration","score":3},"javaClass":"java.util.HashMap"}]}}
>
> }}}
>
> Another example is the implementation of the progress bar for the upload of
> attachements.
> - javascript/client part : in JSPWiki-common.js around line  380+
> - java/server part : ProgressManager.java
>
>
> I assume by looking at both parts of the interface, you should be able to
> understand the puzzle.
>
>
>
> good luck
> dirk
>
>
>
>
> On Thu, Jan 30, 2014 at 9:56 PM, Ichiro Furusato
> <ic...@gmail.com>wrote:
>
> > Hi,
> >
> > I'm digging into an AJAX-related project that in theory should be using
> > the org.apache.wiki.rpc.json.JSONRPCManager to register the callback
> > used in JavaScript (i.e., via requestJSON(WikiContext)).
> >
> > This obviously is working as the search popup uses it, but the existing
> > code seems broken. The JSONRPCManager spits out the following bit
> > of JavaScript:
> >
> >   "jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");
> >
> > In my tests using a subclass of the RPCSamplePlugin, the above code
> > flags two errors in Firebug, namely that the 'jsonrpc' variable hasn't
> > been declared, and the JSONRpcClient class doesn't seem to exist
> > anywhere in the JSPWiki code (nor can I find it in a JS library).
> >
> > Could someone point me to any documentation or examples of how to
> > use the RPCSamplePlugin, as this doesn't seem to exist on even the
> > old ecyrd site. Is this broken legacy code or am I just being daft and
> > can't find something obvious?
> >
> > If I can manage to get an example of a JSON-RPC WikiPlugin going
> > we'll share that code as part of our plugin package, which would help
> > other developers do JSPWiki+AJAX work.
> >
> > Thanks for any assistance,
> >
> > Ichiro
> >
>

Re: JSON-RPC support

Posted by Dirk Frederickx <di...@gmail.com>.
Hi Ichiro,

Here are a few quick pointers,  hope it can help your investigation.

The jsonrpc invocation  javascript is located in jspwiki-common.js, around
line 400+
{{{
$jsonid : 10000,
jsonrpc: function(method, params, fn) {
new Ajax( Wiki.JsonUrl, {
postBody: Json.toString({"id":Wiki.$jsonid++, "method":method,
"params":params}),
method: 'post',
onComplete: function(result){
var r = Json.evaluate(result,true);
if(r){
if(r.result){ fn(r.result) }
else if(r.error){ fn(r.error) }
}
}
}).request();
}
}}}

In this snippet, the *Wiki.JsonUrl* is retrieved from this snippet in
/template/default/commonheader.jsp
{{{
<meta name="wikiJsonUrl" content='<%=
 WikiContext.findContext(pageContext).getURL( WikiContext.NONE, "JSON-RPC"
) %>' /><%--unusual pagename--%>
}}}
The JSON-parameters consist of a unique-id for each invocation, a method
directing to the server RPC java classes, and the method parameters. On
reception of the response, the resulting JSON is decoded, an the "result"
part is returned.



You can find a few examples how to invoke the jsonrpc AJAX interface.
EG. the implementation of the 'quick- navigation' dropdown is based on
json-rpc.

Around line 900+ in jspwiki-common.js, you can find following snippet:
{{{
Wiki.jsonrpc('search.findPages', [qv,20], function(result){
$('searchSpin').hide();
if(!result.list) return;
var frag = new Element('ul');

result.list.each(function(el){
new Element('li').adopt(
new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page),
new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")")
).inject(frag);
});
$('searchOutput').empty().adopt(frag);
Wiki.locatemenu( $('query'), $('searchboxMenu') );
});
}}}

The corresponding server-side code is located in SearchManager.java.

EXAMPLE of the RPC request message, looking for the string "test":  (check
out your browser's NETWORK console)
{{{

   1. {"id":10000,"method":"search.findPages","params":["test",20]}:

}}}

EXAMPLE of the RPC response message:
{{{
{"id":10000,"result":{"javaClass":"java.util.ArrayList","list":[{"map":{"page":"InsertPageTest","score":110},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTestSections","score":96},"javaClass":"java.util.HashMap"},{"map":{"page":"InsertPageTest_WithUnderscore","score":82},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiEventListener","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"CSSInWikipages","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchResultIteratorTag","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"IfPlugin","score":10},"javaClass":"java.util.HashMap"},{"map":{"page":"SearchPageHelp","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"WikiGardener","score":8},"javaClass":"java.util.HashMap"},{"map":{"page":"Wiki.Admin.Security","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"PhotoCollectionPlugin","score":3},"javaClass":"java.util.HashMap"},{"map":{"page":"Configuration","score":3},"javaClass":"java.util.HashMap"}]}}

}}}

Another example is the implementation of the progress bar for the upload of
attachements.
- javascript/client part : in JSPWiki-common.js around line  380+
- java/server part : ProgressManager.java


I assume by looking at both parts of the interface, you should be able to
understand the puzzle.



good luck
dirk




On Thu, Jan 30, 2014 at 9:56 PM, Ichiro Furusato
<ic...@gmail.com>wrote:

> Hi,
>
> I'm digging into an AJAX-related project that in theory should be using
> the org.apache.wiki.rpc.json.JSONRPCManager to register the callback
> used in JavaScript (i.e., via requestJSON(WikiContext)).
>
> This obviously is working as the search popup uses it, but the existing
> code seems broken. The JSONRPCManager spits out the following bit
> of JavaScript:
>
>   "jsonrpc = new JSONRpcClient(\"" + jsonurl + "\");");
>
> In my tests using a subclass of the RPCSamplePlugin, the above code
> flags two errors in Firebug, namely that the 'jsonrpc' variable hasn't
> been declared, and the JSONRpcClient class doesn't seem to exist
> anywhere in the JSPWiki code (nor can I find it in a JS library).
>
> Could someone point me to any documentation or examples of how to
> use the RPCSamplePlugin, as this doesn't seem to exist on even the
> old ecyrd site. Is this broken legacy code or am I just being daft and
> can't find something obvious?
>
> If I can manage to get an example of a JSON-RPC WikiPlugin going
> we'll share that code as part of our plugin package, which would help
> other developers do JSPWiki+AJAX work.
>
> Thanks for any assistance,
>
> Ichiro
>