Getting Started


     For the sake of simplicity we'll start with writing a famous Hello World remote service. The first thing you should do is creating a web project in your IDE and including SRV1.5.0.jar and Apache's commons-logging.jar in your web project. Then place SR listener and Request Response servlet in your web.xml configuration file by fallowing Installation Guide. 

   SR doesn't enforce you how to write a service. It's all about converting existing things to remote services. Let's say you already have a class like following in your project.

package test.bean;

public class HelloWorldBean {

    public String sayHelloWorld(){
        return "Hello World";
    public String salute(String name){
        return "Hello " + name;

   As you can remember we put a configuration files parameter in our web.xml file as following:

        <description>SR Config Files</description>

   This parameter definition says that our configuration files are located in WEB-INF directory which starts with "SR" and ends with ".xml". Let's create a configuration file under WEB-INF directory as following.


<?xml version="1.0" encoding="UTF-8"?>
 <!-- Sample SR Config file -->
<Config xmlns:xsi=""
        <Service name="helloWorldService" target="test.bean.HelloWorldBean">
           <Operation pattern="sa.*" />

     That's it. Our service is now ready to accept remote messages. We exposed our bean's methods which start with "sa" as "helloWorldService" .

Direct HTTP Get/Post

   Enter      "http://yourserver/yourwebproject/JSONRR/helloWorldService/sayHelloWorld" in your browser address bar and make your first call. It's that simple to call your services with HTTP GET.  

  "http://yourserver/yourwebproject/JSONRR/helloWorldService/salute?params="My Name"" url calls your salute method with "My Name" parameter. Parameters of your methods can be send as comma seperated values in "params" parameter. Id of your message is not required for your direct http calls. The server will made one for you if you don't send it. Identity paramater can be send in as "id" url parameter.

  Headers also can be send in "header" parameter. Thus your url turns to "http://yourserver/yourwebproject/JSONRR/helloWorldService/sayHelloWorld?params=&id="A1"&header="headerField1": "headerVal","headerField2": "headerVal" " and gives you a message like below:

  {"id":"A1","result":"Hello World","header":{"headerField1":"headerVal","headerField2":"headerVal"}}

  Direct HTTP POST calls are also accepted, so you can design simple forms in your html pages and post them to your services.

Java Client

     Writing  a java client for your remote services as simple as writing services. The first thing you should do is adding SRClient.jar in your classpath. Then call your service as follow:


public class HelloWorldServiceClient {

    public static void main(String[] args) {

        JSONRRClient client= new JSONRRClient("http://yourserver/yourwebproject/JSONRR");
        JSONResponse resp= client.callAService("helloWorldService","sayHelloWorld", null, null);
        if( ! resp.hasError()) {
        }else {
             System.out.println(resp.getErrorMessage() );


     One imported thing that you should know is getting direct result JSONResponse is valid only for simple java types. For complex type like beans you may need to convert result to
java object type by using transformers:
    JSTransformer transformer = new JSTransformer();
    BeanA result = (BeanA ) transformer.toJava(resp.getResult());

    If you don't prefer to have result as java you can always get your complex types as JSON object.

    JSONObject result = resp.getResult();

    JSONObject is also offers convenient methods  to access your bean properties.

   The framework also offers HTTP Form java implementation to make direct HTTP calls, form class can be used for html form simulations.

           HttpForm httpForm= new HttpForm();

           String BASE_URL = "http://localhost:8080/sr/JSONRR";

           JSTransformer transformer = new JSTransformer();

            httpForm.putFieldValue(HttpForm.FIELD_PARAMS, "\"test\"");
            HttpFormResponse rawResp = httpForm.get(BASE_URL+"/echoBean/echo");
            JSONResponse resp = new JSONResponse(rawResp.getResponseData());
            assertEquals("test", resp.getResult());

Java Script Client

    The project comes with two java script files that you need to include your pages as described in installation guide. UUID generator library also recommended generating and placing unique identifiers in your messages. Then creating JSONRequest object and using its send method would be enough to access your services as following.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <title>SR Sample JS Client</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript" language="JavaScript" src="./jslib/XMLHttpRequest.js"></script>
    <script type="text/javascript" language="JavaScript" src="./jslib/JSONRequest.js"></script>
    <script type="text/javascript" language="JavaScript" src="./jslib/UUID.js"></script>

    <script type="text/javascript">
        function print(s)
        var jsonurl = "/sr/JSONRR";
        var jsonrq = null;
        var uuid = null;
       try {
            jsonrq = new JSONRequest(jsonurl);
            uuid = new UUID();
        } catch(e) {
            if(e.message) alert(e.message);
            else alert(e);
        print("Calling service");
        print(" returns " + jsonrq.send(id,"helloWorldService.sayHello"));