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, JSONP, and SOAP web endpoints.

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 Web Reader Samples

HTTP GET

In this sample, the TIBCO StreamBase® Web Reader input adapter retrieves the contents of a web page by sending an HTTP GET request to the specified URL in the adapter HTTP URL property.

  1. In the Package Explorer, double-click to open the webreader.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. 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. 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.

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

JSONP

In this sample, the TIBCO StreamBase® Web Reader input adapter sends a JSONP request to the server using the URLParams and HTTPHeaders input variables. See the defaults map operator on the canvas of this sample to show how to set up the different types of fields required for this operation. The TupleToJSON operator is used to convert the input data into a JSON string to send to the server.

  1. In the Package Explorer, double-click to open the webreaderJSONP.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. For the example, in the Manual Input view, event some values into the fields and click Send Data to send the tuple.

  4. In the Application Output view, observe tuples emitted on the RawResponse and ParsedResponse output streams.

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

POST JSON

In this sample, the TIBCO StreamBase® Web Reader input adapter sends a JSON request to the server via a POST request using the PostData and HTTPHeaders input variables. See the PostDefaults map operator on the canvas of this sample to show how to set up the different types of fields required for this operation. The TupleToJSON operator is used to convert the input data into a JSON string to send to the server.

  1. In the Package Explorer, double-click to open the webreaderPostJSON.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. For the example, in the Manual Input view, event some values into the fields and click Send Data to send the tuple.

  4. In the Application Output view, observe tuples emitted on the RawResponse and ParsedResponse output streams.

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

POST XML

In this sample, the TIBCO StreamBase® Web Reader input adapter sends a XML request to the server via a POST request using the URLParams input variable. See the PostDefaults map operator on the canvas of this sample to show how to set up the different types of fields required for this operation. The XMLToTuple operator is used to convert the output string data into a Tuple.

  1. In the Package Explorer, double-click to open the webreaderPostXML.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. For the example, in the Manual Input view, event some values into the fields and click Send Data to send the tuple.

  4. In the Application Output view, observe tuples emitted on the RawResponse and ParsedResponse output streams.

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

SOAP

In this sample, the TIBCO StreamBase® Web Reader input adapter sends a SOAP request to the server via a POST request using the PostData and HTTPHeaders input variable. See the SOAPDefaults map operator on the canvas of this sample to show how to set up the different types of fields required for this operation. The XMLToTuple operator is used to convert the output string data into a Tuple.

  1. In the Package Explorer, double-click to open the webreaderSOAP.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. For the example, in the Manual Input view, event some values into the fields and click Send Data to send the tuple.

  4. In the Application Output view, observe tuples emitted on the RawResponse and ParsedResponse output streams.

  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_webreader

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