Service Health Check Sample for REST

REST Binding samples are available in <TIBCO_HOME>/amx/3.4/samples/rest/samples/. This section uses the bookstore sample to demonstrate how to check the health of a Service with a REST Binding.

Use a REST client such as the following to invoke the Service Health Check request:

Deploying the Bookstore Sample

Deploy the DAA file of the sample, com.tibco.restbt.sample.bookstore.daa, to an ActiveMatrix Runtime Node using the ActiveMatrix Administrator UI.

Obtaining the Endpoint URL of the Service

You can obtain the Endpoint URL of the Service either from the Swagger UI or the Configuration tab.

  • From Swagger UI:

    1. In ActiveMatrix Administrator, click Applications.
    2. Select com.tibco.restbt.sample.bookstore from the list of Applications.
    3. Click the General tab.
    4. Expand the BookStoreResource Service.
    5. Select the REST Binding, RESTService_Binding1.
    6. On the right side, select the Node and click .
    7. Note the Base URL mentioned on the Swagger UI page. For example, the Base URL in the following screenshot is test-workstation:9831/bookstore.

    8. Append /checkHealth to this URL to form the Endpoint URL. For example, the Endpoint URL for the above Base URL is:
      test-workstation:9831/bookstore/checkHealth

      Where, checkHealth is the operation name for executing Service Health Check.

  • From the Configuration tab:

    1. In ActiveMatrix Administrator, click Applications.
    2. Select com.tibco.restbt.sample.bookstore from the list of Applications.
    3. Click the Configuration tab.
    4. Select the BookStoreResource Service.
    5. On the right, click Bindings.
    6. Select the REST Binding, RESTService_Binding1.
    7. Click Edit. The Edit Binding dialog is displayed.

    8. Note the Context root and Connector Name details displayed. The details are required to create the Endpoint URL.
    9. Use the Connector Name to find out the port number of the HTTP Connector as follows:
      1. Select Shared Objects > Resource Templates.
      2. Under Resource Templates > Type, select HTTP Connector.
      3. On the right, select the HTTP Connector. The connector name must be the same as the one displayed in the Edit Binding dialog.

        The port number is displayed in the Port field of the General tab.

    10. Create the Endpoint URL using the Context root and port number of the HTTP Connector. The format of the URL is:
      http://<host>:<port>/<Context root>/checkHealth

      Where:

      <host> is the IP address or name of the ActiveMatrix Administrator Host.

      <port> is the port number of the HTTP Connector used to access the Host.

      <Context root> is the context root associated with the Binding. For the bookstore sample, the context root is bookstore. The value of Context root can be got from the Edit Binding dialog box.

      checkHealth is the operation name for Service Health Check.

Running the Bookstore Sample

Using a REST client such as POSTMAN REST, execute the Service Health Check request on the Endpoint URL obtained in the above section to initiate a REST request (POST operation).
Note: The request must conform to the Health Check Request schema, available in <TIBCO_HOME>/administrator/3.4/samples/healthcheck/HealthCheck.wsdl.
  1. Execute the Service Health Check Request on the following Endpoint URL:
    http://<host>:<port>/<Context root>/checkHealth
  2. Set the HTTP method to POST.
  3. Set the HTTP headers in the request. The headers to be set depend on the request payload and the expected payload. See the Samples below.

