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

Reply via email to