Skip to content

API Docs - v1.0.4

Source

http (Source)

The HTTP source receives POST requests via HTTP or HTTPS in format such as text, XML and JSON. If required, you can enable basic authentication to ensure that events are received only from users who are authorized to access the service.

Syntax

@source(type="http", receiver.url="<STRING>", basic.auth.enabled="<STRING>", worker.count="<STRING>", @map(...)))

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
receiver.url The URL to which the events should be received. User can provide any valid url and if the url is not provided the system will use the following format http://0.0.0.0:9763/<appNAme>/<streamName>If the user want to use SSL the url should be given in following format https://localhost:8080/<streamName> http://0.0.0.0:9763// STRING Yes No
basic.auth.enabled If this is set to true, basic authentication is enabled for incoming events, and the credentials with which each event is sent are verified to ensure that the user is authorized to access the service. If basic authentication fails, the event is not authenticated and an authentication error is logged in the CLI. By default this values 'false' false STRING Yes No
worker.count The number of active worker threads to serve the incoming events. The value is 1 by default. This will ensure that the events are directed to the event stream in the same order in which they arrive. By increasing this value the performance might increase at the cost of loosing event ordering. 1 STRING Yes No

System Parameters

Name Description Default Value Possible Parameters
latency.metrics.enabled Property to enable metrics logs to monitor transport latency for config. true true
false
server.bootstrap.socket.timeout property to configure specified timeout in milliseconds which server socket will block for this amount of time for http message content to be received. 15 Any integer
server.bootstrap.boss.group.size property to configure number of boss threads, which accepts incoming connections until the ports are unbound. Once connection accepts successfully, boss thread passes the accepted channel to one of the worker threads. 4 Any integer
server.bootstrap.worker.group.size property to configure number of worker threads, which performs non blocking read and write for one or more channels in non-blocking mode. 8 Any integer
default.host The default host of the transport. 0.0.0.0 Any valid host
http.port The default port if the default scheme is 'http'. 9763 Any valid port
https.port The default port if the default scheme is 'https'. 9443 Any valid port
default.protocol The default protocol. http http
https
https.keystore.file The default keystore file path. ${carbon.home}/resources/security/wso2carbon.jks Path to wso2carbon.jks file
https.keystore.password The default keystore password. wso2carbon String of keystore password
https.cert.password The default cert password. wso2carbon String of cert password

Examples EXAMPLE 1

@source(type='http', receiver.url='http://localhost:9055/endpoints/RecPro', @map(type='xml'))
define stream FooStream (symbol string, price float, volume long);

Above source configuration performs a default XML input mapping. The expected input is as follows:<events>
    <event>
        <symbol>WSO2</symbol>
        <price>55.6</price>
        <volume>100</volume>
    </event>
</events>
If basic authentication is enabled via the basic.auth.enabled='true setting, each input event is also expected to contain the Authorization:'Basic encodeBase64(username:Password)' header.

Sink

http (Sink)

This extension publish the HTTP events in any HTTP method POST, GET, PUT, DELETE via HTTP or https protocols. As the additional features this component can provide basic authentication as well as user can publish events using custom client truststore files when publishing events via https protocol. And also user can add any number of headers including HTTP_METHOD header for each event dynamically.

Syntax

@sink(type="http", publisher.url="<STRING>", basic.auth.username="<STRING>", basic.auth.password="<STRING>", client.truststore.path="<STRING>", client.truststore.password="<STRING>", headers="<STRING>", method="<STRING>", @map(...)))

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
publisher.url The URL to which the outgoing events should be published via HTTP. This is a mandatory parameter and if this is not specified, an error is logged in the CLI. If user wants to enable SSL for the events, use https instead of http in the publisher.url.e.g., http://localhost:8080/endpoint, https://localhost:8080/endpoint STRING No No
basic.auth.username The username to be included in the authentication header of the basic authentication enabled events. It is required to specify both username and password to enable basic authentication. If one of the parameter is not given by user then an error is logged in the CLI. STRING Yes No
basic.auth.password The password to include in the authentication header of the basic authentication enabled events. It is required to specify both username and password to enable basic authentication. If one of the parameter is not given by user then an error is logged in the CLI. STRING Yes No
client.truststore.path The file path to the location of the truststore of the client that sends the HTTP events through 'https' protocol. A custom client-truststore can be specified if required. ${carbon.home}/resources/security/client-truststore.jks STRING Yes No
client.truststore.password The password for the client-truststore. A custom password can be specified if required. If no custom password is specified and the protocol of URL is 'https' then, the system uses default password. wso2carbon STRING Yes No
headers The headers that should be included as a HTTP request headers. There can be any number of headers concatenated on following format. header1:value1#header2:value2. User can include content-type header if he need to any specific type for payload if not system get the mapping type as the content-Type header (ie. @map(xml):application/xml,@map(json):application/json,@map(text):plain/text ) and if user does not include any mapping type then system gets the 'plain/text' as default Content-Type header. If user does not include Content-Length header then system calculate the bytes size of payload and include it as content-length header. STRING Yes Yes
method For HTTP events, HTTP_METHOD header should be included as a request header. If the parameter is null then system uses 'POST' as a default header. POST STRING Yes Yes

System Parameters

Name Description Default Value Possible Parameters
latency.metrics.enabled Property to enable metrics logs to monitor transport latency for config. true Any Integer
server.bootstrap.socket.timeout Property to configure specified timeout in milliseconds which server socket will block for this amount of time for http message content to be received. 15 Any Integer
server.bootstrap.boss.group.size Property to configure number of boss threads, which accepts incoming connections until the ports are unbound. Once connection accepts successfully, boss thread passes the accepted channel to one of the worker threads. 4 Any integer
server.bootstrap.worker.group.size Property to configure number of worker threads, which performs non blocking read and write for one or more channels in non-blocking mode. 8 Any integer
default.protocol The default protocol. http http
https
https.truststore.file The default truststore file path. ${carbon.home}/resources/security/client-truststore.jks Path to client-truststore.jks
https.truststore.password The default truststore password. wso2carbon Truststore password

Examples EXAMPLE 1

@sink(type='http',publisher.url='http://localhost:8009/foo', method='{{method}}',headers='{{headers}}', @map(type='xml' , @payload('{{payloadBody}}')))define stream FooStream (payloadBody String, method string, headers string);

If it is xml mapping expected input should be in following format for FooStream:{<events> <event> <symbol>WSO2</symbol> <price>55.6</price> <volume>100</volume> </event></events>,POST,Content-Length:24#Content-Location:USA#Retry-After:120}Above event will generate output as below.~Output http event payload<events>
    <event>
        <symbol>WSO2</symbol>
        <price>55.6</price>
        <volume>100</volume>
    </event>
</events>
~Output http event headersContent-Length:24,Content-Location:'USA',Retry-After:120,Content-Type:'application/xml',HTTP_METHOD:'POST',~Output http event propertiesHTTP_METHOD:'POST',HOST:'localhost',PORT:8009PROTOCOL:'http'TO:'/foo'