HTTP Client Input Adapter Samples

About The Samples

In this sample, the TIBCO StreamBase® HTTP Client Input adapter handles HTTP requests to a specified URL. The calls made by the adapter demonstrate how to get data from HTTP endpoints.

The samples for this adapter show how to perform various HTTP request calls include Server-Sent Events and Chunked Response type of calls.

REST, SOAP, WEB, SSE (Server-Sent Events), CHUNKED, GET, POST, PUT

Running The HTTP Client Samples

HTTP Client

In this sample, the TIBCO StreamBase® HTTP Client input adapter retrieves the contents of a web page by sending an HTTP GET request to the specified URL via the input tuple. The input tuple can override almost any property of the adapter. This sample will input a few different tuples to demonstrate this at runtime.

  1. In the Package Explorer, double-click to open the HTTPClient.sbapp, and make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

    1. In the Manual Input view select BasicControl from the Stream drop down.

    2. Enter https://www.google.com into the url field.

    3. Click Send Data to send the command to the adapter.

  3. In the Application Output view, observe tuples emitted on the Status and Output output streams.

  4. Select the tuple emitted from the Output stream, then use the triangles next to the data fields displayed to analyze and understand their structure. Notice the data field holds the contents of the web page.

    1. In the Manual Input view select FullControl from the Stream drop down.

    2. Enter https://www.google.com into the url field. Enter 'file download' into the 'settings\requestType' field.

    3. Click Send Data to send the command to the adapter.

  5. In the Application Output view, observe tuples emitted on the Status and Output output streams.

  6. Select the tuple emitted from the Output stream, then use the triangles next to the data fields displayed to analyze and understand their structure. Notice the binary field holds the contents of the web page.

    1. In the Manual Input view select FullControl from the Stream drop down.

    2. Enter https://www.google.com into the url field.

    3. Enter 'file download' into the 'settings\requestType' field.

    4. Enter an absolute file name and path into the 'settings\downloadPath' field, for instance 'c:/tmp/google.html'.

    5. Click Send Data to send the command to the adapter.

  7. In the Application Output view, observe tuples emitted on the Status and Output output streams.

  8. Select the tuple emitted from the Output stream, then use the triangles next to the data fields displayed to analyze and understand their structure. Notice the data field holds the filename of the file the web page was stored into.

  9. Press F9 or click the Stop Running Application button.

Server-Sent Events

In this sample, the TIBCO StreamBase® HTTP Client input adapter connects to the WikiMedia recent changes feed via Server-Sent Events which streams all recent changes and converts that data into a usable StreamBase structure via JSONToTuple operator.

When this sample starts it automatically sends a connection command into the HTTP Client adapter to connect to the WikiMedia recent changes. Select the DefaultWikiEvents map operator to see the definition of the command sent.

  1. In the Package Explorer, double-click to open the HTTPServerSentEvents.sbapp, and make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the Application Output view, observe tuples emitted on the SSEData and SSEStatus output streams.

  4. To disconnect, in the Manual Input view select SSECommand from the Stream drop down, enter disconnect into the command field and click Send Data to send the command to the adapter.

  5. Press F9 or click the Stop Running Application button.

Chunked Response

In this sample, the TIBCO StreamBase® HTTP Client input adapter connects to the https://dweet.io/ server and subscribes to changes to a IOT item. The sample then sends a new sensor reading value to the tibco-streambase-demo-thing item on the dweet system which in turn is sent back to our adapter which has subscribed to that item.

When this sample starts it automatically sends a connection command into the HTTP Client adapter to connect to the https://dweet.io/ server and subscribe to item tibco-streambase-demo-thing and sends a value. Select the Default map operator to see the definition of the command sent.

This sample also checks for the status of the adapters status port for disconnects and reconnects automatically.

  1. In the Package Explorer, double-click to open the HTTPChunkedResponse.sbapp, and make sure the application is the currently active tab in the EventFlow Editor.

  2. Click the Run button. This opens the SB Test/Debug perspective and starts the application.

  3. In the Application Output view, observe tuples emitted on the output streams.

  4. To disconnect, in the Manual Input view select ChunkedCommand from the Stream drop down, enter disconnect into the command field and click Send Data to send the command to the adapter.

  5. Press F9 or click the Stop Running Application button.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top menu, select FileLoad StreamBase Sample.

  • Select Web Reader input adapter from the StreamBase Standard Adapters category.

  • Click OK.

StreamBase Studio creates a single project containing the sample files.

Sample Location

When you load the sample into StreamBase Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_httpclient

See Default Installation Directories for the default location of studio-workspace on your system.