Reputation: 24641
After the original call to servlet.doGet() has returned, asyncContext.getRequest().getServletContext() seems to return null. How do I get the ServletContext in a plain Java method given only the AsyncEvent or AsyncContext? I. e. outside the scope of a doGet(), doPost() or one of the other servlet methods?
Upvotes: 2
Views: 631
Reputation: 7943
I do not know of a way to get the ServletContext out of these objects thus I would go with an approach of setting it directly yourself.
Similar approach I use in this answer where I am setting the context for a Quartz Scheduler's job.
If in your case it is your regular Java class just pass it on creation or have a setter method.
Upvotes: 1