[undertow-dev] How to get response bytes before they are sent

Nagaraj,Vikas Vikas.Nagaraj at safenet-inc.com
Wed Feb 17 14:10:49 EST 2016


Hello,

Is it possible to get the full content of a response body before it's sent?  I'm trying to sign the response and add this signature in a header.  There was a similar question on this list a couple of weeks ago, but that one was about signing the incoming request.  My current approach is, in HttpHandler.handleRequest():

- Create a javax.crypto.Signature object
- Use HttpServerExchange. addResponseWrapper() to add a StreamSinkConduit that updates the Signature object as write() is called
- Use HttpServerExchange.addResponseCommitListener() to add a callback that calls Signature.sign() when the response is ready to be sent

Good in theory, but I'm finding that the sign happens before the updates - looks like the Conduit is only active as the response is being sent.  Is there something else I should wrap to get the bytes as they're being added to the response?  Even better would be if I could read them directly from the ResponseCommitListener.beforeCommit() callback.  I can see the number of bytes that have been written, but not the actual data.

Note: I'm using Undertow 1.2.x, as we're on WildFly 9.

--
Vikas Nagaraj
vikas.nagaraj at safenet-inc.com<mailto:vikas.nagaraj at safenet-inc.com>




-- 
The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20160217/b8fc62ab/attachment.html 


More information about the undertow-dev mailing list