Web Reader Input Adapter Samples

About The Samples

In this sample, the TIBCO StreamBase® Web Reader input adapter retrieves the contents of a web page by sending an HTTP GET or HTTP POST request to a specified URL. The calls made by the adapter demonstrate how to get data from REST and SOAP web endpoints. The URL's used in the sample's EventFlow application is a special case because they contain a pure XML structure whose elements describe recent currency exchange transactions. The adapter's HTTP GET and HTTP POST commands retrieves whatever a specified URL serves, which is this case is an XML file.

Thus, this sample retrieves an XML file served as a web page on a particular URL, then uses the XML to Tuple operator to parse the XML and convert it to tuple format. In the context of a larger application, this sample's ParsedWebPage output stream would be ready to be processed further by downstream components.

Running The Samples in StreamBase Studio

  1. In the Package Explorer, double-click to open the webreader.sbapp for a HTTP GET example, webreaderPost.sbapp for a HTTP POST example, and webreaderSOAP.sbapp for a SOAP request example. 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. For the example, in the Manual Input view, click Send Data to send the default null tuple.

  4. In the Application Output view, observe tuples emitted on the RawWebPage and ParsedWebPage output streams.

  5. Select the tuple emitted from the ParsedWebPage stream, then use the triangles next to the data fields displayed to analyze and understand their structure.

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

  7. (The next steps only applies to HTTP GET) Back on the EventFlow Editor canvas, double-click the WebReader component to edit its properties. Clear the Enable Control Port control, and set the Poll Frequency control to 10,000. Now save the module and run it again.

  8. The application now retrieves the contents of the specified URL every 10 seconds. Watch the output in the Application Output view and look for changes in the Bid and Offer fields over time.

  9. When done, press F9 or click the Stop Running Application button.

Running This Sample in Terminal Windows

This section describes how to run this sample in UNIX terminal windows or Windows command prompt windows. Running this sample in terminal windows does not provide the best illustration of the Web Reader adapter, because tuples emitted on its primary output port are not designed for human readability. Nevertheless, if you only have terminal access to a UNIX server running StreamBase, follow the steps in this section.

On Windows, be sure to use the StreamBase Command Prompt from the Start menu as described in the Test/Debug Guide, not the default command prompt.

  1. Open three terminal windows on UNIX, or three StreamBase Command Prompts on Windows. In each window, navigate to your workspace copy of the sample, as described above.

  2. In window 1, type:

    If you are running the HTTP GET example:

    sbd webreader.sbapp
    

    If you are running the HTTP POST example:

    sbd webreaderPost.sbapp
    

    If you are running the SOAP example:

    sbd webreaderSOAP.sbapp
    
  3. In window 2, type:

    sbc dequeue ParsedWebPage
    

    This window will display tuples dequeued from the adapter's primary output port.

  4. In window 3, type:

    sbc enqueue Control
    
  5. In window 3, for the HTTP GET example type:

    null
    

    In window 3, for the HTTP POST or SOAP example type:

    null,null,null
    

    and press Enter.

  6. Observe in window 2 that a single tuple is emitted from the ParsedWebPage stream. This tuple contains a single field of type tuple, which in turn contains a single field of type list(tuple).

  7. In window 3, type Ctrl+C, then the following command to terminate the server and dequeuer:

    sbadmin shutdown
    

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 the permission problems that can occur when trying to work with the initially installed location of the sample. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_webreader

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

In the default TIBCO StreamBase installation, this sample's files are initially installed in:

streambase-install-dir/sample/adapter/embedded/webreader

See Default Installation Directories for the location of streambase-install-dir on your system. This location may require administrator privileges for write access, depending on your platform.