Return-Path: Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: (qmail 67297 invoked from network); 1 Nov 2008 22:10:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Nov 2008 22:10:54 -0000 Received: (qmail 16180 invoked by uid 500); 1 Nov 2008 22:10:54 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 16093 invoked by uid 500); 1 Nov 2008 22:10:53 -0000 Mailing-List: contact users-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: users@cocoon.apache.org List-Id: Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 16082 invoked by uid 99); 1 Nov 2008 22:10:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Nov 2008 15:10:53 -0700 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [130.231.240.1] (HELO oulu.fi) (130.231.240.1) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Nov 2008 22:09:34 +0000 Received: from cc.oulu.fi (sun3.oulu.fi [130.231.240.13]) by oulu.fi (8.13.7/8.13.7) with ESMTP id mA1MADkp000748 for ; Sun, 2 Nov 2008 00:10:13 +0200 (EET) Received: from [192.168.1.10] (dsl-176-86.oulu.fi [130.231.176.86]) by cc.oulu.fi (8.13.7/8.13.7) with ESMTP id mA1MACm6024741 for ; Sun, 2 Nov 2008 00:10:13 +0200 (EET) Message-ID: <490CD3C4.3050501@cc.oulu.fi> Date: Sun, 02 Nov 2008 00:10:12 +0200 From: Andre Juffer Reply-To: Andre.Juffer@oulu.fi Organization: The University of Oulu User-Agent: Icedove 1.5.0.14eol (X11/20080724) MIME-Version: 1.0 To: users@cocoon.apache.org Subject: Re: Can a Serializer acceess the Request Object ? References: <4905A430.6010407@imkenberg.de> <4907C030.6080909@apache.org> <49086BF1.5030000@oulu.fi> <490CC073.5060000@imkenberg.de> In-Reply-To: <490CC073.5060000@imkenberg.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi Thorsten, so you actually went for the second option! That's very interesting, I did not actually tried this all myself, but it was just a thought of how one could possibly do this. In any case, I will now try this also myself with cocoon 2.2 and see that I get this to work as well. Andre. Thorsten Mauch wrote: > Thanks a lot. The second solution works for me ( cocoon 2.1.11) . > contextualize ist called only once, but is easy to store the context > Object. > This save me a lot work :) > > Thorsten > > > > > Andre Juffer schrieb: >> Hi, >> >> with reference to a previous discussion about accessing the >> HttpSession object in a possibly cocoon unrelated Java class (see [1] >> below), would the following work: >> >> public interface MyInterface { >> void someMethod(..); >> } >> >> public interface UserRepository { >> User getUser(Long id); >> } >> >> public class MyInterfaceImp implements MyInterface, Contextualizable { >> >> private UserRepository userRepository; >> private HttpServletRequest ||request; >> >> public MyInterfaceImp(UserRepository userRepository) >> { >> this.userRepository = userRepository; >> this.request = null; >> } >> >> public void contextualize(Context context) throws ContextException >> { >> this.request = >> org.apache.cocoon.components.ContextHelper.getRequest(context); >> } >> >> public void someMethod(..) >> { >> HttpSession session = this.request.getSession(); >> Long id = session.getAttribute("userid"); >> User user = this.userRepository.getUser(id); >> .... >> } >> } >> >> The MyInterface is completely unrelated to Cocoon (version 2.2). >> Should the MyInterfaceImpl would be defined as a cocoon component in >> the sitemap? Or in some Spring configuration file? The someMethod >> would be called by means of aspects, pointcuts and join points (see >> [1]) (this already works) so I also would need to inform the Spring >> AOP setup about it and this would only be aware of the MyInterface. >> The Session would store an identifier to recognize an user. >> >> It was actually not clear to me whether the "void >> contextualize(Context context)" is called for every new request. If >> not, the MyInterfaceImpl possibly could be implemented as follows. >> >> public class MyInterfaceImp implements MyInterface, Contextualizable { >> >> private Context context; >> private UserRepository userRepository; >> >> public MyInterfaceImp(UserRepository userRepository) >> { >> this.context = null; >> this.userRepository = userRepository; >> } >> >> public void contextualize(Context context) throws ContextException >> { >> this.context = context; >> } >> >> public void someMethod(..) >> { >> HttpServletRequest request = >> org.apache.cocoon.components.ContextHelper.getRequest(this.context); >> HttpSession session = this.request.getSession(); >> Long id = session.getAttribute("userid"); >> User user = this.userRepository.getUser(id); >> .... >> } >> } >> >> Thanks, >> Andre >> >> [1] http://www.mail-archive.com/users@cocoon.apache.org/msg43673.html >> >> >> >> Jason Johnston wrote: >>> On 10/27/2008 05:21 AM, Thorsten Mauch wrote: >>>> Hi >>>> I wonder if a Serializer can access the request object ? My problem is >>>> that i want to pass a java Object to the Serializer that is created >>>> somewhere else. Is this possible ? >>> >>> >>> Your serializer can implement the Contextualizable interface, and get >>> access to the org.apache.cocoon.environment.Request object from the >>> injected Context object: >>> >>> public void contextualize(Context context) throws ContextException { >>> Request req = org.apache.cocoon.components >>> .ContextHelper.getRequest(context); >>> } >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org >>> For additional commands, e-mail: users-help@cocoon.apache.org >>> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org > For additional commands, e-mail: users-help@cocoon.apache.org > -- Andre H. Juffer | Email: Andre.Juffer@oulu.fi The Biocenter and | WWW: www.biochem.oulu.fi/Biocomputing/ the Dep. of Biochemistry | Fax: +358-8-553-1141 University of Oulu, Finland | Phone: +358-8-553 1161 Triacle Biocomputing | WWW: www.triacle-bc.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org For additional commands, e-mail: users-help@cocoon.apache.org