I have a servlet which is used to fetch data from many third party REST datapoints, integrate all the data and report the data in a HTML format. I also have a filter which has the following flow -
- Create an event record when the request hits the filter and add the eventrecord object to the request
- perform chain.doFilter - which allows the servlet to add more details to the eventrecord
- on the way back to the browser, filter gets the eventrecord object and logs it.
Now if I use Asynchronous servlet using AsyncContext context = request.getAsyncContext();
, which will talk to the same REST datapoints but as and when data is ready, it will write to the response stream instead of waiting for all the REST data points to respond, how would I re write my filter ? Would it be attached to the thread which is responsible for flushing data from the REST data points so that once all the data is processed and flused, it will log the eventrecord ?
Is there any common pattern that I can study to understand how such use cases can be handled with Servlet 3.0's asynchronous servlets ?
I am using JDK 6.0, Tomcat 7.0.
AsyncContext
? I'm confused. – Singletary