I also like JSON-RPC for looser coupling between client and server.
Still, in order to do RPC you need to expose at least some information
about the object you are talking to.
So if you know the server class' methods and their parameters, this is
already an interface description. Now using this information it could be
possible to generate Java interface file, something along the lines of
WSDL->proxy class compilers in SOAP implementaitons. Is this something
that may help?
I for one like the fact I can use Java interface as "protocol
definition". BTW, client and server definitions does not have to be 100%
in sync. In many cases, older clients may be able to talk to newer
servers and vise versa.
Also, could you give more information about your use case?
Thanks,
-- Sasha
Rhino "native" client / JavaScript client = Java "native" method / Java methodYour project looks interesting; if you can give me a working example of what you are trying to achieve using the (non-efficient) JavaScript implementation of proxy I can take a stab at making more efficient native implementation in Java. Should be pretty straightforward.
Hi Sasha, thanks for the reply. My use case might be a little bit unique, although I feel that removing the necessity to have the interface class files available on the client may help in other situations as well. I'm in the process of developing a kind of universal client which allows for the display of rich user interfaces (http://www.uidl.net). This client includes a Rhino JavaScript interpreter and downloads scripts containing the UI code from a server (as per HTML for a browser but for complex UIs). I would like to use JSON-RPC to transparently call server side objects from thir JavaScript proxies on the client. I can do this if I use the JavaScript JSON-RPC client from within Rhino, although this isn't efficient. I'd prefer to be able to use a native Java JSON-RPC client to retreive the Java proxies and then just get Rhino to expose them as JavaScript equivalents. As you suggest, we have the interface information available. In fact, this is how the standard (JavaScript) client constructs proxies. It issues a request when it loads of the type: {"id": 1, "params": [], "method": "system.listMethods"} ... and the server responds with a response like: {"id":1,"result": ["serviceTranslationManager.translateAllLocal","productManager.isEnabled","serviceManager.getAllServices","serviceTranslationManager.getNonTranslatedCriterium","productManager.getHibernateTemplate","serviceTranslationManager.translate","serviceManager.getSessionFactory","serviceManager.getHibernateTemplate","productManager.afterPropertiesSet","productManager.setHelpDeskManager","serviceManager.setEnabled","productTranslationManager.translateLocal","productManager.getEnabledProducts","productTranslationManager.translate","serviceTranslationManager.afterPropertiesSet","serviceManager.update","serviceTranslationManager.setTranslation","serviceManager.setHibernateTemplate","companyManager.getCompanyName","serviceManager.setSessionFactory","productTranslationManager.translateAll","serviceManager.setHelpDeskManager","serviceTranslationManager.setHibernateTemplate","productTranslationManager.translateAllLocal","serviceManager.getService","serviceTranslationManager.getHibernateTempl ate","serviceTranslationManager.setType","productManager.setEnabled","serviceTranslationManager.setProductManager","productManager.update","serviceManager.afterPropertiesSet","serviceTranslationManager.getProductList","productTranslationManager.afterPropertiesSet","serviceTranslationManager.getNonUniqueCriteriumNames","serviceManager.getProduct","companyManager.setHelpDeskManager","productTranslationManager.getSessionFactory","productManager.getProduct","companyManager.loadCompanies","serviceManager.getEnabledServices","productTranslationManager.setType","productManager.getSessionFactory","serviceManager.getAllProducts","productManager.setSessionFactory","companyManager.loadCompany","productManager.getAllProducts","productTranslationManager.getHibernateTemplate","productTranslationManager.getProductList","serviceTranslationManager.translateLocal","serviceTranslationManager.setSessionFactory","productManager.setHibernateTemplate","productTranslationManager.setSessionFactory"," productTranslationManager.setHibernateTemplate","productTranslationManager.removeTranslation","serviceManager.isEnabled","serviceTranslationManager.getSessionFactory","serviceTranslationManager.removeTranslation","serviceTranslationManager.translateAll","productTranslationManager.setTranslation","productTranslationManager.setProductManager","productTranslationManager.getNonUniqueCriteriumNames","serviceManager.getEnabledProducts","productTranslationManager.getNonTranslatedCriterium"]} As far as I can see, the json-rpc-client Java client doesn't use this "self describing" functionality of the JSON-RPC server. Ideally, it would be good to use this information to help construct the Java proxy objects so that we don't need to supply the interface class files to the client. The reason that I don't want the client to need the class files for the interfaces to the server implementation objects is that this means my "universal client" isn't so universal any more. I do have the ability to dynamically load class or JAR files from the server (within my client) although I don't really want developers to need to worry about generating complex ANT build files which separate out only the class files which may be required by the client. Ideally it should be as simple as registering any POJO on the server and then referencing it on a client. Regards, Dominic. On Dec 11, 10:46 pm, sasha...@gmail.com wrote:
Surely it would be possible in Java as well to construct an object dynamically based on the metadata we can retrieve from the JSON-RPC server?
RemoteObject myObject= client.openProxy("myObject");
Result1 result1= (Result1)myObject.call("method1", param1, param2);
myObject.call("method2");
Anyway, again, I don't really require this for my project and I'm just being pedantic. As for the dynamic construction of Rhino ScriptableObjects, is this something that you would be willing to help with?