Full example of a simple Server

524 views
Skip to first unread message

Nachtwind

unread,
Dec 24, 2012, 9:06:59 PM12/24/12
to json...@googlegroups.com
Hi, 
I am currently trying to implement a rudimentary JSON RPC server in small java application but as unexperienced as i am i seem to be unable to do it right..
Therefore i wonder if someone could post a simple Hello World example that would just start a JSON RPC Server without spring or web.xml file..
Currently i try this code:

[code]
 ////////////////////////////////
       // RPC COde
       ///////////////////////////////


       RPCService uRPCService = new RPCService() {
public int getBlocks() {
// TODO Auto-generated method stub
return 0;
}
public int getBalance() {
// TODO Auto-generated method stub
return 0;
}
};
       
       Object compositeService = ProxyUtil.createCompositeServiceProxy(
           this.getClass().getClassLoader(),
           new Object[] { uRPCService},
           new Class<?>[] { RPCService.class},
           true);

       // now compositeService can be used as any of the above service, ie:
       int bal = (((RPCService) compositeService).getBalance());
       
       
       JsonRpcServer jsonRpcServer = new JsonRpcServer( compositeService );

       // create the stream server
       int maxThreads = 50;
       int port = 1420;
       InetAddress bindAddress = InetAddress.getByName("localhost");
       
       StreamServer streamServer = new StreamServer(jsonRpcServer, maxThreads, port, 0, bindAddress);

       // start it, this method doesn't block
       streamServer.start();
       
       ///////////////////////////////////
       /// RPC CODE
       ///////////////////////////////////
[/code]

inside my main() function.. but unfortunately it doesnt work at all...
So would someone be able to somehow post a simple program or snippet to start an RPC Server and how to implement ones own functions? 

THanks in advance
Nachtwind

Dennis Gearon

unread,
Mar 28, 2013, 11:49:41 PM3/28/13
to json...@googlegroups.com
I to would like to see a full plentation. just 1 pojo, accessed from localhost and wvery error tested, with a s we t of curl commands
Reply all
Reply to author
Forward
0 new messages