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/02/01 01:09:50 UTC

Re: JSON-RPC support

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
> >
>