The interface used when you wish to transform Request or Response body content. More...
#include <TransformationPlugin.h>
Inherits atscppapi::TransactionPlugin.
Inherited by atscppapi::transformations::GzipDeflateTransformation, and atscppapi::transformations::GzipInflateTransformation.
Public Types | |
enum | Type { REQUEST_TRANSFORMATION = 0, RESPONSE_TRANSFORMATION } |
The available types of Transformations. More... | |
Public Member Functions | |
virtual void | consume (const std::string &data)=0 |
A method that you must implement when writing a TransformationPlugin, this method will be fired whenever an upstream TransformationPlugin has produced output. | |
virtual void | handleInputComplete ()=0 |
A method that you must implement when writing a TransformationPlugin, this method will be fired whenever the upstream TransformationPlugin has completed writing data. | |
virtual | ~TransformationPlugin () |
Destructor for a TransformationPlugin. | |
Protected Member Functions | |
size_t | produce (const std::string &) |
This method is how a TransformationPlugin will produce output for the downstream transformation plugin, if you need to produce binary data this can still be done with strings by a call to string::assign() or by constructing a string with string::string(char *, size_t). | |
size_t | setOutputComplete () |
This is the method that you must call when you're done producing output for the downstream TranformationPlugin. | |
TransformationPlugin (Transaction &transaction, Type type) | |
a TransformationPlugin must implement this interface, it cannot be constructed directly |
The interface used when you wish to transform Request or Response body content.
Transformations are deceptively simple, transformations are chained so the output of one TransformationPlugin becomes the input of another TransformationPlugin. As data arrives it will fire a consume() and when all the data has been sent you will receive a handleInputComplete(). Data can be sent to the next TransformationPlugin in the chain by calling produce() and when the transformation has no data left to send it will fire a setOutputCompete().
Since a TransformationPlugin is a type of TransactionPlugin you can call registerHook() and establish any hook for a Transaction also; however, remember that you must implement the appropriate callback for any hooks you register.
A simple example of how to use the TransformationPlugin interface follows, this is an example of a Response transformation, the avialable options are REQUEST_TRANSFORMATION and RESPONSE_TRANSFORMATION which are defined in Type.
This example is a Null Transformation, meaning it will just spit out the content it receives without actually doing any work on it.
class NullTransformationPlugin : public TransformationPlugin { public: NullTransformationPlugin(Transaction &transaction) : TransformationPlugin(transaction, RESPONSE_TRANSFORMATION) { registerHook(HOOK_SEND_RESPONSE_HEADERS); } void handleSendResponseHeaders(Transaction &transaction) { transaction.getClientResponse().getHeaders().set("X-Content-Transformed", "1"); transaction.resume(); } void consume(const string &data) { produce(data); } void handleInputComplete() { setOutputComplete(); } };
Definition at line 81 of file TransformationPlugin.h.
The available types of Transformations.
REQUEST_TRANSFORMATION |
Transform the Request body content. |
RESPONSE_TRANSFORMATION |
Transform the Response body content. |
Definition at line 86 of file TransformationPlugin.h.
virtual atscppapi::TransformationPlugin::~TransformationPlugin | ( | ) | [virtual] |
Destructor for a TransformationPlugin.
atscppapi::TransformationPlugin::TransformationPlugin | ( | Transaction & | transaction, | |
Type | type | |||
) | [protected] |
a TransformationPlugin must implement this interface, it cannot be constructed directly
virtual void atscppapi::TransformationPlugin::consume | ( | const std::string & | data | ) | [pure virtual] |
A method that you must implement when writing a TransformationPlugin, this method will be fired whenever an upstream TransformationPlugin has produced output.
Implemented in atscppapi::transformations::GzipDeflateTransformation, and atscppapi::transformations::GzipInflateTransformation.
virtual void atscppapi::TransformationPlugin::handleInputComplete | ( | ) | [pure virtual] |
A method that you must implement when writing a TransformationPlugin, this method will be fired whenever the upstream TransformationPlugin has completed writing data.
Implemented in atscppapi::transformations::GzipDeflateTransformation, and atscppapi::transformations::GzipInflateTransformation.
size_t atscppapi::TransformationPlugin::produce | ( | const std::string & | ) | [protected] |
This method is how a TransformationPlugin will produce output for the downstream transformation plugin, if you need to produce binary data this can still be done with strings by a call to string::assign() or by constructing a string with string::string(char *, size_t).
size_t atscppapi::TransformationPlugin::setOutputComplete | ( | ) | [protected] |
This is the method that you must call when you're done producing output for the downstream TranformationPlugin.