Bug 49937 - Problems with AsyncListener and resource injection
Summary: Problems with AsyncListener and resource injection
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-16 01:49 UTC by david jencks
Modified: 2010-10-03 17:00 UTC (History)
0 users



Attachments
propose fix for a couple possible async listener problems (3.12 KB, patch)
2010-09-16 01:49 UTC, david jencks
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description david jencks 2010-09-16 01:49:41 UTC
Created attachment 26031 [details]
propose fix for a couple possible async listener problems

I asked about these on the dev list and am proposing some simple fixes in case there's agreement that they are bugs.

1. AsyncListeners are subject to resource injection from annotations, so they should be created using the instance manager. To get the instance manager to the AyncContextImpl I added a getInstanceManager() method to the Context interface.  Maybe there's a better way, this interface is currently not very small or simple.

2. various application code can use one of the ServletContext.addListener methods to tell the container to scan for annotations.  Just because tomcat doesn't yet actually scan doesn't mean it should throw an exception if you try this.

cf servlet 3.0 spec section 15.5 page 179.
Comment 1 Mark Thomas 2010-10-03 16:40:20 UTC
The second point is not correct. The Javadoc (which annoyingly is considered part of the specification even though it isn't in the specification document) lists the valid listener classes and AsyncListener is not one of them. The spec requires throwing an Exception in that case.
Comment 2 Mark Thomas 2010-10-03 16:54:52 UTC
Fixed with an alternative patch in trunk and will be included in 7.0.4 onwards.

I used the same approach as is used in ApplicationFilterConfig to access the InstanceManager.
Comment 3 david jencks 2010-10-03 17:00:02 UTC
Thanks for fixing the listener creation to use instance manager.  As to whether you can call addListener with an async listener, I don't think its very clear.

In Section 15.5:  AsyncListener is included in the list of interfaces for which 
<<
Annotations must be supported on the following container managed classes that implement the following interfaces and are declared in the web application deployment descriptor or using the annotations defined in Section 8.1, “Annotations and pluggability” on page 8-61 or added programmatically.
>>

Note that this indicates that AsyncListeners can be annotated with @WebListener and that the ServletContext.addListener methods can be called for an AsyncListener.
Furthermore the section makes clear that resource injection must be supported for AsyncListeners defined in web.xml, with a @WebListener annotation, or added programatically, and that AsyncListeners can be managed beans.

Section 4.4.3 agrees with the javadoc you cite.

I think the spec contradicts itself here.  I plan to ask for clarification from the e.g. by filing a tck challenge.