The TIBCO StreamBase® Web Server Response Adapter allows the system to handle HTTP and WebSocket responses. Each request from a Web Server Request adapter must end up in a Web Server Request Adapter. The adapter uses the requestId field of the incoming tuple to determine which web server and request/response object to send the HTTP response to. To close a websocket send a none null status code in with the requestId of the websocket.
This section describes the properties you can set for this adapter, using the various tabs of the Properties view in StreamBase Studio.
Name: Use this required field to specify or change the name of this instance of this component, which must be unique in the current EventFlow module. The name must contain only alphabetic characters, numbers, and underscores, and no hyphens or other special characters. The first character must be alphabetic or an underscore.
Operator: A read-only field that shows the formal name of the operator.
Class name: Shows the fully qualified class name that implements the functionality of this operator. If you need to reference this class name elsewhere in your application, you can right-click this field and select Copy from the context menu to place the full class name in the system clipboard.
Start options: This field provides a link to the Cluster Aware tab, where you configure the conditions under which this adapter starts.
Enable Error Output Port: Select this check box to add an Error Port to this component. In the EventFlow canvas, the Error Port shows as a red output port, always the last port for the component. See Using Error Ports to learn about Error Ports.
Description: Optionally enter text to briefly describe the component's purpose and function. In the EventFlow Editor canvas, you can see the description by pressing Ctrl while the component's tooltip is displayed.
Property | Type | Description |
---|---|---|
WebServer Configuration | Edit Button | Shortcut to the StreamBase Configuration File Editor, used for adapter configuration or converting an existing application's adapter-configurations.xml file to HOCON format.
|
Request Id Field Name | string | The field in the incoming tuple which represents the requestId value to be used to look up the original HTTP request and corresponding web server. This field must be of type string. |
Data Field Name | string | The field in the incoming tuple which represents the data to send as the HTTP response. This field must be of type string or blob. |
Http Headers Field Name | string | The field in the incoming tuple which represents the HTTP headers to send with the HTTP response. This field must be of type
list<tuple<string Key,string Value>>.
For example (long lines wrap to the next for clarity): list( tuple('Access-Control-Allow-Origin' as Key, '*' as Value), tuple('Access-Control-Allow-Headers' as Key, 'Origin, X-Requested-With, Content-Type, Accept' as Value), tuple('Test-Header-page' as Key, '1234' as Value) ) |
Status Code Field Name | string | *Optional. The field in the incoming tuple which represents the status code to send with the HTTP response. The field must be of type int. If the value is not specified, the default 200 is used. If the requestId corresponds to a websocket and the status code is not null the socket will be closed with the status code given. |
Content Type Field Name | string | *Optional. The field in the incoming tuple which represents the content type to send with the HTTP response. The field must be of type string. If the value is not specified, the system tries to determine the best content type based on the data field. |
Cookies Field Name | string | *Optional. The field in the incoming tuple which represents the cookies to send with the HTTP response. The field can have
the following schemas:
|
Log Level | INFO | Controls the level of verbosity the adapter uses to issue informational traces to the console. This setting is independent of the containing application's overall log level. Available values, in increasing order of verbosity, are: OFF, ERROR, WARN, INFO, DEBUG, TRACE. |
Property | Type | Description |
---|---|---|
Response Data Transformer Accept Type Map | string, string |
The key/value map which has a regex key that matches to the requests ACCEPT header and the value is a class that implements
|
Response Data Transformer Settings | string, string | The key/value map of settings to pass to the Response Data Transformers. The key is the classname.setting of each setting to send to individual data transformers. The value is the setting value to set. For example to set the JSONResponseDataTransformer
timestamp format you would have a key of JSONResponseDataTransformer .TimestampFormat and some string format for the value.
|
Property | Type | Description |
---|---|---|
Default HTTP Headers | string, string |
The default HTTP headers that are added to each output response. These values are overridden by any HTTP fields given by the input tuple. An example of an HTTP header might be |
Use the settings in this tab to allow this operator or adapter to start and stop based on conditions that occur at runtime in a cluster with more than one node. During initial development of the fragment that contains this operator or adapter, and for maximum compatibility with TIBCO Streaming releases before 10.5.0, leave the Cluster start policy control in its default setting, Start with module.
Cluster awareness is an advanced topic that requires an understanding of StreamBase Runtime architecture features, including clusters, quorums, availability zones, and partitions. See Cluster Awareness Tab Settings on the Using Cluster Awareness page for instructions on configuring this tab.
Use the Concurrency tab to specify parallel regions for this instance of this component, or multiplicity options, or both. The Concurrency tab settings are described in Concurrency Options, and dispatch styles are described in Dispatch Styles.
Caution
Concurrency settings are not suitable for every application, and using these settings requires a thorough analysis of your application. For details, see Execution Order and Concurrency, which includes important guidelines for using the concurrency options.
The response data transformer interface com.streambase.sb.adapter.webserver.data.IResponseDataTransformer
is used to convert tuples to a POST response.
package com.streambase.sb.adapter.webserver.data; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.Request; import org.slf4j.Logger; import com.streambase.sb.Schema; import com.streambase.sb.StreamBaseException; import com.streambase.sb.Tuple; import com.streambase.sb.operator.TypecheckException; public interface IResponseDataTransformer { /*** * This method will be called during typecheck time to allow * a response data transformer to validate a key value map of settings * against the transformer * * @param settings A key value map of settings the end user specified for * this adapters custom data transformation * @param schema The schema of the input data to transform * @throws TypecheckException */ public void validateSettings(Map<String, String> settings, Schema schema) throws TypecheckException; /*** * This method allows the tuple to be sent to the HTTP response with any custom * logic required * * @param logger A logger than can be used to log any extra information which may * be required * @param settings A key value map of settings the end user specified for this * adapters custom data transformation * @param httpServletRequest The HTTP request * @param request The base HTTP request * @param tuple The tuple to convert * @throws StreamBaseException */ public void transformResponseData(Logger logger, Map<String, String> settings, HttpServletRequest httpServletRequest, Request request, HttpServletResponse httpServletResponse, Tuple tuple) throws StreamBaseException; }
The JSON response data transform converts a tuple to a JSON response. If no content type is set, this will set it as application/json
.
Setting | Type | Default | Description |
---|---|---|---|
TimestampFormat | string | yyyy-MM-dd HH:mm:ss.SSSZ | The timestamp format used when converting a tuple timestamp fields to JSON |
TimestampAsLong | true/false | false | If true timestamp fields will be output as long values |
IncludeNullFields | true/false | false | If true null fields are included in the output JSON |
SerializedSubTupleType | Map/List | Map | The type of JSON to create |
The XML response data transform converts a tuple to an XML response. If no content type is set, this will set it as application/xml
.
Setting | Type | Default | Description |
---|---|---|---|
TimestampFormat | string | yyyy-MM-dd HH:mm:ss.SSSZ | The timestamp format used when converting a timestamp field to XML |
IncludeNullListValues | true/false | true | If true null fields in the tuple will be included in the XML response |
NullListValueRepresentation | string | null | The string value to set for any field that is null in the input tuple |
WrapperFieldName | string | Response | The outer most XML element to create when converting the tuple to XML to wrap the tuples fields. |