Contents
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.
-
In the Package Explorer, double-click to open the
webreader.sbapp
for a HTTP GET example,webreaderPost.sbapp
for a HTTP POST example, andwebreaderSOAP.sbapp
for a SOAP request example. Make sure the application is the currently active tab in the EventFlow Editor. -
Click the Run button. This opens the SB Test/Debug perspective and starts the application.
-
For the example, in the Manual Input view, click
to send the defaultnull
tuple. -
In the Application Output view, observe tuples emitted on the
RawWebPage
andParsedWebPage
output streams. -
Select the tuple emitted from the
ParsedWebPage
stream, then use the triangles next to the data fields displayed to analyze and understand their structure. -
Press F9 or click the Stop Running Application button.
-
(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. -
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
andOffer
fields over time. -
When done, press F9 or click the Stop Running Application button.
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.
-
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.
-
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
-
In window 2, type:
sbc dequeue ParsedWebPage
This window will display tuples dequeued from the adapter's primary output port.
-
In window 3, type:
sbc enqueue Control
-
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.
-
Observe in window 2 that a single tuple is emitted from the
stream. This tuple contains a single field of type tuple, which in turn contains a single field of type list(tuple).ParsedWebPage
-
In window 3, type Ctrl+C, then the following command to terminate the server and dequeuer:
sbadmin shutdown
In StreamBase Studio, import this sample with the following steps:
-
From the top menu, select
→ . -
Select
Web Reader input adapter
from the StreamBase Standard Adapters category. -
Click OK.
StreamBase Studio creates a single project containing the sample files.
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.