Sample Request and Response with XML Payload

  • HTTP Headers:

    To make a request with XML Payload, the appropriate HTTP headers are:

    Accept = application/xml
    Content-Type = application/xml
  • Request:

    Specify the appropriate request parameters as shown in the following example:

    <HealthCheckRequest xmlns="http://www.tibco.com/healthcheck/">
    <hops>-1</hops>
    <suppressStackTrace>False</suppressStackTrace>
    <timeout>30000</timeout>
    </HealthCheckRequest>
  • Response:

    The Service Health Check response shows the health status of the participating entities. The component type would be TIBCO-IT-JAVA for the Java Implementation Type.

    <?xml version="1.0" encoding="UTF-8"?>
    <ns2:HealthCheckResponse applicationName="com.tibco.restbt.sample.bookstore" correlationID="315b7bd6-ae9e-4c6a-a3ea-135194727b50" status="Passed" xmlns:ns2="http://www.tibco.com/healthcheck/">
    <Service bindingName="RESTService_Binding1" bindingType="REST" endTime="21 May 2018 16:40:09,848" endpointURI="urn:amx:DevEnvironment/com.tibco.restbt.sample.bookstore#service-binding(BookStoreResource/RESTService_Binding1)___1.0.0.v2014-12-31-1101" environmentName="DevEnvironment" hostName="SystemHost" ipAddress="127.0.0.1" isSSLEnabled="false" machineName="test-workstation" name="BookStoreResource" nodeName="DevNode" portTypeName="BookStoreResource" responseTime="1" startTime="21 May 2018 16:40:09,847" status="Passed" transportType="HTTP">
    <Component componentType="TIBCO-IT-JAVA" endTime="21 May 2018 16:40:09,845" environmentName="DevEnvironment" hostName="SystemHost" name="BookStoreResource" nodeName="DevNode" responseTime="2" startTime="21 May 2018 16:40:09,843" status="Passed" version="1.0.0.v2014-12-31-1101"/>
    </Service>
    </ns2:HealthCheckResponse>

Sample Request and Response with Standard JSON Payload

  • HTTP Headers:

    To make a request with JSON Payload, the appropriate HTTP headers are:

    Accept = application/json
    Content-Type = application/json
  • Request:

    Specify the appropriate request parameters as shown in the following example:

    {
      "HealthCheckRequest": {
        "hops": "1",
        "suppressStackTrace": "False",
        "timeout": "30000"
      }
    }
  • Response:

    Following response is seen for request in the above example.

     {
        "HealthCheckResponse": {
            "@correlationID": "0cb3f1bd-272d-4765-a3d6-4b1593e4613c",
            "@applicationName": "com.tibco.restbt.sample.bookstore",
            "@status": "Passed",
            "Service": {
                "@bindingType": "REST",
                "@nodeName": "DevNode",
                "@hostName": "SystemHost",
                "@isSSLEnabled": "false",
                "@portTypeName": "BookStoreResource",
                "@responseTime": "0",
                "@ipAddress": "127.0.0.1",
                "@bindingName": "RESTService_Binding1",
                "@machineName": "test-workstation",
                "@environmentName": "DevEnvironment",
                "@name": "BookStoreResource",
                "@startTime": "21 May 2018 16:37:57,529",
                "@transportType": "HTTP",
                "@endTime": "21 May 2018 16:37:57,529",
                "@endpointURI": "urn:amx:DevEnvironment/com.tibco.restbt.sample.bookstore#service-binding(BookStoreResource/RESTService_Binding1)___1.0.0.v2014-12-31-1101",
                "@status": "Passed",
                "Component": {
                    "@nodeName": "DevNode",
                    "@componentType": "TIBCO-IT-JAVA",
                    "@hostName": "SystemHost",
                    "@environmentName": "DevEnvironment",
                    "@responseTime": "0",
                    "@name": "BookStoreResource",
                    "@startTime": "21 May 2018 16:37:57,513",
                    "@endTime": "21 May 2018 16:37:57,513",
                    "@version": "1.0.0.v2014-12-31-1101",
                    "@status": "Passed"
                }
            }
        }
    }

