Operator HTTPRequestProcess

IBMStreams streamsx.inetserver Toolkit > com.ibm.streamsx.inetserver 4.3.4 > com.ibm.streamsx.inet.rest > HTTPRequestProcess

Operator accepts a web request and generates corresponding response. The request is injected into streams on the output port, the input port receives the response.This enables a developer to process HTTP form's and REST calls. The request arrives on the output port, results are presented on the input port.The request is correlated to the response with an attribute 'key' that arrives with the request parameters' on the output port and must accompany the response on the input port.

The URLs defined by this operator are:
  • prefix/ports/analyze/port index/ - Injects a tuple into the output and the response is taken from the matching tuple on the input port.
  • prefix/ports/input/port index/info - Output port meta-data including the stream attribute names and types (content type application/json).
The prefix for the URLs is:
  • context path/base operator name - When the context parameter is set.
  • full operator name - When the context parameter is not set.

For the analyze path any HTTP method can be used and any sub-path. For example with a context of api and operator name of Bus then api/Bus/ports/analyze/0/get_location is valid.

Input and output ports have two possible formats: tuple and json. The modes of input- and output port are independant.A port works in json mode if it has one attribute with name jsonString. With tuple format, each web input fields is mapped to an attribute. Json format has one attribute ('jsonString'), each web field is mapped to a json object field.

The jsonString object will be populated with all the fields. The default attribute names can be overridden for tuple.

The operator handles two flavors of http requests, forms and REST. In the case of forms, webpages can be served up from the contextResourceBase, this can be to static html or template. . Refer to the spl example for a form processed by the operator using a template to format the response.

For the input port (the web response), only the 'key' is mandatory for both json and tuple.

For the output port in tuple mode (the web request), only the 'key' attribute is mandatory. All other attributes 'request', 'method', 'header', 'contentType', 'pathInfo', 'contextPath' and 'url' are optional. In json mode all attributes are propagated to the json attribute

The following lists the default values if the field or attribute is not provided.
  • rstring response : 0 length response.
  • int32 statusCode : 200 (OK)
  • rstring statusMessage : not set
  • rstring contentType : 'text/html; charset=utf-8'.
  • Map<rstring,rstring> headers : No headers provided

Notes:

  • The 'key' attribute on the output and input port's are correlated. Losing the correlation loses the request.
  • If the input port's response key cannot be located the web request will timeout, metrics will be incremented.
  • If the input jsonString value cannot be converted to an jsonObject, no response will be generated and web request will timeout.
  • Only the first input port's key will produce a web response.
  • The 'jsonString' attribute json field names are the default attribute names.
  • context/pathInfo relationship : A request's context path beyond the base is accepted, the 'pathInfo' attribute will have path beyond the base. If the context path is /work requests to /work/translate will have a 'pathInfo' of /translate and requests to /work/translate/speakeasy will have a 'pathInfo' of /translate/speakeasy.

HTTPS Support and Sharing the Jetty Server

see also namespace:com.ibm.streamsx.inet

Summary

Ports
This operator has 1 input port and 1 output port.
Windowing
This operator does not accept any windowing configurations.
Parameters
This operator supports 26 parameters.

Optional: certificateAlias, contentTypeAttributeName, context, contextPathAttributeName, contextResourceBase, headerAttributeName, host, jsonAttributeName, keyAttributeName, keyPassword, keyStore, keyStorePassword, methodAttributeName, pathInfoAttributeName, port, requestAttributeName, responseAttributeName, responseContentTypeAttributeName, responseHeaderAttributeName, responseJsonAttributeName, responseStatusAttributeName, sslAppConfigName, trustStore, trustStorePassword, urlAttributeName, webTimeout

Metrics
This operator reports 8 metrics.

Properties

Implementation
Java

Input Ports

Ports (0)

Response to be returned to the web requestor.

Properties

Output Ports

Assignments
Java operators do not support output assignments.
Ports (0)

Request from web to process.

Properties

Parameters

This operator supports 26 parameters.

Optional: certificateAlias, contentTypeAttributeName, context, contextPathAttributeName, contextResourceBase, headerAttributeName, host, jsonAttributeName, keyAttributeName, keyPassword, keyStore, keyStorePassword, methodAttributeName, pathInfoAttributeName, port, requestAttributeName, responseAttributeName, responseContentTypeAttributeName, responseHeaderAttributeName, responseJsonAttributeName, responseStatusAttributeName, sslAppConfigName, trustStore, trustStorePassword, urlAttributeName, webTimeout

certificateAlias

Alias of the certificate to use in the key store. When this parameter is set all connections use HTTPS and parameters keyStore and keyPassword are required.

Properties
contentTypeAttributeName

Output port's attribute name with content-type will be provided in. The type of the attribute must be rstring or ustring. Default: "contentType".

Properties
context

Define a URL context path that maps to the resources defined by contextResourceBase. This allows a composite that invokes this operator in a toolkit to provide resources regardless of the value of the application's data directory. For example setting it to maps would result in the URL /maps/index.html mapping to the file index.html in the directory defined by contextResourceBase. Requires the parameter contextResourceBase to be set. If when the operator is initialized the context already exists then no action is taken. This allows multiple independent composites in the same toolkit to have common context and contextResourceBase settings, typically to point to a single set of HTML and Javascript resources for the toolkit.

If the operator provides URLs for its input or output ports then they are placed in the this context when this parameter is set. This then provides fixed locations for the URLs regardless of the depth of the operator invocation in the main composite.

Only a single context per invocation is supported.

