Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 38258 invoked from network); 16 Sep 2010 20:27:02 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Sep 2010 20:27:02 -0000 Received: (qmail 29984 invoked by uid 500); 16 Sep 2010 20:27:01 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 29914 invoked by uid 500); 16 Sep 2010 20:27:01 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 29905 invoked by uid 99); 16 Sep 2010 20:27:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Sep 2010 20:27:01 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [98.136.44.57] (HELO smtp102.prem.mail.sp1.yahoo.com) (98.136.44.57) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 16 Sep 2010 20:26:53 +0000 Received: (qmail 92706 invoked from network); 16 Sep 2010 20:26:31 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=xyhugy8tSeV7o3bBJ+3AWeCymrBco8TAfLUrAxpj/k27Me+NQBxlNFew80CYIi1CgZEiKRK7CRWYbFE+G4c32IYZ5YWMgSjsxPetm4t86Ux/gorWDjmkDZBzCm8W+lCKtwutUEs3mIZ5tdEqcuPcr2AIsdn5lKdJxc6+yNVRCcY= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1284668791; bh=TSNQkgLpy+1tLbaKOe/kfsiuwd+SGHzyT8FVIyi+drA=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=FdwvK2tXlv+wthmxO8DLGh4huNEPF7AhUVP/N+Iryf/7C+lWCite0oQ0JaRwLWpQmmKnYJyG7GduhHXY0jbN22f1GJKqZVgnJ0ALECa2WtxBZAXUMB+exMf696vy/JHsLMdLop6sbmoFoIM7i9AdMQfHrpGKHbdKDMWqFzQ2Tf8= Received: from [10.0.1.4] (david_jencks@76.76.148.215 with plain) by smtp102.prem.mail.sp1.yahoo.com with SMTP; 16 Sep 2010 13:26:31 -0700 PDT X-Yahoo-SMTP: .9oIUzyswBANsYgUm_5uPui0skTnzGJXJQ-- X-YMail-OSG: fxyEQ5EVM1lbLDnyWl5m2PlUEjD4yvnz6McIENW5ruQdPXi pt9XtmfrIwYQQ5ORH1MhBH6CYMtMGSR_s8tgivkVrElGSJ4kZC8AJnxzk0MF 5p66ogwn_dB.CXFM_bMUNR7SKtT0c9C7.lCv2bSAQ9Te6Hk81tpdrPEIkJEF 8fmT_lyHcqgVUwI54Mo3js43NdnoR1H3R3DdeRLvJSpc9b0idIBdgTyGCbkk 5qurxo3xWPCHwYBVkBoLBGIaeMLhpW4NLIaLYUi6biG1.fWgjvutLNdxaE1Q IOXRPYdVnPNG9K3tbkgqPkf43bCsVDggxwn8uweLdyT9qDDuaZC5DMCGH34u MoIaCpCD2QOU6jLwQ X-Yahoo-Newman-Property: ymail-3 Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Apple Message framework v1081) Subject: Re: AsyncListeners and resource injection From: David Jencks In-Reply-To: <015C21FF-AC6C-4EF0-90C3-29F76E12E549@yahoo.com> Date: Thu, 16 Sep 2010 13:26:29 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <68941D55-BA32-46F7-B7B6-B1508CDF25C3@yahoo.com> References: <015C21FF-AC6C-4EF0-90C3-29F76E12E549@yahoo.com> To: "Tomcat Developers List" X-Mailer: Apple Mail (2.1081) X-Virus-Checked: Checked by ClamAV on apache.org On Sep 15, 2010, at 10:51 PM, David Jencks wrote: >=20 > On Sep 15, 2010, at 9:58 PM, David Jencks wrote: >=20 >> I think this is how AsyncContextImpl creates async listeners (lines = 228ff) >>=20 >> @Override >> public T createListener(Class clazz) >> throws ServletException { >> T listener =3D null; >> try { >> listener =3D clazz.newInstance(); >> } catch (InstantiationException e) { >> ServletException se =3D new ServletException(e); >> throw se; >> } catch (IllegalAccessException e) { >> ServletException se =3D new ServletException(e); >> throw se; >> } >> return listener; >> } >>=20 >>=20 >>=20 >> but the 3.0 spec section 15.5 page 179 says >>=20 >> 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, =93Annotations and pluggability=94 on page 8-61 or added = programmatically. >>=20 >> and includes AsyncListener in the table following. =20 >>=20 >> So shouldn't this be using the instance manager to create the = instance so the resource injection machinery can do its stuff? >>=20 >>=20 >> Secondly, if you do try to register an AsyncListener with the = ServletContext so it can be scanned for annotations, aside from not = actually scanning it, it quickly gets to this code (ApplicationContext = lines 1262 ff) >>=20 >> @Override >> public void addListener(T t) { >> if (!context.getState().equals(LifecycleState.STARTING_PREP)) { >> throw new IllegalStateException( >> sm.getString("applicationContext.addListener.ise", >> getContextPath())); >> } >>=20 >> // TODO SERVLET3 >> // throw UnsupportedOperationException - if this context was = passed to the >> // {@link = ServletContextListener#contextInitialized(javax.servlet.ServletContextEven= t)} >> // method of a {@link ServletContextListener} that was not = declared >> // in web.xml, a web-fragment or annotated with {@link = WebListener}. >>=20 >> boolean match =3D false; >> if (t instanceof ServletContextAttributeListener || >> t instanceof ServletRequestListener || >> t instanceof ServletRequestAttributeListener || >> t instanceof HttpSessionAttributeListener) { >> context.addApplicationEventListener(t); >> match =3D true; >> } >>=20 >> if (t instanceof HttpSessionListener >> || (t instanceof ServletContextListener && >> newServletContextListenerAllowed)) { >> context.addApplicationLifecycleListener(t); >> match =3D true; >> } >>=20 >> if (match) return; >>=20 >> throw new IllegalArgumentException(sm.getString( >> "applicationContext.addListener.iae.wrongType", >> t.getClass().getName())); >>=20 >> } >>=20 >>=20 >> which doesn't accept AsyncListeners. (of course it shouldn't do = anything with then). >>=20 >> Thoughts? >>=20 >> thanks >> david jencks >>=20 >=20 > BTW I opened bug 49937 with fixes that work for me for these = problems. >=20 > david jencks >=20 The situation seems to be more complicated than I thought at first. As noted above, section 15.5 clearly indicates annotation based resource = injection is supported for all servlet related listeners including = AsyncListener, and that these can be specified in the xml deployment = descriptor, via annotation, or by adding programatically. However....=20 4.4.3 indicates that an AsyncListener cannot be added programatically 4.4.3.5 indicates that resource injection is not supported for listeners = added programatically unless the listener is a managed bean. I think = this directly contradicts 15.5. 8.1.4 indicates that an AsyncListener cannot be annotated with = @WebListener 11.3.2 says Listener classes are declared in the Web application deployment = descriptor using the listener element. They are listed by class name in = the order in which they are to be invoked. Unlike other listeners, = listeners of type AsyncListener may only be registered (with a = ServletRequest) programmatically. I can't figure out what this is supposed to mean. It might mean that = you aren't allowed to list an AsyncListener in your web.xml, or it might = mean that you can, but to use it you have to explicitly add it to an = AsyncContext. Despite the contradictions in the spec, it seems pretty clear that an = asyncListener can be a managed bean and thus be subject to resource = injection. It might also be possible for it to be listed in web.xml, = have a @WebListener annotation, and be "added" programatically so it can = be scanned for normal ee resource injection annotations (depending on = how much weight you put on 15.5 compared with the other sections). So, = I think that the AsyncContext.createListener method should use the = instance manager in any case. I think it makes sense to relax the = restrictions on @WebListener and programatically adding AsyncListeners = as well (i.e. giving priority to 15.5 rather than all the other = sections) since it doesn't break anything and is more powerful. thanks david jencks >=20 >>=20 >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org >> For additional commands, e-mail: dev-help@tomcat.apache.org >>=20 >=20 >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org > For additional commands, e-mail: dev-help@tomcat.apache.org >=20 --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org