Search in sources :

Example 6 with Buffer

use of io.gravitee.gateway.api.buffer.Buffer 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)6 BufferedReadWriteStream (io.gravitee.gateway.api.stream.BufferedReadWriteStream)3 OnRequestContent (io.gravitee.policy.api.annotations.OnRequestContent)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 UrlEscapers (com.google.common.net.UrlEscapers)1 HttpHeaders (io.gravitee.common.http.HttpHeaders)1 HttpMethod (io.gravitee.common.http.HttpMethod)1 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 Api (io.gravitee.definition.model.Api)1 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)1 Invoker (io.gravitee.gateway.api.Invoker)1 Request (io.gravitee.gateway.api.Request)1 Endpoint (io.gravitee.gateway.api.endpoint.Endpoint)1 EndpointManager (io.gravitee.gateway.api.endpoint.EndpointManager)1 Handler (io.gravitee.gateway.api.handler.Handler)1 ProxyConnection (io.gravitee.gateway.api.proxy.ProxyConnection)1 ProxyRequest (io.gravitee.gateway.api.proxy.ProxyRequest)1 ProxyRequestBuilder (io.gravitee.gateway.api.proxy.builder.ProxyRequestBuilder)1 ReadStream (io.gravitee.gateway.api.stream.ReadStream)1 ReadWriteStream (io.gravitee.gateway.api.stream.ReadWriteStream)1