Properties
contextPathAttributeName

Output ports's attribute name of the context path. The type of the attribute must be rstring or ustring. Default: "contextPath".

Properties
contextResourceBase

Directory location of resources that will be available through the the URL context defined by the parameter context. Typically used to allow a toolkit to provide a set of resources in a fixed location. The set of resources is recommended to be stored in the application_dir/opt directory, which is automatically included in the bundle by default. Path of this directory can be absolute or relative, if relative path is specified then it is relative to the application directory. A set of default resources is included in the toolkit directory under ToolkitDir/opt/resources and will be loaded by the operator. This default resources can be viewed at http://hostname:8080/streamsx.inet.resources. A path within the application is obtained using the SPL function getThisToolkitDir(). Thus a composite in the file maps.spl in the namespace directory com.acme.streams.apps.map might have the following setting to map http://127.0.0.1:8080/maps to opt/resources/mapinfo in the application.

param
  context: “maps”
  contextResourceBase: getThisToolkitDir() + “/opt/resources/mapinfo”

If this parameter is applied parameter contextResourceBase is required too.

Properties
headerAttributeName

Output port's attribute name with web request headers, in the form of a map<rstring, rstring>, default: "header".

Properties
host

You can configure a host either as a host name or IP address to identify a specific network interface on which to listen. If not set, or set to the value of 0.0.0.0, the integrated jetty server listens on all local interfaces.

Properties
jsonAttributeName

Output port's attrinute name for json request (complete request). The type of the attribute must be rstring or ustring. Default: "jsonString".

Properties
keyAttributeName

Input and output port's corrolation key. The values is expected to be unchanged between the input and output, default: "key".

Properties
keyPassword

Password to the private key.

Properties
keyStore

URL to the key store containing the certificate. If a relative file path then it is taken as relative to the application directory.

Properties
keyStorePassword

Password to the key store.

Properties
methodAttributeName

Output ports's attribute name with the request method (PUT, GET, POST). The type of the attribute must be rstring or ustring. Default: "method".

Properties
pathInfoAttributeName

Output ports's attribute name of the content path below the base. The type of the attribute must be rstring or ustring. Default "pathInfo".

Properties
port

Port number for the embedded Jetty HTTP server, default: "8080". If the port is set to 0, the jetty server uses a free tcp port, and the metric serverPort delivers the actual value.

Properties
requestAttributeName

Output port's attribute name with the web request (body of the web request). The type of the attribute must be rstring or ustring. Default "request".

Properties
responseAttributeName

Input port's attribute name for the response body of the web response. The type of the attribute must be rstring or ustring. Default: "response".

Properties
responseContentTypeAttributeName

Input port's attribute name for web response content type. The type of the attribute must be rstring or ustring. Default: "contentType". If null or an empty string is delivered, the default content type 'text/html; charset=utf-8' is used.

Properties
responseHeaderAttributeName

Input port's attribute name for web response headers. The type of this attribute must be map<rstring, rstring>. Default: "header".

Properties
responseJsonAttributeName

Input port's attribute name for json results (complete response). The type of the attribute must be rstring or ustring. Default: "jsonString".

Properties
responseStatusAttributeName

Input port's attribute attribute name for web status. The type of the attribute must be int32. Default: "status". In no web status is deliveres, the value: 200 is used.

Properties
sslAppConfigName
The operator can get the SSL server key/certificate and the client trust material from Streams application configuration with this name. If this parameter is present, certificateAlias, keyStore, keyPassword, trustStore and trustStorePassword are not allowed. The application configuration must contain the folowing properties:
  • server.jks - Base 64 encoded representation of the Java key store with one key-certificate pair to be used as server key and certitficate.
  • server.pass -Password for server.jks (and its key) and cacerts.jks.
The app configuration may contain property:
  • cacerts.jks - Base 64 encoded representation of the Java trust store with the client trust material.
If the property cacerts.jks is present, the operator requests client certificates. To create the Streams application configuration you may use a comand like:
streamtool mkappconfig --description 'server cert and trust store' --property "server.jks=$(base64 --wrap=0 etc/keystore.jks)" --property "server.pass=password" --property "cacerts.jks=$(base64 --wrap=0 etc/cacerts.jks)" streams-certs
Properties
trustStore

URL to the trust store containing client certificates. If a relative file path then it is taken as relative to the application directory. When this parameter is set, client authentication is required.

Properties
trustStorePassword

Password to the trust store.

Properties
urlAttributeName

Output ports's attribute name of the url. The type of the attribute must be rstring or ustring. Default "url".

Properties
webTimeout

Number of seconds to wait for the web request to be processed by Streams, default: "15.0".

Properties

Metrics

https - Gauge

Jetty SSL/TLS status: 0=HTTP, 1=HTTPS.

nActiveRequests - Gauge

Number of requests currently being processed.

nMessagesReceived - Counter

Number of requests received from web.

nMessagesResponded - Counter

Number of vaild responses sent back via web.

nMissingTrackingKey - Counter

Missing tracking key count. In case of json input, this counts the received tuples with a corrupt json structure or the json structure does not contain a valid key object.

nRequestTimeouts - Counter

Number of timeouts waiting for response from Streams.

nTrackingKeyNotFound - Counter

Number of input tuples where the delivered tracking key was not found in the active messages database.

serverPort - Gauge

Jetty (HTTP/HTTPS) server port if the operator hosts the server, 0 otherwise

Libraries

Operator class library
Library Path: ../../impl/lib/com.ibm.streamsx.inetserver.jar