<div dir="ltr">Hi,<div><br></div><div>Perhaps URLRewritingPolicy <a href="https://github.com/apiman/apiman/blob/master/gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/URLRewritingPolicy.java">https://github.com/apiman/apiman/blob/master/gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/URLRewritingPolicy.java</a> be an informative place to start?</div><div><br></div><div>- Apiman streams data, so the client may be receiving data already by the time you&#39;ve determined you want to cancel (the connection is already established; headers have been sent) - it&#39;s often too late to gracefully cancel. You could try throwing an exception and seeing what happens (not recommended practice!).</div><div><br></div><div>If that doesn&#39;t work, perhaps you can explain your use-case more clearly and explicitly so we can see what the alternatives are?</div><div><br></div><div>- Policies are *static* instances, if you are assigning that buffer to the object then it&#39;s as if you were writing &quot;static Buffer  buffer&quot; and different requests will all share that variable (and thus swap it out repeatedly!).</div><div><br></div><div>Regards,</div><div>Marc</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 February 2017 at 16:56, Balu S <span dir="ltr">&lt;<a href="mailto:sbalu27@gmail.com" target="_blank">sbalu27@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div>I&#39;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&#39;t find a way to throw policy failure from responseDataHandler(). And I cannot achieve this in doApply() as the ApiResponse object does not have &quot;content&quot; to parse. </div><div><br></div><div>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().</div><div><br></div><div>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.</div><div><br></div><div><br></div><div><b>URLRewritingPolicy.java</b><br></div><div><br></div><div><div>    @Override</div><div>    protected IReadWriteStream&lt;ApiResponse&gt; responseDataHandler(<wbr>ApiResponse response,</div><div>            IPolicyContext context, URLRewritingConfig policyConfiguration) {</div><div>        if (policyConfiguration.<wbr>isProcessResponseBody()) {</div><div>            return new URLRewritingStream(context.<wbr>getComponent(<wbr>IBufferFactoryComponent.class)<wbr>, response,</div><div>                    policyConfiguration.<wbr>getFromRegex(), policyConfiguration.<wbr>getToReplacement());</div><div>        } else {</div><div>            return null;</div><div>        }</div><div>    }</div></div><div><b><br></b></div><div><b>URLRewritingStream.java</b><br></div><div><br></div><div><div>    /**</div><div>     * @see <a href="http://io.apiman.gateway.engine.io">io.apiman.gateway.engine.io</a>.<wbr>AbstractStream#write(io.<wbr><a href="http://apiman.gateway.engine.io">apiman.gateway.engine.io</a>.<wbr>IApimanBuffer)</div><div>     */</div><div>    @Override</div><div>    public void write(IApimanBuffer chunk) {</div><div>        if (buffer == null) {</div><div>            buffer = bufferFactory.cloneBuffer(<wbr>chunk);</div><div>        } else {</div><div>            buffer.append(chunk);</div><div>        }</div><div>        atEnd = false;</div><div>        processBuffer();</div><div>    }</div></div><div><br></div><div><br></div><div>Best regards</div><span class="HOEnZb"><font color="#888888"><div>Balu</div></font></span></div>
<br>______________________________<wbr>_________________<br>
Apiman-user mailing list<br>
<a href="mailto:Apiman-user@lists.jboss.org">Apiman-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/apiman-user" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/apiman-user</a><br>
<br></blockquote></div><br></div>