• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Async Listener and Request/Response objects

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't retrieve ServletResponse object from AsyncEvent. I am using AsyncEvent#getSuppliedResponse() but I am getting null. I am adding the listener programmatically by AsyncContext#addListener(AsyncListener).
Servlet 3.0 Specification

public void addListener(asyncListener) - Registers the given listener
for notifications of time out, error and complete with the most recent
asynchronous cycle by a call to one of the ServletRequest.startAsync
methods. If startAsync(req, res) or startAsync() is called on the
request, the exact same request and response objects are available from the
AsyncEvent when the AsyncListener is notified.


Am I misinterpreting the explanation of this method. What should I do to get access to request or response object from my listener?
 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you are registering the listener using wrong method. Use AsyncContext#addListener(AsyncListener, ServletRequest, ServletResponse).

See the Javadocs for AsyncEvent#getSuppliedResponse():

public ServletResponse getSuppliedResponse()

Gets the ServletResponse from this AsyncEvent.
If the AsyncListener to which this AsyncEvent is being delivered was added using AsyncContext#addListener(AsyncListener, ServletRequest, ServletResponse), the returned ServletResponse will be the same as the one supplied to the above method. If the AsyncListener was added via AsyncContext#addListener(AsyncListener), this method must return null.

 
Stoian Azarov
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thansk Piuysh, It looks that I have to read more carefully the javadoc.
Now using the other #addListener() method I managed to retrieve the response.

I suppose that this sentence:

public void addListener(asyncListener)
...
If startAsync(req, res) or startAsync() is called on the
request, the exact same request and response objects are available from the
AsyncEvent when the AsyncListener is notified.


means that AsyncEvent has access to the request and response objects that were used when async process was started but we do not have access to them(especially using getSuppliedRequest/Response() methods).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic