Search in sources :

Example 1 with OnRequestContent

use of io.gravitee.policy.api.annotations.OnRequestContent in project gravitee-gateway by gravitee-io.

the class OverrideRequestContentPolicy method onRequestContent.

@OnRequestContent
public ReadWriteStream onRequestContent(Request request) {
    return new BufferedReadWriteStream() {

        @Override
        public SimpleReadWriteStream<Buffer> write(Buffer content) {
            // We dot want to get the request content, skipping
            return this;
        }

        @Override
        public void end() {
            Buffer content = Buffer.buffer(STREAM_POLICY_CONTENT);
            request.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(content.length()));
            // Write content
            super.write(content);
            // Mark the end of content
            super.end();
        }
    };
}
Also used : Buffer(io.gravitee.gateway.api.buffer.Buffer) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) OnRequestContent(io.gravitee.policy.api.annotations.OnRequestContent)

Example 2 with OnRequestContent

use of io.gravitee.policy.api.annotations.OnRequestContent in project gravitee-gateway by gravitee-io.

the class TransformRequestContentPolicy method onRequestContent.

@OnRequestContent
public ReadWriteStream onRequestContent(Request request, ExecutionContext executionContext) {
    return new BufferedReadWriteStream() {

        Buffer buffer = Buffer.buffer();

        @Override
        public SimpleReadWriteStream<Buffer> write(Buffer content) {
            // We dot want to get the request content, skipping
            buffer.appendBuffer(content);
            return this;
        }

        @Override
        public void end() {
            String content = executionContext.getTemplateEngine().convert(buffer.toString());
            Buffer contentBuf = Buffer.buffer(content);
            request.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(contentBuf.length()));
            // Write content
            super.write(contentBuf);
            // Mark the end of content
            super.end();
        }
    };
}
Also used : Buffer(io.gravitee.gateway.api.buffer.Buffer) BufferedReadWriteStream(io.gravitee.gateway.api.stream.BufferedReadWriteStream) OnRequestContent(io.gravitee.policy.api.annotations.OnRequestContent)

Aggregations

Buffer (io.gravitee.gateway.api.buffer.Buffer)2 BufferedReadWriteStream (io.gravitee.gateway.api.stream.BufferedReadWriteStream)2 OnRequestContent (io.gravitee.policy.api.annotations.OnRequestContent)2