Return-Path: Delivered-To: apmail-incubator-abdera-dev-archive@locus.apache.org Received: (qmail 16946 invoked from network); 14 May 2008 14:53:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 May 2008 14:53:07 -0000 Received: (qmail 87438 invoked by uid 500); 14 May 2008 14:53:09 -0000 Delivered-To: apmail-incubator-abdera-dev-archive@incubator.apache.org Received: (qmail 87431 invoked by uid 500); 14 May 2008 14:53:09 -0000 Mailing-List: contact abdera-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-dev@incubator.apache.org Delivered-To: mailing list abdera-dev@incubator.apache.org Received: (qmail 87420 invoked by uid 99); 14 May 2008 14:53:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 May 2008 07:53:08 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jasnell@gmail.com designates 66.249.82.227 as permitted sender) Received: from [66.249.82.227] (HELO wx-out-0506.google.com) (66.249.82.227) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 May 2008 14:52:22 +0000 Received: by wx-out-0506.google.com with SMTP id s13so2751097wxc.21 for ; Wed, 14 May 2008 07:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; bh=u1VZi4ZLqI1HZVBMOP4Tg75uAQNjbK3m3M8Mf0Cg8MA=; b=LZ+lqCOEYqd3gL9wyQAULTRZZl5Z3rnDtchSaFx+KdtI2AEWOa5VtNfxhzUDwLrnIF9NWI7EWWGFjKJKSs709xd7nMynrGXpN/9OwkNcY++fKI9YvPTkXTN03bcamcGUirBMw34Qa5HIzZpqAqBhOpYdan0ACHVaSv/YCUs+/p0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:x-enigmail-version:content-type:content-transfer-encoding; b=K3jFz9r6dJjvsOFmz9ez1w1yQ9TUuuAznW2Ucs1EFzfnP2H7aM2GCzf2CkGOK8l2PZ75vA2GjY3VmDt3tg9y86twxTX3J6c2H80T+VRslWswt8kRr1DFOvHDKBpP4VMP7rV32dtoMGULsjDJIamxv9QROktlz3Fr0a/m7oKzbEw= Received: by 10.100.213.4 with SMTP id l4mr1347196ang.53.1210776741739; Wed, 14 May 2008 07:52:21 -0700 (PDT) Received: from ?192.168.2.2? ( [98.224.93.96]) by mx.google.com with ESMTPS id 7sm1286001hsx.1.2008.05.14.07.52.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 14 May 2008 07:52:20 -0700 (PDT) Message-ID: <482AFCA2.7080102@gmail.com> Date: Wed, 14 May 2008 07:52:18 -0700 From: James M Snell User-Agent: Thunderbird 2.0.0.14 (X11/20080505) MIME-Version: 1.0 To: abdera-dev@incubator.apache.org Subject: Re: Passing an Object from the servlet through to the provider? References: <482A5EE6.4000808@wso2.com> <482A7BCF.9080108@gmail.com> <482AF3CD.8010907@wso2.com> In-Reply-To: <482AF3CD.8010907@wso2.com> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Glen Daniels wrote: > Hi James! > > James M Snell wrote: >> RequestContext.setAttribute(Scope scope, String name, Object value) >> ... where Scope == Scope.REQUEST or Scope.SESSION >> >> Does that work for what you need? > > Nope, because that implies you have access to the RequestContext, which > I don't. Even if I subclass AbderaServlet, there's no hook in service() > that lets me get at the ServletRequestContext in between creation and > passing it to the Provider/TargetResolver. > You can create a Filter. The filters are invoked immediately before the Provider. I've used them to set properties on the RequestContext prior to passing it off to the Provider for handling. > To be clear, here's my situation: > > class Servlet1 { > init() { > Object thing = createObject(); // Here's my thing > servletContext.setAttribute("thing", thing); // Store it somewhere > } > } > > class MyServlet extends AbderaServlet { > service(request, response) { > // I can't get at the ServletContext from within Abdera, so... > Object thing = servletContext.getAttribute("thing"); > // ...put it somewhere I *can* get to > request.setAttribute("thing", thing); > super.service(request, response); > } > } > > If AbderaServlet made the ServletContext available in the same way it > makes the HttpServletRequest available, I wouldn't need the subclassed > servlet or the per-request overhead. True. Ok, I'll see what I can do... unless, of course, you want to submit a patch :-) - James > > --Glen > >> Glen Daniels wrote: >>> Hey Abderites: >>> >>> So here's my situation. I've got an Abdera server (i.e. >>> AbderaServlet in Tomcat) running that needs to share some information >>> with another servlet. In particular, the non-AbderaServlet (let's >>> call it Servlet1) needs to create an Object and then in an ideal >>> world pass that through to the AbderaServlet in such a way that the >>> Provider instance that gets created has access to it. Make sense? >>> >>> The best solution for me would be to put something into the >>> ServletContext, and then somehow get access to that later - but I >>> can't seem to do that currently. >>> >>> Since the initialization step doesn't really need to be done until >>> the first actual request, and I've already got a solid connection >>> between my Provider and my TargetResolver, I figured one way would be >>> something like (pseudocode): >>> >>> TargetResolver.resolve(Request request) { >>> ServletRequestContext context = (ServletRequestContext)request; >>> if (thing == null) { >>> thing = context.getServletContext().getAttribute("thing"); >>> } >>> } >>> >>> A patch that would just carry the ServletContext in addition to the >>> HttpServletRequest in each ServletRequestContext would be very easy >>> to do in Abdera, and would get me what I need. Am happy to >>> contribute same. >>> >>> Is there a better way to do this? I noticed the ManagedProvider >>> stuff but it looks like you can only pass Strings in there, and only >>> in very specific ways. Perhaps some kind of more general >>> initialization context that I'm missing? The above patch would solve >>> my problem later but not in v0.4.0. >>> >>> The solution I've come up with for now is to subclass the >>> AbderaServlet, and add the ServletContext to every HttpRequest as an >>> attribute - that lets me do basically the same trick, but it seems... >>> less than optimal. >>> >>> Thoughts/comments? >>> >>> Thanks, >>> --Glen >>> >> >