<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dear Marc</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Sorry that I tried to reproduce the issue in my local test environment&nbsp;however I can't get body content anymore without ticking the stateful payload introspection&nbsp;option.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style=" background-color: rgb(255, 255, 255); display: inline !important">Besides I just enable 1 policy in order to simplify&nbsp;the test.</span><br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style=" background-color: rgb(255, 255, 255); display: inline !important">If you need more information, please let me know.</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style=" background-color: rgb(255, 255, 255); display: inline !important">Thanks for your help.</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>寄件者:</b> Marc Savy &lt;marc.savy@redhat.com&gt;<br>
<b>寄件日期:</b> 2018年6月12日 下午 10:28<br>
<b>收件者:</b> 林 柏廷<br>
<b>副本:</b> Eric Wittmann; apiman-user@lists.jboss.org<br>
<b>主旨:</b> Re: [Apiman-user] Is it possible blocking request after request body parsing?</font>
<div>&nbsp;</div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">I haven't been able to reproduce this. Could you please provide a bit<br>
more information so I can debug this.<br>
<br>
1. What is your policy chain<br>
2. Can you provide a skeleton policy that reproduces the issue where<br>
you say you are able to get a parsed entity without ticking the<br>
appropriate box in the UI?<br>
<br>
<br>
On 30 April 2018 at 02:16, 林 柏廷 &lt;btlin1025@hotmail.com&gt; wrote:<br>
&gt; Thanks for your information.<br>
&gt; I'll enable this option for parsing request body.<br>
&gt;<br>
&gt; ________________________________<br>
&gt; 寄件者: Marc Savy &lt;marc.savy@redhat.com&gt;<br>
&gt; 寄件日期: 2018年4月26日 下午 07:36<br>
&gt; 收件者: Eric Wittmann<br>
&gt; 副本: 林 柏廷; apiman-user@lists.jboss.org<br>
&gt;<br>
&gt; 主旨: Re: [Apiman-user] Is it possible blocking request after request body<br>
&gt; parsing?<br>
&gt;<br>
&gt; Thanks. I'll check it out and report back.<br>
&gt;<br>
&gt; On 26 April 2018 at 12:26, Eric Wittmann &lt;eric.wittmann@redhat.com&gt; wrote:<br>
&gt;&gt; Yes that is the UI option I was referring to.<br>
&gt;&gt;<br>
&gt;&gt; If the request payload is being parsed without that option being set, then<br>
&gt;&gt; there is a bug in the Apiman gateway.&nbsp; I will write up a bug report for<br>
&gt;&gt; that<br>
&gt;&gt; so that @marcsavy can have a look. :)<br>
&gt;&gt;<br>
&gt;&gt; -Eric<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Apr 26, 2018 at 4:36 AM, 林 柏廷 &lt;btlin1025@hotmail.com&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Dear Eric<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks for your helpful information.<br>
&gt;&gt;&gt; I can get request body with IPolicyContext object.<br>
&gt;&gt;&gt; Besides, you also mentioned enable this on a per-API basis in the apiman<br>
&gt;&gt;&gt; UI.<br>
&gt;&gt;&gt; Is It &quot;Enable stateful request payload insepction&quot; in API implementation<br>
&gt;&gt;&gt; tab?<br>
&gt;&gt;&gt; I'm wondering because I didn't enable this option but can still get the<br>
&gt;&gt;&gt; request body in doApply() with IPolicyContext.<br>
&gt;&gt;&gt; What is the difference if I enable this option?<br>
&gt;&gt;&gt; Thanks<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Regards<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; ________________________________<br>
&gt;&gt;&gt; 寄件者: Eric Wittmann &lt;eric.wittmann@redhat.com&gt;<br>
&gt;&gt;&gt; 寄件日期: 2018年4月25日 下午 08:15<br>
&gt;&gt;&gt; 收件者: 林 柏廷<br>
&gt;&gt;&gt; 副本: apiman-user@lists.jboss.org<br>
&gt;&gt;&gt; 主旨: Re: [Apiman-user] Is it possible blocking request after request body<br>
&gt;&gt;&gt; parsing?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Yes there is a feature where apiman will parse the request BEFORE<br>
&gt;&gt;&gt; applying<br>
&gt;&gt;&gt; the policies.&nbsp; This will make the HTTP request body available to all<br>
&gt;&gt;&gt; policies in the chain, should they need them.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; You can enable this on a per-API basis in the apiman UI.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; When this feature is enabled, your custom policy can access the request<br>
&gt;&gt;&gt; body as an object found in the IPolicyContext object.&nbsp; For example:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Object payload = context.getAttribute(&quot;apiman.request-payload&quot;);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The type of thing that you get depends on the API's endpoint type.&nbsp; The<br>
&gt;&gt;&gt; endpoint type might be JSON, XML, or SOAP.&nbsp; I think it might be possible<br>
&gt;&gt;&gt; to<br>
&gt;&gt;&gt; have some other kind of endpoint type, but those three are handled by the<br>
&gt;&gt;&gt; request body parser feature.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Here is what you'll get as that payload object, depending on endpoint<br>
&gt;&gt;&gt; type:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; JSON - Java Map object as a result of parsing the JSON data using Jackson<br>
&gt;&gt;&gt; XML - org.w3c.dom.Document<br>
&gt;&gt;&gt; Soap - javax.xml.soap.SOAPEnvelope<br>
&gt;&gt;&gt; Anything Else - byte[]<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; So for example, if your endpoint type is XML, then you could do this in<br>
&gt;&gt;&gt; your policy implementation (in the doApply() method):<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; org.w3c.dom.Document requestBody = (org.w3c.dom.Document)<br>
&gt;&gt;&gt; context.gettAttribute(&quot;apiman.request-payload&quot;);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; And then you could make some decision using the request data and e.g.<br>
&gt;&gt;&gt; call<br>
&gt;&gt;&gt; doFailure().<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Also note - you can *change* the request body at this point as well.&nbsp; For<br>
&gt;&gt;&gt; example you could apply a XML Transformation to the w3c Document,<br>
&gt;&gt;&gt; resulting<br>
&gt;&gt;&gt; in a new w3c Document object, which you could store in the Policy Context<br>
&gt;&gt;&gt; (at the same key, obviously).&nbsp; That new document would then get<br>
&gt;&gt;&gt; serialized<br>
&gt;&gt;&gt; and sent as the request body to the backing API impl.&nbsp; There may be some<br>
&gt;&gt;&gt; Content-Length issues if you do that, I can't remember...<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -Eric<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Apr 25, 2018 at 1:29 AM, 林 柏廷 &lt;btlin1025@hotmail.com&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hi all,<br>
&gt;&gt;&gt; I would like to customize a policy, which parses the request body and<br>
&gt;&gt;&gt; blocks the request in case.<br>
&gt;&gt;&gt; in <a href="http://www.apiman.io/latest/developer-guide.html">http://www.apiman.io/latest/developer-guide.html</a> 4.2.1.2 IData policy,<br>
&gt;&gt;&gt; it describes:<br>
&gt;&gt;&gt; The request or response body will not begin streaming before the<br>
&gt;&gt;&gt; corresponding doApply has been called, however, it is still possible to<br>
&gt;&gt;&gt; interrupt the conversation during the streaming phase by signalling<br>
&gt;&gt;&gt; doFailure or doError.<br>
&gt;&gt;&gt; When I trace the transformation-policy source code, doApply() executes<br>
&gt;&gt;&gt; before getRequestDataHandler() which matches the description.<br>
&gt;&gt;&gt; In doApply() I can blocks the request via chain.doFailure() however I<br>
&gt;&gt;&gt; have<br>
&gt;&gt;&gt; no idea how to interrupt/block request in getRequestDataHandler().<br>
&gt;&gt;&gt; Besides, I found following mail group which is similar to my question.<br>
&gt;&gt;&gt; Eric also points it's possible to parse the body before apply in request:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Thu, Feb 2, 2017 at 10:31 PM, Eric Wittmann &lt;<br>
&gt;&gt;&gt; eric.wittmann at redhat.com&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; The bottom line here is that you cannot return a Policy Failure (or<br>
&gt;&gt;&gt;&nbsp; customize it) based on information in the response body.&nbsp; The response<br>
&gt;&gt;&gt; is<br>
&gt;&gt;&gt;&nbsp; streamed from the back-end to the client, and at the time streaming<br>
&gt;&gt;&gt; begins,<br>
&gt;&gt;&gt;&nbsp; the response code and HTTP headers have already been sent.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; It sounds to me like you're asking for a feature where you can parse<br>
&gt;&gt;&gt;&nbsp; the response body *before* the policy's &quot;apply&quot; method is invoked.&nbsp; we<br>
&gt;&gt;&gt; have<br>
&gt;&gt;&gt;&nbsp; such a feature for requests, but not for responses.&nbsp; I suspect core<br>
&gt;&gt;&gt; changes<br>
&gt;&gt;&gt;&nbsp; to apiman would be required to enable that.&nbsp; It seems like a reasonable<br>
&gt;&gt;&gt;&nbsp; request to me, as long as users of the feature understand the<br>
&gt;&gt;&gt; performance<br>
&gt;&gt;&gt;&nbsp; and memory requirements of enabling it.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&nbsp; -Eric<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks for any comments in advance.<br>
&gt;&gt;&gt; Kind Regards<br>
&gt;&gt;&gt; BT<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Apiman-user mailing list<br>
&gt;&gt;&gt; Apiman-user@lists.jboss.org<br>
&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/apiman-user">https://lists.jboss.org/mailman/listinfo/apiman-user</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Apiman-user mailing list<br>
&gt;&gt; Apiman-user@lists.jboss.org<br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/apiman-user">https://lists.jboss.org/mailman/listinfo/apiman-user</a><br>
&gt;&gt;<br>
</div>
</span></font></div>
</body>
</html>