From dev-return-103396-apmail-cocoon-dev-archive=cocoon.apache.org@cocoon.apache.org Tue Mar 13 13:46:03 2012 Return-Path: X-Original-To: apmail-cocoon-dev-archive@www.apache.org Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5DE849B35 for ; Tue, 13 Mar 2012 13:46:03 +0000 (UTC) Received: (qmail 79084 invoked by uid 500); 13 Mar 2012 13:46:03 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 79026 invoked by uid 500); 13 Mar 2012 13:46:03 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 79019 invoked by uid 99); 13 Mar 2012 13:46:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Mar 2012 13:46:03 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of scherler@gmail.com designates 209.85.214.51 as permitted sender) Received: from [209.85.214.51] (HELO mail-bk0-f51.google.com) (209.85.214.51) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Mar 2012 13:45:56 +0000 Received: by bkwj10 with SMTP id j10so529024bkw.24 for ; Tue, 13 Mar 2012 06:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=L4oRbR3wALJrRe1ipmNP3mjLEUSV7MR1CCHdNOFlYHk=; b=vceLlLtL7r53mgWJMy/eiRX7UR2YlL4YQuOCfnQxu54HNVzNy6JrgoAePqEW7660k8 XO5Osretlgr+oeDgazLyaYk96P1fwUb+z98ZMRlfRkXuoFVpDACIgCZWQC834CuWOdhl Seat+41EL8TOwz+Dz0QwkIaYn8nbeF5+u1t6Z2KujLVbtW4EUB9VxzNxj6znr8zN4mrs Ax8MaeNWM+QJoJwi27w/GDFzjJY/vk0FOpGQZxFj8ix29cLWfTeXjgbqEtnkSf2GVBrX ZATgIvYIfY2CBXP8PeFI5KspJKAyAgrgv8W/odNB6miZ5YMmXpec0UEY1QX9z57Bzoo2 uBkQ== Received: by 10.204.141.10 with SMTP id k10mr6468678bku.51.1331646335333; Tue, 13 Mar 2012 06:45:35 -0700 (PDT) Received: from [10.0.0.17] (94.168.216.87.static.jazztel.es. [87.216.168.94]) by mx.google.com with ESMTPS id o7sm1488583bkw.16.2012.03.13.06.45.33 (version=SSLv3 cipher=OTHER); Tue, 13 Mar 2012 06:45:34 -0700 (PDT) Message-ID: <4F5F4F7E.8050408@gmail.com> Date: Tue, 13 Mar 2012 14:45:34 +0100 From: Thorsten Scherler User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: [c3] CallStack.getCurrentFrame() returns null - why? References: <4F5F3BEB.3000707@gmail.com> In-Reply-To: <4F5F3BEB.3000707@gmail.com> Content-Type: multipart/alternative; boundary="------------040806040603080908060508" X-Virus-Checked: Checked by ClamAV on apache.org This is a multi-part message in MIME format. --------------040806040603080908060508 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 03/13/2012 01:22 PM, Thorsten Scherler wrote: > Hi all, > > as I mentioned in another thread I am ATM extracting various code from > our main c3 block into separate ones. The extraction works fine for > i18n and some general pipes. However we use a activemq queue and when > I try to invoke a java pipeline from within a > javax.jms.MessageListener I get a NPE in invoking pipe.execute(). > > I use something like: > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > Pipeline emailPipe = > this.applicationContext.getBean("emailPipe", Pipeline.class); > emailPipe.setup(baos, parameters); > emailPipe.execute(); -> here we get NPE > > I debugged the whole thing and found out that we never enter in the > execute() method of the pipeline because before the > CallStackCollectorDataStore.set is called. > > public void set(String key, Object value) { > CallStack.getCurrentFrame().setAttribute(key, value); > } > > This provokes the following: > java.lang.NullPointerException > at > org.apache.cocoon.servlet.collector.CallStackCollectorDataStore.set(CallStackCollectorDataStore.java:28) > at > org.apache.cocoon.servlet.collector.ResponseHeaderCollector.setModifiedResponse(ResponseHeaderCollector.java:200) > at > org.apache.cocoon.servlet.collector.ResponseHeaderCollector.interceptInvoke(ResponseHeaderCollector.java:49) > > Now finally I found that CallStack.getCurrentFrame() is NULL, because > in CallStack > public static CallFrame getCurrentFrame() { > final Stack stack = (Stack) callStack.get(); > ... > the stack is null and then the method is returning null provoking this > very ugly NPE (which took me ages to track down). > > Now my question is how can it be that the stack is null and how can I > prevent it from happening? Further I would strongly vote to refactor > CallStack.getCurrentFrame().setAttribute to something like > CallFrame frame = CallStack.getCurrentFrame(); > if(null!=frame){ > frame.setAttribute(key, value); > }else{ > // should we throw here an exception or is there an alternative? > } > > Any ideas are welcome. Ok, getting closer to the underlying problem. I did ServletContext xXx = CallStackHelper.getCurrentServletContext(); and surprise surprise "xXx = null" ...now how can I attach the context to my jms listener again? salu2 -- Thorsten Scherler codeBusters S.L. - web based systems http://www.codebusters.es/ --------------040806040603080908060508 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 03/13/2012 01:22 PM, Thorsten Scherler wrote:
Hi all,

as I mentioned in another thread I am ATM extracting various code from our main c3 block into separate ones. The extraction works fine for i18n and some general pipes. However we use a activemq queue and when I try to invoke a java pipeline from within a javax.jms.MessageListener I get a NPE in invoking pipe.execute().

I use something like:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
Pipeline<SAXPipelineComponent> emailPipe = this.applicationContext.getBean("emailPipe", Pipeline.class);
emailPipe.setup(baos, parameters);
emailPipe.execute(); -> here we get NPE

I debugged the whole thing and found out that we never enter in the execute() method of the pipeline because before the CallStackCollectorDataStore.set is called.

public void set(String key, Object value) {
        CallStack.getCurrentFrame().setAttribute(key, value);
    }

This provokes the following:
java.lang.NullPointerException
    at org.apache.cocoon.servlet.collector.CallStackCollectorDataStore.set(CallStackCollectorDataStore.java:28)
    at org.apache.cocoon.servlet.collector.ResponseHeaderCollector.setModifiedResponse(ResponseHeaderCollector.java:200)
    at org.apache.cocoon.servlet.collector.ResponseHeaderCollector.interceptInvoke(ResponseHeaderCollector.java:49)

Now finally I found that CallStack.getCurrentFrame() is NULL,  because in CallStack
public static CallFrame getCurrentFrame() {
 final Stack stack = (Stack) callStack.get();
...
the stack is null and then the method is returning null provoking this very ugly NPE (which took me ages to track down).

Now my question is how can it be that the stack is null and how can I prevent it from happening? Further I would strongly vote to refactor CallStack.getCurrentFrame().setAttribute to something like
CallFrame frame = CallStack.getCurrentFrame();
if(null!=frame){
  frame.setAttribute(key, value);
}else{
  // should we throw here an exception or is there an alternative?
}

Any ideas are welcome.

Ok, getting closer to the underlying problem. I did
ServletContext xXx = CallStackHelper.getCurrentServletContext();
and surprise surprise "xXx = null"

...now how can I attach the context to my jms listener again?

salu2
-- 
Thorsten Scherler <scherler.at.gmail.com>
codeBusters S.L. - web based systems
<consulting, training and solutions>

http://www.codebusters.es/
--------------040806040603080908060508--