Show TOC

Example: Sending a JSON Request Using a REST Web Service ClientLocate this document in the navigation structure

Use a JSON request to insert a record into a window in the ESP project.

Prerequisites

  • Install the ESP REST Provider.
  • Perform all steps outlined in Configuring the SAP Event Stream Processor REST Provider.
  • Install and configure a REST Web service client.
  • Start the ESP Server.
    Note You can send gzip format compressed data HTTP requests to the REST provider by setting the Content-Encoding HTTP header field to gzip. For example, Content-Encoding: gzip. Ensure that the request body is encoded with gzip.

Procedure

  1. Use the wsp.bat or wsp.sh script in %STREAMING_HOME%\wsp to start the JETTY server and initialize the REST port.
  2. Open the ESP Studio and create a new project with a name of your choice.
  3. Double-click the project configuration file (<yourprojectname>.ccr) to open the CCR Project Configuration editor. Include the following in your CCL file:
    CREATE INPUT WINDOW window1 
    SCHEMA (booleanField boolean, integerField integer, longField long, stringField string, doubleField float,  timestampField msdate, dateField seconddate, bigdateField bigdatetime, intervalField interval, binaryField BINARY, money1Field money(1), money2Field money(2), money3Field money(3), money4Field money(4), money5Field money(5), money6Field money(6), money7Field money(7), money8Field money(8), money9Field money(9), money10Field money(10), money11Field money(11), money12Field money(12), money13Field money(13), money14Field money(14), money15Field money(15)) 
    PRIMARY KEY (integerField);
  4. Select the Advanced tab.
  5. Set the value of the Web Service Enabled option to true in the Project Deployment Details window.
  6. Save the updated ccr file.
    The <yourprojectname>.ccr file now has an entry, <Option name="ws-enabled" value="true"/>, to show that Web service accessibility is enabled.
  7. If the project is started, for the changes to take effect, use Studio or streamingclusteradmin to stop and remove the project from the node, then redeploy (add) the project. Or restart the cluster on which the project runs.
  8. Send the following JSON request using your REST client:

    Type: POST

    Header
    http://<serverName>:9091/espws/restservice/stream/window1?action=insert&workspace=default&project=project1 
    Body
    {
        "connectionDetails": {
            "clusterName": "<serverName>",
            "port": "19011",
    
            "authentication": {
                "type": "user",
                "data": "<espUserName>:<password>",
                "sslEnabled": "true"
            }
        },
        "content": {
            "booleanField": "true",
            "integerField": "1",
            "longField": "12345",
            "stringField": "abcd",
            "doubleField": "12345",
            "timestampField": "2013-07-16 03:25:10.111",
            "dateField": "2013-07-16 15:25:10.111",
            "bigdateField": "2013-08-24T09:45:23.543221",
            "intervalField": "1234",
            "binaryField": "17",
            "money1Field": "10.1",
            "money2Field": "10.12",
            "money3Field": "10.123",
            "money4Field": "10.1234",
            "money5Field": "10.12345",
            "money6Field": "10.123456",
            "money7Field": "10.1234567",
            "money8Field": "10.12345678",
            "money9Field": "10.123456789",
            "money10Field": "10.1234567891",
            "money11Field": "10.12345678912",
            "money12Field": "10.123456789123",
            "money13Field": "10.1234567891234",
            "money14Field": "10.12345678912345",
            "money15Field": "10.123456789123456"
        }
    }
    

Results

A new record is added to the window window1 in Studio.