Defining the StringServlet response

The ResponseBody component of the StringServlet configures a response to be sent back to the remote client. This comes with a DefaultResponse component, which has slots for the body string (Data), and Response Code.
Prerequisites: A StringServlet exists in the station. The httpClient palette is open.
  1. Double-click the StringServlet and expand Response Body.
    The Response Body properties open.
    Image
  2. To add one or more alternative responses, drag a ConditionalResponse component from the palette to the Response Body folder and double-click the ConditionalResponse component.
    The response properties open.
    Image
  3. Enter an alternative Data property and Response Code.
    This example links the output of a JSONSchema component to the Data slot. For this ConditionalResponse to be used, some conditions must be defined. Several example conditions are available in the palette:
    Image
  4. Expand IncomingRequests > ConditionalResponse > Conditions and drag a condition, such as BodyContains from the palette to the Conditions folder under ConditionalResponse and double-click the condition.
    The condition’s properties open.
    Image
  5. Set the Not value to true.
    This negates the defined logic.

    If you have multiple conditions defined, the default logic requires that all must be true. Set the And slot to false and only one of the conditions needs to be true.

  6. To configure a response report, enter a filename for Report Name and define the file extension using the Report File Ext property.
    These are the last properties at the bottom of the StringServlet AX Property Sheet.
    Image
  7. To create a file to capture each request in the station home folder, link this topic to an appropriate recipient, such as a report FileRecipient.
    Image
  8. Right-click the servlet component and click Actions > Send.
    In the example, when we repeat the same external request, the conditional response returns:

    curl -k -u MrBasic:Manager123 -X POST "https://127.0.0.1/temperature" -d '{"getTemp":"Inside"}'

    {"time":1626273698782,"temp":21,"units":"°C"}

It is also possible to send GET requests to a StringServlet. The functionality is the same, except no Request Body can be posted.