Sample Request and Response with Badgerfish JSON Payload

  • HTTP Headers:

    To make a request with Badgerfish JSON Payload, the appropriate HTTP headers are:

    Accept = application/bjson
    Content-Type = application/bjson
  • Request:

    Specify the appropriate request parameters as shown in the following example:

     {
      "HealthCheckRequest": {
        "@xmlns": {
          "$": "http:\/\/www.tibco.com\/healthcheck\/"
        },
        "hops": {
          "$": "-1"
        },
        "suppressStackTrace": {
          "$": "False"
        },
        "timeout": {
          "$": "30000"
        }
      }
    }
  • Response:

    Following response is seen for the request in the above example:

     {
        "ns2:HealthCheckResponse": {
            "@xmlns": {
                "ns2": "http://www.tibco.com/healthcheck/"
            },
            "@correlationID": "013933c5-c725-448f-be71-4c8b042b3f50",
            "@applicationName": "com.tibco.restbt.sample.bookstore",
            "@status": "Passed",
            "Service": {
                "@bindingType": "REST",
                "@nodeName": "DevNode",
                "@hostName": "SystemHost",
                "@isSSLEnabled": "false",
                "@portTypeName": "BookStoreResource",
                "@responseTime": "2",
                "@ipAddress": "127.0.0.1",
                "@bindingName": "RESTService_Binding1",
                "@machineName": "test-workstation",
                "@environmentName": "DevEnvironment",
                "@name": "BookStoreResource",
                "@startTime": "21 May 2018 16:39:32,247",
                "@transportType": "HTTP",
                "@endTime": "21 May 2018 16:39:32,249",
                "@endpointURI": "urn:amx:DevEnvironment/com.tibco.restbt.sample.bookstore#service-binding(BookStoreResource/RESTService_Binding1)___1.0.0.v2014-12-31-1101",
                "@status": "Passed",
                "Component": {
                    "@nodeName": "DevNode",
                    "@componentType": "TIBCO-IT-JAVA",
                    "@hostName": "SystemHost",
                    "@environmentName": "DevEnvironment",
                    "@responseTime": "2",
                    "@name": "BookStoreResource",
                    "@startTime": "21 May 2018 16:39:32,242",
                    "@endTime": "21 May 2018 16:39:32,244",
                    "@version": "1.0.0.v2014-12-31-1101",
                    "@status": "Passed"
                }
            }
        }
    }

Sample Request and Response for Caching

  • HTTP Headers:

    To make a request with XML Payload, the appropriate HTTP headers are:

    Accept:application/json
    Content-Type:application/xml
  • Request:
    Ensure that caching is enabled to perform a Service Health Check. For more information, see Enabling or Disabling the Caching of a Health Check Response. Specify the caching-related parameters as shown in the following example:
    <HealthCheckRequest xmlns="http://www.tibco.com/healthcheck/">
    <hops>2</hops>
    <cache refreshCache="false" validityDurationInSecs="300" refreshIfOlderThan="40"/>
    </HealthCheckRequest> 
  • Response:
    The following response is seen for the caching request in the above example. The attribute isCached is true which indicates that response is cached.
    {
        "HealthCheckResponse": {
            "@cachedForDurationInSecs": "300",
            "@correlationID": "c1359c1a-36a0-4d14-8392-6a7d7b663f0a",
            "@cachedAtTime": "23 May 2018 22:27:09,385",
            "@applicationName": "com.tibco.restbt.sample.bookstore",
            "@isCached": "true",
            "@status": "Passed",
            "Service": {
                "@bindingType": "REST",
                "@nodeName": "DevNode",
                "@hostName": "SystemHost",
                "@isSSLEnabled": "false",
                "@portTypeName": "BookStoreResource",
                "@responseTime": "1",
                "@ipAddress": "127.0.0.1",
                "@bindingName": "RESTService_Binding1",
                "@machineName": "test-workstation",
                "@environmentName": "DevEnvironment",
                "@name": "BookStoreResource",
                "@startTime": "23 May 2018 22:27:09,383",
                "@transportType": "HTTP",
                "@endTime": "23 May 2018 22:27:09,384",
                "@endpointURI": "urn:amx:DevEnvironment/com.tibco.restbt.sample.bookstore#service-binding(BookStoreResource/RESTService_Binding1)___1.0.0.v2014-12-31-1101",
                "@status": "Passed",
                "Component": {
                    "@nodeName": "DevNode",
                    "@componentType": "TIBCO-IT-JAVA",
                    "@hostName": "SystemHost",
                    "@environmentName": "DevEnvironment",
                    "@responseTime": "1",
                    "@name": "BookStoreResource",
                    "@startTime": "23 May 2018 22:27:09,380",
                    "@endTime": "23 May 2018 22:27:09,381",
                    "@version": "1.0.0.v2014-12-31-1101",
                    "@status": "Passed"
                }
            }
        }
    }