public static interface AsyncMiddleManServlet.ContentTransformer
Allows applications to transform upstream and downstream content.
Typical use cases of transformations are URL rewriting of HTML anchors
(where the value of the href
attribute of <a> elements
is modified by the proxy), field renaming of JSON documents, etc.
Applications should override AsyncMiddleManServlet.newClientRequestContentTransformer(HttpServletRequest, Request)
and/or AsyncMiddleManServlet.newServerResponseContentTransformer(HttpServletRequest, HttpServletResponse, Response)
to provide the transformer implementation.
Modifier and Type | Field and Description |
---|---|
static AsyncMiddleManServlet.ContentTransformer |
IDENTITY
The identity transformer that does not perform any transformation.
|
Modifier and Type | Method and Description |
---|---|
void |
transform(ByteBuffer input,
boolean finished,
List<ByteBuffer> output)
Transforms the given input byte buffers into (possibly multiple) byte buffers.
|
static final AsyncMiddleManServlet.ContentTransformer IDENTITY
void transform(ByteBuffer input, boolean finished, List<ByteBuffer> output) throws IOException
Transforms the given input byte buffers into (possibly multiple) byte buffers.
The transformation must happen synchronously in the context of a call
to this method (it is not supported to perform the transformation in another
thread spawned during the call to this method).
The transformation may happen or not, depending on the transformer implementation.
For example, a buffering transformer may buffer the input aside, and only
perform the transformation when the whole input is provided (by looking at the
finished
flag).
The input buffer will be cleared and reused after the call to this method. Implementations that want to buffer aside the input (or part of it) must copy the input bytes that they want to buffer.
Typical implementations:
// Identity transformation (no transformation, the input is copied to the output) public void transform(ByteBuffer input, boolean finished, List<ByteBuffer> output) { output.add(input); } // Discard transformation (all input is discarded) public void transform(ByteBuffer input, boolean finished, List<ByteBuffer> output) { // Empty } // Buffering identity transformation (all input is buffered aside until it is finished) public void transform(ByteBuffer input, boolean finished, List<ByteBuffer> output) { ByteBuffer copy = ByteBuffer.allocate(input.remaining()); copy.put(input).flip(); store(copy); if (finished) { List<ByteBuffer> copies = retrieve(); output.addAll(copies); } }
input
- the input content to transform (may be of length zero)finished
- whether the input content is finished or more will comeoutput
- where to put the transformed output contentIOException
- in case of transformation failuresCopyright © 1995-2015 Webtide. All Rights Reserved.