Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Understanding AsyncMiddleManServlet request lifecycle

I've done some more digging here, but I'm still not exactly sure what I'm observing.

I think this observation is related to POSTing data that needs to be asynchronously proxied to the backend service.

https://gist.github.com/stevenschlansker/ad5734d54765ab2f1a738a3345eafafa

It looks to me like the request starts copying data, and goes to the DISPATCHED / ASYNC_IO / STREAM states.
Then the onProxyResponseSuccess callback is invoked ("success" in the log)

Then, the same (?) request gets re-dispatched and eventually goes DISPATCHED -> IDLE.

This surprises me, I would have thought that the onProxyResponseSuccess callback is only called after the
entire HTTP exchange is complete, but it looks like it is getting called first when we start proxying data
(with the attribute map and other properties intact) and then again after the entire exchange completes,
but the second time all of the attributes and other interesting properties have been cleared.

Either that, or these are two totally unrelated requests to the same endpoint, but if that is the case
I then have one of them being cleared before success, and one not.  That's a confusing result too.

Any thoughts on what's going on here?  Thanks a bunch!

> On Nov 3, 2017, at 3:56 PM, Steven Schlansker <stevenschlansker@xxxxxxxxx> wrote:
> 
> I'm trying to extend the Requests created by my Awesome Jetty Based Proxy 2.0 to include company specific metadata.
> 
> I instrument it before sending it off to the base impl:
> 
> @Override
> public void service(HttpServletRequest req, HttpServletResponse resp) {
>    final ProxyContext ctx = new ProxyContext(req, resp, ...);
>    request.setAttribute(PROXY_CONTEXT, ctx);
>    LOG.debug("context instrumented '{}': {}", ServletUtil.uriIncludingQueryString(request), request);
>    super.service(req, resp);
> }
> 
> 
> @Override
> protected void onProxyResponseSuccess(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse) {
>    super.onProxyResponseSuccess(clientRequest, proxyResponse, serverResponse);
>    if (clientRequest.getAttribute(PROXY_CONTEXT) == null) {
>        LOG.debug("No proxy context on {}", ToStringBuilder.reflectionToString(clientRequest));
>    }
> }
> 
> It sure looks like the request object is getting recycled before the callback is being invoked.  But that seems crazy!  How am I to do anything with it if all fields are nulled out first?
> 


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail


Back to the top