Apama 10.7.2 | Connecting Apama Applications to External Components | Standard Connectivity Plug-ins | The HTTP Client Transport Connectivity Plug-in | Mapping events between EPL and HTTP client requests | Distinguishing response types
 
Distinguishing response types
A single chain will often deal with multiple event types in either direction. In the direction towards the transport, the type is already known and can be used to create multiple stanzas in the Mapper codec. For messages towards the host, the event type will not yet have been set. The Classifier codec can use fields in the message (payload or metadata) to set the event type.
For the HTTP client, one of the major distinctions is between success replies and various types of failure. The HTTP status code (metadata.http.statusCode) is used to determine whether or not the response is a success. Typically, a response code of 200 indicates that the request was a success, and anything else would be some kind of error. Both errors returned by the remote host and issues which occur within the client itself are returned as messages with a status code other than 200.
For example, a Classifier codec which wants to just distinguish errors and success would look as follows:
- classifierCodec:
rules:
- MyResponse:
- metadata.http.statusCode: 200
- Error:
- metadata.http.statusCode:
There may also be multiple types of success response, possibly from requests to different URLs in the same host. You can use other fields from the metadata or the payload to set the event type. For example:
- classifierCodec:
rules:
- LoginSuccess: # OK response with a session cookie set
- metadata.http.statusCode: 200
- metadata.http.cookies.session:
- DataResponse1:
- metadata.http.statusCode: 200
- payload.datatype: foo
- DataResponse2:
- metadata.http.statusCode: 200
- metadata.http.path: /data2
- Error:
- metadata.http.statusCode: