Apama 10.7.2 | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The HTTP Server Transport Connectivity Plug-in | Mapping events between EPL and HTTP server requests | Handling HTTP form decoding
 
Handling HTTP form decoding
The HTTP server transport decodes multipart/form-data or application/x-www-form-urlencoded media types to a dictionary payload.
If the Content-Type header field contains the application/x-www-form-urlencoded media type, the request payload is decoded to a dictionary payload with string keys and string values.
If the Content-type header field contains the multipart/form-data media type, the request payload is decoded to a dictionary payload with string keys and either string or binary values.
For the parts that have binary data, additional metadata is created. This metadata contains the contentType, charset and filename information for each binary part.
You can get the metadata as follows:
metadata.http.form.name.contentType
metadata.http.form.name.charset
metadata.http.form.name.filename
where name corresponds to the data in payload.name.
Simple example
In this example, a client sends HTTP POST requests to the HTTP server transport and the Content-Type header is set to multipart/form-data. The request payload contains two form fields, one field has both a string key and string value, and the other field has a string key and binary value.
Simple raw HTTP POST request:
POST http://localhost:80/
Content-Length: 737
Content-Type: multipart/form-data; boundary=--123456789
--123456789
Content-Disposition: form-data; name="foo"
bar
--123456789
Content-Disposition: form-data; name="file"; filename="file.txt"
Content-Type: text/plain; charset=utf-8
File data
--123456789--
For the above request, the HTTP server transport sends a dictionary payload({"foo":"bar", "file":File data}) to EPL.
Metadata created for the file parts have text/plain as the content type, utf-8 as the character set, and file.txt as the filename. You can map the metadata using the Mapper codec:
- mapperCodec:
"*":
towardsHost:
mapFrom:
- payload.contentType: metadata.http.form.file.contentType
- payload.charset: metadata.http.form.file.charset
- payload.filename: metadata.http.form.file.filename
Parts metadata is only created for binary or file-upload form-data.