briandilley/jsonrpc4j

how to invoke class specific method json rpc 4

Opened this issue · 2 comments

I am going through document provided by vendor they have given python code

  params = {'query':'name = \'ABC \''}
   list = server.call(session, 'class.A', 'search', params)

I have to do same thing in java using this library so I have written something like this

    List<String> list =  a.rpcCall("class.A.search",new Object[]{"query":"name = \'ABC \'"},List.class);
    private <T> T rpcCall(String methodName, Object[] object,Class<T> classtype) {
    T classList = null;
    	
    	try {
    		classList=	 client.invoke(methodName, object,classtype);
    	} catch (Throwable e) {
    		// TODO Auto-generated catch block
    		e.printStackTrace();
    	}
    	
    	return classList;
}

but I got exception like this

com.googlecode.jsonrpc4j.JsonRpcClientException: Method not implemented: class.A.search
at com.googlecode.jsonrpc4j.DefaultExceptionResolver.createJsonRpcClientException(DefaultExceptionResolver.java:53)
at com.googlecode.jsonrpc4j.DefaultExceptionResolver.resolveException(DefaultExceptionResolver.java:28)
at com.googlecode.jsonrpc4j.JsonRpcClient.handleErrorResponse(JsonRpcClient.java:270)
at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:196)
at com.googlecode.jsonrpc4j.JsonRpcClient.readResponse(JsonRpcClient.java:529)
at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:148)
at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:118)
at com.googlecode.jsonrpc4j.JsonRpcHttpClient.invoke(JsonRpcHttpClient.java:176)
at Autheticate.rpcCall(Autheticate.java:58)
at Autheticate.main(Autheticate.java:47)

please let me know how to invoke class specific method in rpc and how to pass session id ?

Hi @vihang16,

I'm not sure I understand what you mean by 'invoke class specific method'. Generally, the JSON-RPC works by mapping a class to some remote 'service' object that exposes a set of methods. Those methods are addressable via the method parameter in the JSON body. JSONRPC4J does this mapping for you when you create a client. In your case, is 'class.A' the service that you're calling methods on or is it some class with a method called A that you'd like to call?

Hi Sorry I totally missed this one.actually vendor has given this example in python. in my case class A is my class name and search is the method name.