jnan77 / jsonrpc4j

Automatically exported from code.google.com/p/jsonrpc4j
0 stars 0 forks source link

Support method dot-notation services #41

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
While it is not part of the JSON-RPC 2.0 specification, it has become common 
practice (some might even say "best practice") to expose services using a 
"dot-notation" method name.   Here are some examples:

http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v4
http://www.zabbix.com/wiki/doc/api
http://support.mashery.com/docs/read/mashery_api/20/JSON_RPC

Using XMBC as an example, they expose service methods such as 
"AudioLibrary.GetAlbums".  Using jsonrpc4j exposing services in this way is not 
possible.  It is possible to aggregate multiple Java interfaces into a single 
service endpoint, but this makes for a "wide" and flat API, and there are 
issues if two interfaces exposes a method with the same signature.  A second 
solution is to use multiple endpoint URLS, for example, 
"http://<host>/rest/AudioLibrary" and "http://<host>/rest/Player".  However, 
this presents it own issues in that clients must often use two connections, 
each requiring separate authentication.

The attached patch adds a new class to jsonrpc4j called JsonRpcMultiServer, 
which extends JsonRpcServer.
The usage pattern for JsonRpcMultiServer goes like this:

 JsonRpcMultiServer rpcServer = new JsonRpcMultiServer();
 rpcServer.addService("Foo", new FooService())
               .addService("Bar", new BarService());

Minor changes were made to JsonRpcServer to make this possible.  For the above 
case, the request payload might look something like this:

{
    "jsonrpc": "2.0",
    "method": "Foo.test",
    "params": ["some", "thing"],
    "id": 1
}

This patch in no way affects the standard usage pattern of JsonRpcServer 
itself, and all unit tests pass without issue.  We would like to see this patch 
integrated into jsonrpc4j.  Note, the attached patch includes the code patch 
for issue#37.  Included in the patch is an additional unit test for 
JsonRpcMultiServer.  The patch file can be applied and reviewed in Eclipse by 
right-clicking on the top-level project and selecting Team->Apply patch.

Original issue reported on code.google.com by brett.wo...@gmail.com on 25 Oct 2012 at 7:28

Attachments:

GoogleCodeExporter commented 8 years ago
Great job! Thanks!

Original comment by denis.schelkunov@gmail.com on 29 Oct 2012 at 1:41

GoogleCodeExporter commented 8 years ago
I'd really like to see the spring support updated for this as well.  I'll 
include it in the next release regardless

Original comment by brian.di...@gmail.com on 28 Nov 2012 at 7:57

GoogleCodeExporter commented 8 years ago
included in next release, good work.

Original comment by brian.di...@gmail.com on 28 Nov 2012 at 8:22

GoogleCodeExporter commented 8 years ago
Unfortunately (or fortunately depending on your perspective), I'm not a 
"spring" guy and haven't touched it in about 5 years, so I'm not sure what 
spring support would entail.

Original comment by brett.wo...@gmail.com on 29 Nov 2012 at 9:06