<div dir="ltr">If I understand you correctly Eric, only the soap:Body part will be forwarded to the registered API?<div>What if the API still needs to receive the soap:Header part?</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-03-29 15:34 GMT+02:00 Keith Babo <span dir="ltr"><<a href="mailto:kbabo@redhat.com" target="_blank">kbabo@redhat.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sounds cool to me. Header policy will need to be QName and DOM-aware, so that namespace-qualified headers can be added and appropriate namespace definitions can be added to the DOM if required. Of course you already know all this, but pointing it out makes me feel useful.<br>
<div class="HOEnZb"><div class="h5"><br>
> On Mar 29, 2016, at 8:38 AM, Eric Wittmann <<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>> wrote:<br>
><br>
> That's an interesting idea. It'd be harder to inject the headers into the request than it is to inject HTTP request headers, obviously. But not impossible. We'd need to be aware of the change to any Content-Length that may be set.<br>
><br>
> This makes the implementation slightly more complicated, because I think the HTTP connector will need to be made smarter (it will need to send the <soap:Envelope> and <soap:Header> sections first, then just stream the remaining request body as-is.<br>
><br>
> So perhaps what we have is this:<br>
><br>
> 1. <?xml version="1.0"?><br>
> 2. <soap:Envelope xmlns:soap="<a href="http://www.w3.org/2003/05/soap-envelope" rel="noreferrer" target="_blank">http://www.w3.org/2003/05/soap-envelope</a>"><br>
> 3. <soap:Header><br>
> 4. <ns1:Foo actor="..." xmlns:ns1="uri:ns1">BAR</ns1:Foo><br>
> 5. </soap:Header><br>
> 6. <soap:Body><br>
> 7. <m:GetStockPrice xmlns:m="<a href="http://www.example.org/stock/Surya" rel="noreferrer" target="_blank">http://www.example.org/stock/Surya</a>"><br>
> 8. <m:StockName>IBM</m:StockName><br>
> 9. </m:GetStockPrice><br>
> 10. </soap:Body><br>
> 11. </soap:Envelope><br>
><br>
> Lines 1-5 will be read and consumed by apiman *before* any policies are executed. We'll actually keep reading until we find <soap:Body> in the request body. We'll throw out everything before line #6 from our in-memory buffer, resulting in a buffer with just line #6 (and any extra bytes after that based on our I/O chunk size).<br>
><br>
> The policies will be executed, which may result in soap headers being added, modified, or removed. If all policies pass, then we proxy the request to the back-end. Normally the HTTP connection would simply send all bytes from the HTTP request as-is. Instead, we'll need to *generate* new content for lines 1-5, with the newly modified soap headers. Once the generated content is sent, then we send the contents of the in-memory buffer (which contains line #6+ any additional bytes). After that, we proxy the remaining bytes from the HTTP request as-is.<br>
><br>
> This may be starting to take shape. :)<br>
><br>
> Additional thoughts?<br>
><br>
> -Eric<br>
><br>
> PS: @Keith - we'll likely have a separate Policy for manipulating SOAP headers, rather than re-use the existing HTTP headers policy.<br>
><br>
> On 3/29/2016 8:13 AM, Keith Babo wrote:<br>
>> Sounds like a reasonable first step to me. Just to make life slightly<br>
>> more complicated, will the headers policy be updated to allow add/remove<br>
>> of SOAP:Headers? :-)<br>
>><br>
>> ~ keith<br>
>><br>
>>> On Mar 29, 2016, at 7:52 AM, Eric Wittmann <<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>>> wrote:<br>
>>><br>
>>> OK so here's what I propose (feedback welcome):<br>
>>><br>
>>> *If* an API's 'type' is set to SOAP, then we will *always* look for a<br>
>>> soap envelope in the body. If no body is found or no soap envelope is<br>
>>> found in the body, then a standard apiman error will be thrown.<br>
>>><br>
>>> If an envelope *is* found, then we will read the body of the HTTP<br>
>>> request until we find "<soap:Body>". We'll extract the <soap:Header><br>
>>> and parse its children. While parsing, we'll obviously keep the data<br>
>>> we read in a memory buffer. Once parsing is done, we'll include the<br>
>>> soap headers, soap action, and the global encoding type in some sort<br>
>>> of soapinfo object and include that in the policy context.<br>
>>><br>
>>> Finally, after all that is done, we'll process the request as normal,<br>
>>> executing the policy chain, then processing the request body, etc. The<br>
>>> entire request payload will still be processed (remember that we saved<br>
>>> the bytes we read in a memory buffer).<br>
>>><br>
>>> So from the perspective of a policy, everything will look identical<br>
>>> except that a SOAPInfo object will be available in the policy context.<br>
>>><br>
>>> Thoughts?<br>
>>><br>
>>> -Eric<br>
>>><br>
>>> On 3/28/2016 1:48 PM, Benjamin Kastelic wrote:<br>
>>>> Yup, I agree. That would probably be best, since several validators<br>
>>>> (wss4j for example) require DOM Elements (javax.xml.soap.SOAPHeader) to<br>
>>>> function.<br>
>>>><br>
>>>> Best regards,<br>
>>>> Benjamin<br>
>>>><br>
>>>> 2016-03-28 19:14 GMT+02:00 Eric Wittmann <<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>>>:<br>
>>>><br>
>>>> Thanks! In that case, making the headers available as DOM Element<br>
>>>> objects (perhaps with a simple QName based lookup) would be best.<br>
>>>><br>
>>>> -Eric<br>
>>>><br>
>>>> On 3/28/2016 12:39 PM, Keith Babo wrote:<br>
>>>><br>
>>>> SOAP:Headers can be complex types. WS-Security is a good<br>
>>>> example of<br>
>>>> this in practice.<br>
>>>><br>
>>>> ~ keith<br>
>>>><br>
>>>> On Mar 28, 2016, at 11:37 AM, Eric Wittmann<br>
>>>> <<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>><mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>>>> wrote:<br>
>>>><br>
>>>> That's a bit hacky, but also sort of a genius approach as<br>
>>>> well. I'm<br>
>>>> actually a little bummed I didn't think of it. :)<br>
>>>><br>
>>>> As for extending SOAP support - I was thinking that I could<br>
>>>> make the<br>
>>>> relevant changes to apiman if you would be willing to provide<br>
>>>> feedback/guidance/testing. My SOAP expertise is quite stale<br>
>>>> at this<br>
>>>> point, so having some eyeballs on these changes would be<br>
>>>> very useful.<br>
>>>><br>
>>>> To start off with, what pieces of the SOAP envelope should<br>
>>>> be extracted<br>
>>>> prior to calling the policy chain? Some candidates are:<br>
>>>><br>
>>>> * The encoding style<br>
>>>> * All SOAP headers<br>
>>>> * SOAPAction (already available as an HTTP header)<br>
>>>> * ???<br>
>>>><br>
>>>> For the soap headers, all of the examples I've seen take the<br>
>>>> following<br>
>>>> form:<br>
>>>><br>
>>>> <HeaderName xmlns="elementNS">Header-Value</HeaderName><br>
>>>><br>
>>>> It can also have the optional "actor" or "mustUnderstand"<br>
>>>> attributes.<br>
>>>> The SOAP envelope schema is pretty lax though, so I'm not<br>
>>>> sure if the<br>
>>>> above is a convention or a rule. Can headers be more<br>
>>>> complex than the<br>
>>>> above?<br>
>>>><br>
>>>> -Eric<br>
>>>><br>
>>>> On 3/26/2016 7:06 AM, Benjamin Kastelic wrote:<br>
>>>><br>
>>>> Hi,<br>
>>>><br>
>>>> I temporarily solved the problem by storing the request<br>
>>>> body, which is<br>
>>>> contained in ApiRequest.rawRequest object, in a<br>
>>>> temporary buffer. I then<br>
>>>> process the data (authentication) and based on the<br>
>>>> results proceed with<br>
>>>> the policy chain or report a failure. Then in the end()<br>
>>>> method of the<br>
>>>> requestDataHandler method I write the contents of my<br>
>>>> temporary buffer<br>
>>>> using super.write(IApimanBuffer). That way I can forward<br>
>>>> the request to<br>
>>>> then ext policy in the chain. But this is still a hacky<br>
>>>> way of doing<br>
>>>> this.<br>
>>>><br>
>>>> I would be glad to help with extending SOAP support. But<br>
>>>> I would need a<br>
>>>> few pointers where to start. The way of storing SOAP<br>
>>>> headers in the<br>
>>>> ApiRequest object seems like a good idea.<br>
>>>><br>
>>>> 2016-03-24 18:40 GMT+01:00 Eric Wittmann<br>
>>>> <<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>><mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>>><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a><br>
>>>> <mailto:<a href="mailto:eric.wittmann@redhat.com">eric.wittmann@redhat.com</a>>>>:<br>
>>>><br>
>>>> Hi Benjamin - thanks for the excellent question. I<br>
>>>> will do my best<br>
>>>> to answer and note that I am CC'ing the apiman-dev<br>
>>>> mailing list so<br>
>>>> others can chime in.<br>
>>>><br>
>>>> First let me say that a WS-Security policy sounds<br>
>>>> great - we haven't<br>
>>>> focused much on the WS-* protocols because we get<br>
>>>> much more demand<br>
>>>> for managing REST APIs than SOAP APIs. That said,<br>
>>>> better SOAP<br>
>>>> support is certainly on the radar. When that<br>
>>>> happens, my hope is<br>
>>>> that processing the envelope might be a core part of<br>
>>>> the gateway and<br>
>>>> so implementing policies that use information in<br>
>>>> there will be<br>
>>>> easier. Perhaps your implementation can be the<br>
>>>> genesis of some of<br>
>>>> that work!<br>
>>>><br>
>>>> To your question - without core changes to apiman,<br>
>>>> the approach you<br>
>>>> *need* to take is to have your policy implement<br>
>>>> IDataPolicy. I<br>
>>>> believe you may have already tried that, and<br>
>>>> observed that you<br>
>>>> cannot send proper policy failures from that<br>
>>>> method. You are right<br>
>>>> - that's something we will need to fix! I think you<br>
>>>> should be able<br>
>>>> to throw a runtime exception from the<br>
>>>> write(IApimanBuffer chunk)<br>
>>>> method if you detect an error. However, this is a<br>
>>>> little bit hacky!<br>
>>>><br>
>>>> Instead, I suggest (if you're up for it) that we<br>
>>>> perhaps work<br>
>>>> together to bake SOAP support directly into the core<br>
>>>> of apiman, such<br>
>>>> that the SOAP envelope is read/parsed *before* the<br>
>>>> policy chain is<br>
>>>> executed. We could expose, for example, the SOAP<br>
>>>> headers as a<br>
>>>> proper Map<> stored either in the context or on the<br>
>>>> ApiRequest.<br>
>>>> This would allow you to properly implement most<br>
>>>> (all?) WS-*<br>
>>>> protocols as proper apiman policies in the<br>
>>>> apply(ApiRequest request)<br>
>>>> method.<br>
>>>><br>
>>>> Thoughts?<br>
>>>><br>
>>>> -Eric<br>
>>>><br>
>>>><br>
>>>> On 3/24/2016 7:58 AM, Benjamin Kastelic wrote:<br>
>>>><br>
>>>> Greetings,<br>
>>>><br>
>>>> I first thought to write this question as an<br>
>>>> issue on Github,<br>
>>>> but it<br>
>>>> seemed better to write you a direct email.<br>
>>>><br>
>>>> I am making a custom WS Security policy, that<br>
>>>> reads the body and<br>
>>>> check<br>
>>>> the UsernameToken security header. This works<br>
>>>> OK, but now I've<br>
>>>> hit a wall.<br>
>>>><br>
>>>> In the doApply method I get the rawRequest<br>
>>>> object and read the<br>
>>>> body from<br>
>>>> the ServletInputStream of the request. The<br>
>>>> problem I'm facing<br>
>>>> now is<br>
>>>> that the input stream was read and it can't be<br>
>>>> reset back to it's<br>
>>>> initial state.<br>
>>>><br>
>>>> I was also trying to implement the same logic<br>
>>>> in the<br>
>>>> requestDataHandler<br>
>>>> method, but I don't know if it is even possible<br>
>>>> to send a failure<br>
>>>> message to the request chain from there.<br>
>>>><br>
>>>> Any suggesstions ?<br>
>>>><br>
>>>> Best regards,<br>
>>>> Benjamin<br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> --<br>
>>>> Lp, Benjamin<br>
>>>><br>
>>>> _______________________________________________<br>
>>>> Apiman-dev mailing list<br>
>>>> <a href="mailto:Apiman-dev@lists.jboss.org">Apiman-dev@lists.jboss.org</a> <mailto:<a href="mailto:Apiman-dev@lists.jboss.org">Apiman-dev@lists.jboss.org</a>><br>
>>>> <mailto:<a href="mailto:Apiman-dev@lists.jboss.org">Apiman-dev@lists.jboss.org</a>><br>
>>>> <mailto:<a href="mailto:Apiman-dev@lists.jboss.org">Apiman-dev@lists.jboss.org</a><br>
>>>> <mailto:<a href="mailto:Apiman-dev@lists.jboss.org">Apiman-dev@lists.jboss.org</a>>><br>
>>>> <a href="https://lists.jboss.org/mailman/listinfo/apiman-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/apiman-dev</a><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> --<br>
>>>> Lp, Benjamin<br>
>><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Lp, Benjamin</div></div>
</div>