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.frederi...@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 > <ichiro.furus...@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 > > >