jspwiki-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Frederickx <dirk.frederi...@gmail.com>
Subject Re: JSON-RPC support
Date Thu, 30 Jan 2014 22:11:02 GMT
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,
method: 'post',
onComplete: function(result){
var r = Json.evaluate(result,true);
if(r.result){ fn(r.result) }
else if(r.error){ fn(r.error) }

In this snippet, the *Wiki.JsonUrl* is retrieved from this snippet in
<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

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

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+")")
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:


Another example is the implementation of the progress bar for the upload of
- 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

On Thu, Jan 30, 2014 at 9:56 PM, Ichiro Furusato

> 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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message