Return-Path: Delivered-To: apmail-myfaces-dev-archive@www.apache.org Received: (qmail 89695 invoked from network); 2 Dec 2009 06:29:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Dec 2009 06:29:53 -0000 Received: (qmail 96055 invoked by uid 500); 2 Dec 2009 06:29:53 -0000 Delivered-To: apmail-myfaces-dev-archive@myfaces.apache.org Received: (qmail 95874 invoked by uid 500); 2 Dec 2009 06:29:51 -0000 Mailing-List: contact dev-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list dev@myfaces.apache.org Received: (qmail 95859 invoked by uid 99); 2 Dec 2009 06:29:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Dec 2009 06:29:51 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of darkarena@gmail.com designates 209.85.217.209 as permitted sender) Received: from [209.85.217.209] (HELO mail-gx0-f209.google.com) (209.85.217.209) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Dec 2009 06:29:48 +0000 Received: by gxk1 with SMTP id 1so3339033gxk.16 for ; Tue, 01 Dec 2009 22:29:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:x-mailer:subject :mime-version:date:references; bh=nhK8Ls3U0QFHCMiTBSR6fr+reiOGt9Lu7F9dppNrwb8=; b=ri7xsgGX6u5OA9GVwJcL6i1l+QKLqvDUqnl339zAIkXE0QRDom6PKvtoDh3NDM+3Eh kcTGkYyXwRgkwf0B8SJkLd341+bzVupwye40OGO0JUbbkmkMyrPYclsxFycBtDD5o8Bn HQU5P7Hbk/PcTZ4svFkUIvvGmDkq3hiSGfm3A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:subject:mime-version:date :references; b=rORQu7cBAKxqTGJCRr9tr/5f3ymHaSPpcjuiOiCRGzMk/p7VClf+UFI/p1N2k37hYk r34PnqjX+79IyhF84cCKh2Zb11GBjG2XwPS3r4+YGc217SBC6VPaSLfJ9ecd1mDsAlcz f7cg7rEmG4H3AyLpxb9WZbRvWp3CY9pD4gMdU= Received: by 10.91.164.30 with SMTP id r30mr9525861ago.95.1259735367644; Tue, 01 Dec 2009 22:29:27 -0800 (PST) Received: from ?192.168.1.122? (c-67-176-98-65.hsd1.co.comcast.net [67.176.98.65]) by mx.google.com with ESMTPS id 5sm433487yxd.35.2009.12.01.22.29.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 01 Dec 2009 22:29:26 -0800 (PST) Message-Id: <4EF7C5A4-DFFA-44E4-BB71-B631A7165787@gmail.com> From: Scott O'Bryan To: MyFaces Development In-Reply-To: <4B15C100.6000507@gmail.com> Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Mailer: iPhone Mail (7D11) Subject: Re: [MyFaces 2.0] how to handle _SystemEventServletRequest and _SystemEventServletResponse classes (attn:Werner) Mime-Version: 1.0 (iPhone Mail 7D11) Date: Tue, 1 Dec 2009 23:29:09 -0700 References: <4B158F43.1020909@nc.rr.com> <4B15C100.6000507@gmail.com> I don't know why you couldn't just pass the proxy, and just throw IllegalOperationExceptions for unrecognized methods. But this one may be a bit cleaner. Don't know. Sent from my iPhone On Dec 1, 2009, at 6:21 PM, Bernhard Huemer wrote: > Hello, > > regarding the 1st solution: > According to the JavaDocs the ServletRequestWrapper throws an > IllegalArgumentException if you pass "null" as delegate, so this > won't work (I'll come back to that later though). However, given > that you're worried about NullPointerExceptions in case someone > calls methods that have been introduced in the Servlet 3.0 version > release, I assume that MyFaces isn't really concerned about those > methods anyway. Otherwise you'd probably override those methods? If > I'm mistaken, please correct me as some suggestions later on rely on > this assumption. > > regarding the 2nd solution: > Just ignoring the @Override annotation won't work as the respective > interfaces introduce dependencies to artifacts that are only > available in a Servlet 3.0 environment (for example, there's the > startAsync() method that returns an AsyncContext). If a class loader > were to load your request / response dummy class, he would now also > have to load the class AsyncContext as it's a dependency of your > class itself, which apparently the class loader cannot do in a > Servlet 2.5 environment. > > Given that I'd say you'll have to create two different dummy > implementations, one that implements the Servlet 2.5 ServletRequest > interface and one that implements the Servlet 3.0 ServletRequest > (i.e. the only thing that changes is the set of methods you have to > implement). However, now another problem arises as you can't just > use two different versions of the same API in a single build, i.e. > there's no way to tell the compiler that one class just implements > the methods in the Servlet 2.5 version whereas another class has to > implement the methods of the Servlet 3.0 version. Both versions have > to be compilable using the same Servlet API version and as the > Servlet 2.5 API is just a subset of the Servlet 3.0 API, both > versions have to be compilable using the Servlet 3.0 version. > > The big issue now is that we've got a contradiction now. If we want > to support a Servlet 3.0 environment, we'll have to use this version > in our build (again, Servlet 3.0 is if I'm not mistaken a superset > of Servlet 2.5, that's the reason for that). However, the 2.5 > version of the dummy class cannot compile if one uses the 3.0 > version for the actual build. Maybe that sounds a little bit strange > up until now, but hopefully now it will get clearer: A 2.5 > compatible implementation of the ServletRequest interface must not > implement the method "startAsync" as it introduces an unsatisfiable > dependency, but a 3.0 compatible build environment requires any > implementation to implement the method "startAsync" (amongs others) > as it is a part of the interface after all. > > Hence I'm afraid but this solution just won't work either. Of > course, the third solution would probably work, but why bother about > the performance implications if there's another solution? :-) > > I think the preferable solution is actually the first one. It's easy > to implement as we don't have to deal with the difference between > the Servlet 2.5 API and Servlet 3.0 API, but as I've already > mentioned there is the IllegalArgumentException issue that you just > can't ignore either. We just want to get rid of the null value > somehow, so why not use a dummy proxy instead? Note that there are > no performance implications if you override the wrapped methods > anyway, i.e. in fact, the proxy won't be called even once. It's sole > purpose is to replace the "null", that's it. It could look like the > following: > > /// > > public class DummyServletRequest extends ServletRequestWrapper { > > public DummyServletRequest() { > super(Proxy.newProxyInstance( > DummyServletRequest.class.getClassLoader(), > new Class[] { ServletRequest.class }, > new InvocationHandler() { > public Object invoke(Object proxy, Method m, Object[] args) { > throw new UnsupportedOperationException(...); > } > } > ); > } > > // --------- "Implement" the interface ServletRequest now! > > public Object getAttribute(String name) { > // ... > } > > // ... > > } > > \\\ > > Hope that helps. :-) > > regards, > Bernhard Huemer > > On 12/01/2009 09:48PM GMT, Michael Concini wrote: >> I need some help with the best way to handle updating the dummy >> request/response objects that we use for system event listeners >> kicked off when there isn't a request context. Currently, we're >> implementing ServletRequest and ServletResponse directly. This is >> broken when using a servlet 3.0 runtime though since we're not >> implementing the new methods added by the servlet 3.0 spec. >> I tried already updating the classes to extend the request/response >> wrapper classes, but that turned out to be problematic since the >> constructor requires a request/response object to be passed. Since >> we don't have access to that as we're outside of a request I hit an >> NPE try to use FacesContext that wasn't there. >> I've come up with a couple of potential solutions on this and would >> like some input as to the best way to go. >> 1) We could also extend the wrapper classes, but add a no-arg >> constructor to the dummy classes that would just call super(null). >> This would be fine in most cases, but if an application tried to >> call any of the new ServletContext methods from Servlet 3.0 we'd >> get an NPE instead of a runtime exception (not ideal) >> 2) We can simply add the new methods from the Servlet 3.0 API to >> our dummy classes. I think as long as we don't include the >> @Override annotation it should build and run in either a 2.5 or 3.0 >> environment. >> 3) We could implement a dynamic proxy to handle the calls. Would >> be a little more complex to implement, but might be the most >> elegant solution. Not fully sure if there are performance >> implications here though. >> Personally, I'd lean towards (2), I'd like to here from Werner as >> well since he was the one that initially implemented this. Any >> additional feedback from others in the community is of course >> welcome. >> Thanks, >> Mike >