[Apiman-user] API policy response data handler

Balu S sbalu27 at gmail.com
Thu Feb 2 11:56:37 EST 2017


Hello,
I'm trying to parse the response using responseDataHandler() in the custom
policy. In cases, if the response from API is of certain content, I would
like the Apiman to consider as failure. But I don't find a way to throw
policy failure from responseDataHandler(). And I cannot achieve this in
doApply() as the ApiResponse object does not have "content" to parse.

Also, what I found is write(chunk) in the AbstractStream is called after
doApply, so I cannot set any attributes in it to fetch it in doApply() and
trigger doFailure().

For example, in below call, how to throw as policy failure after parsing
the contents ? Or how can I access response content even before write()
method.


*URLRewritingPolicy.java*

    @Override
    protected IReadWriteStream<ApiResponse> responseDataHandler(ApiResponse
response,
            IPolicyContext context, URLRewritingConfig policyConfiguration)
{
        if (policyConfiguration.isProcessResponseBody()) {
            return new
URLRewritingStream(context.getComponent(IBufferFactoryComponent.class),
response,
                    policyConfiguration.getFromRegex(),
policyConfiguration.getToReplacement());
        } else {
            return null;
        }
    }

*URLRewritingStream.java*

    /**
     * @see
io.apiman.gateway.engine.io.AbstractStream#write(io.apiman.gateway.engine.io.IApimanBuffer)
     */
    @Override
    public void write(IApimanBuffer chunk) {
        if (buffer == null) {
            buffer = bufferFactory.cloneBuffer(chunk);
        } else {
            buffer.append(chunk);
        }
        atEnd = false;
        processBuffer();
    }


Best regards
Balu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/apiman-user/attachments/20170202/129e7905/attachment.html 


More information about the Apiman-user mailing list