json-rpc

Downloads

Source and binary

json-httpd_0.7.0.tar.gz json-httpd_0.7.0.zip

Running

To run the software as a standalone webserver:

java -jar jars/json-httpd.jar

The webserver will look in the working directory for a folder namned webroot for its contents

Creating the webserver

// Create server at port 8080. httpd = new HTTPServer(8080, 20); // Add an service. httpd.addService(new ExampleService()); // Start the server httpd.start();

Writing a JSON-RPC Service


  1. Create a class.
  2. Create a method that takes arguments of type String, int, long, float or doble, return value should be a JSON formated string.
  3. Add the @JsonServiceMethod annotation to the method.
  4. Write the code and generate a JSON formated return value with the JSONWriter class. (For more info about JSONWriter check http://www.stringtree.org/stringtree-json.html).

Example JSON-RPC Service:

public class ExampleService { @JsonServiceMethod public String log(double log) { JSONWriter writer = new JSONWriter(); return writer.write(Math.log10(log)); } }
SourceForge.net Logo