Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 94037 invoked from network); 19 Aug 2008 06:07:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Aug 2008 06:07:51 -0000 Received: (qmail 85556 invoked by uid 500); 19 Aug 2008 06:07:34 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 85532 invoked by uid 500); 19 Aug 2008 06:07:34 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 85521 invoked by uid 99); 19 Aug 2008 06:07:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Aug 2008 23:07:34 -0700 X-ASF-Spam-Status: No, hits=3.8 required=10.0 tests=HTML_MESSAGE,MIME_QP_LONG_LINE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [216.82.247.115] (HELO mail86.messagelabs.com) (216.82.247.115) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Aug 2008 06:06:37 +0000 X-VirusChecked: Checked X-Env-Sender: AdamJenkins@nti.com.au X-Msg-Ref: server-3.tower-86.messagelabs.com!1219125901!815713!1 X-StarScan-Version: 5.5.12.14.2; banners=nti.com.au,-,- X-Originating-IP: [202.83.74.134] Received: (qmail 9986 invoked from network); 19 Aug 2008 06:05:03 -0000 Received: from unknown (HELO BNE-EXCH3.nti.internal) (202.83.74.134) by server-3.tower-86.messagelabs.com with RC4-SHA encrypted SMTP; 19 Aug 2008 06:05:03 -0000 Received: from BNE-EXCH2.nti.internal (192.168.200.66) by BNE-EXCH3.nti.internal (192.168.200.89) with Microsoft SMTP Server (TLS) id 8.1.263.0; Tue, 19 Aug 2008 16:05:04 +1000 Received: from bne-extemp1.nti.internal (192.168.200.67) by BNE-EXCH2.nti.internal (192.168.200.66) with Microsoft SMTP Server id 8.1.263.0; Tue, 19 Aug 2008 16:05:00 +1000 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C901C1.83BEC5BA" Subject: NullPointerException 5.5.17 Request.setAttribute(Request.java:1376) Date: Tue, 19 Aug 2008 16:05:00 +1000 Message-ID: <82A68136DC5559418D5FDB1EECBC7F9E01CFA10A@bne-extemp1.nti.internal> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: NullPointerException 5.5.17 Request.setAttribute(Request.java:1376) Thread-Index: AckBwYO+T/X8UeLISeyaOWGHTtf/tw== From: Adam Jenkins To: X-Virus-Checked: Checked by ClamAV on apache.org ------_=_NextPart_001_01C901C1.83BEC5BA Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi=20All, I'be=20been=20tearing=20my=20hair=20out=20for=20a=20couple=20of=20weeks=20= over=20this=20one=20and=20would=20appreciate=20any=20assistance=20anyone=20= could=20give.=20=20It's=20a=20bit=20of=20a=20unique=20scenario,=20so=20it'= ll=20take=20me=20a=20little=20while=20to=20explain: We=20have=20a=20legacy=20struts=20app,=20forwarding=20to=20a=20jsf=20app=20= (details=20of=20how=20below)=20running=20on=20tomcat=205.5.17.=20=2099.9%=20= of=20the=20time=20everythign=20works=20great,=20but=20every=20now=20and=20= then=20(which=20in=20users=20speak=20translates=20to=20'I=20keep=20on=20ge= tting',=20hence=20we=20can't=20ignore=20it)=20a=20NullPointerException=20g= ets=20thrown=20from=20org.apache.catalina.connector.Request.setAttribute. The=20flow=20is: Third=20party=20application=20---<>--->=20JSFBridgeFilter= =20(will=20explain=20later)=20----->=20Struts=20application=20---->=20JSFB= ridge--->JSF=20Application--->Response=20back=20to=20third=20party=20app. The=20struts=20application=20contains=20proprietary=20logic=20to=20interfa= ce=20with=20the=20third=20party=20app,=20so=20we=20can't=20get=20rid=20of=20= it.=20Business=20wants=20all=20development=20internally=20to=20be=20done=20= in=20JSF,=20so=20we=20can't=20get=20rid=20of=20that. The=20JSFBridgeFilter=20instantiates=20the=20JSF=20Context=20for=20later=20= use,=20and=20wraps=20the=20request=20that=20is=20used=20to=20instantiate=20= it=20in=20a=20request=20wrapper=20that=20translates=20".do"=20context=20pa= ths=20to=20".jsf"=20context=20paths=20(otherwise=20all=20the=20forms=20sub= mit=20back=20to=20".do"=20after=20coming=20from=20the=20struts=20framework= .=20=20It=20looks=20like=20this: public=20void=20doFilter(ServletRequest=20strutsRequest,=20ServletResponse= =20response,=20FilterChain=20chain)=20throws=20IOException,=20ServletExcep= tion=20{ HttpServletRequest=20jsfRequest=20=3D=20new=20StrutsToJsfRequestWrapper((H= ttpServletRequest)strutsRequest); JSFBridge.getFacesContext(viewId,=20(HttpServletRequest)jsfRequest,=20(Htt= pServletResponse)response); chain.doFilter(strutsRequest,=20response);=20 } ...and=20the=20StrutsToJsfRequestWrapper=20contains=20only=20one=20overrid= e=20method=20(it=20extends=20HttpServletRequestWrapper): @Override public=20String=20getServletPath()=20{ =09String=20oldPath=20=3D=20super.getServletPath(); =09String=20newPath=20=3D=20null; =09int=20index=20=3D=20oldPath.lastIndexOf(".do"); =09if=20(index=20>=3D=200)=20{ =09=09newPath=20=3D=20oldPath.substring(0,=20index=20+=201)=20+=20".jsf"; =09}=20else=20{ =09=09newPath=20=3D=20oldPath; =09} =09return=20newPath; } =20 Now,=20you'll=20notice=20in=20the=20filter=20that=20the=20request=20wrappe= r=20is=20used=20to=20instantiate=20the=20faces=20context,=20and=20the=20or= iginal=20request=20passed=20onto=20the=20struts=20application.=20=20The=20= 'getFacesContext'=20method=20implements=20some=20code=20from=20the=20apach= e=20myfaces=20wiki=20that=20shows=20a=20way=20to=20call=20into=20the=20JSF= =20framework=20from=20non=20jsf=20artifacts: =20 It=20looks=20like=20this: =20 public=20class=20JSFBridge=20{ =20 =09private=20abstract=20static=20class=20InnerFacesContext=20extends=20Fac= esContext=20{ =09=09protected=20static=20void=20setFacesContextAsCurrentInstance(final=20= FacesContext=20facesContext)=20{ =09=09=09FacesContext.setCurrentInstance(facesContext); =09=09} =09} =20 =09public=20static=20FacesContext=20getFacesContext(final=20String=20viewI= d,=20final=20ServletRequest=20request,=20final=20ServletResponse=20respons= e)=20{=20 =09=09FacesContext=20facesContext=20=3D=20FacesContext.getCurrentInstance(= ); =09=09if=20(facesContext=20!=3D=20null)=20{=20 =09=09=09return=20facesContext; =09=09}=20 =09=09return=20getNewFacesContext(viewId,=20request,=20response); =09} =20 =09public=20static=20FacesContext=20getNewFacesContext(final=20String=20vi= ewId,=20final=20ServletRequest=20request,=20final=20ServletResponse=20resp= onse)=20{ =09=09FacesContext=20facesContext; =09=09FacesContextFactory=20contextFactory=20=3D=20(FacesContextFactory)=20= FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); =09=09LifecycleFactory=20lifecycleFactory=20=3D=20(LifecycleFactory)=20Fac= toryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); =09=09Lifecycle=20lifecycle=20=3D=20lifecycleFactory.getLifecycle(Lifecycl= eFactory.DEFAULT_LIFECYCLE); =09=09facesContext=20=3D=20contextFactory.getFacesContext(((HttpServletReq= uest)request).getSession().getServletContext(),request,=20response,=20life= cycle); =09=09InnerFacesContext.setFacesContextAsCurrentInstance(facesContext); =09=09UIViewRoot=20view=20=3D=20facesContext.getApplication().getViewHandl= er().createView(facesContext,=20viewId); =09=09facesContext.setViewRoot(view);=20 =09=09return=20facesContext; =09}=20 } =20 And=20the=20final=20piece=20of=20the=20puzzle=20is=20a=20struts=20action=20= that=20actually=20loads=20the=20context=20and=20forwards=20to=20the=20appr= opriate=20JSF=20method...which=20looks=20like=20this: =20 public=20class=20ForwardToJSFAction=20extends=20Action=20{ =09 =09public=20ActionForward=20execute(ActionMapping=20mapping,=20ActionForm=20= form,=20HttpServletRequest=20request,=20HttpServletResponse=20response)=20= throws=20Exception=20{=20 =09=09JSFMapping=20viewMapping=20=3D=20(JSFMapping)=20mapping; =09=09FacesContext=20ctx=20=3D=20JSFBridge.getFacesContext(viewMapping.get= ViewId(),=20request,=20response);=20 =09=09MethodBinding=20mb=20=3D=20lookupMethodBinding(viewMapping,=20ctx);=20= =09=09navigateToMethodBinding(viewMapping,=20ctx,=20mb); =09=09return=20null; =09} =20 =09private=20MethodBinding=20lookupMethodBinding(JSFMapping=20viewMapping,= =20FacesContext=20ctx)=20{ =09=09return=20ctx.getApplication().createMethodBinding("#{"=20+=20viewMap= ping.getJsfAction()=20+=20"}",=20new=20Class[]=20{}); =09} =20 =09private=20void=20navigateToMethodBinding(JSFMapping=20viewMapping,=20Fa= cesContext=20ctx,=20MethodBinding=20mb)=20{ =09=09Object=20obj=20=3D=20mb.invoke(ctx,=20new=20Object[]=20{}); =09=09NavigationHandler=20navHandler=20=3D=20ctx.getApplication().getNavig= ationHandler(); =09=09navHandler.handleNavigation(ctx,=20"#{"=20+=20viewMapping.getJsfActi= on()=20+=20"}",=20(String)=20obj); =09} } =20 Now,=20as=20odd=20as=20all=20this=20looks,=20it=20actually=20works=20quite= =20well=20in=2099.9%=20of=20the=20cases.=20=20We=20get=20a=20request=20in=20= struts,=20which=20forwards=20quite=20nicely=20onto=20a=20JSF=20method=20an= d=20completes=20the=20business=20process=20in=20JSF.=20=20Every=20now=20an= d=20then=20though,=20we=20get=20the=20following=20error=20when=20we=20try=20= to=20invoke=20the=20method=20binding: Caused=20by:=20java.lang.NullPointerException =09at=20org.apache.catalina.connector.Request.setAttribute(Request.java:13= 76) =09at=20org.apache.catalina.connector.RequestFacade.setAttribute(RequestFa= cade.java:500) =09at=20javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWra= pper.java:283) =09at=20org.apache.myfaces.context.servlet.RequestMap.setAttribute(Request= Map.java:46) =09at=20org.apache.myfaces.context.servlet.AbstractAttributeMap.put(Abstra= ctAttributeMap.java:104) =09at=20org.apache.myfaces.el.VariableResolverImpl.resolveVariable(Variabl= eResolverImpl.java:301) =09at=20org.apache.myfaces.config.LastVariableResolverInChain.resolveVaria= ble(LastVariableResolverInChain.java:42) =09at=20org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveV= ariable(ValueBindingImpl.java:574) =09at=20org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124) =09at=20org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(Va= lueBindingImpl.java:455) =09at=20org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(M= ethodBindingImpl.java:180) =09at=20org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.j= ava:114) Diving=20into=20Request.java(Line=201376),=20shows=20that=20it's=20happeni= ng=20on=20this=20line: Object=20listeners[]=20=3D=20context.getApplicationEventListeners(); So=20I'm=20guessing=20that=20'context'=20is=20null=20for=20some=20reason.=20= =20Since=20it=20is=20so=20rare,=20it's=20almost=20impossible=20to=20reprod= uce=20in=20a=20manner=20consistent=20enough=20to=20actually=20diagnose=20a= nd=20debug=20it. Can=20anyone=20see,=20from=20the=20above,=20anything=20that=20could=20shed= =20some=20light=20on=20this? Cheers Adam Number=201=20in=20Truck=20Insurance ______________________________________________________________________ CAUTION=20-=20This=20message=20is=20intended=20for=20the=20addressee=20nam= ed=20above. It=20may=20contain=20privileged=20or=20confidential=20information.=20If=20= you=20are=20 not=20the=20intended=20recipient=20of=20this=20message=20you=20must=20not=20= use,=20 copy,=20distribute=20or=20disclose=20it=20to=20anyone=20other=20than=20the= =20addressee. If=20you=20have=20received=20this=20email=20in=20error=20please=20return=20= the=20message=20to=20the=20sender=20by=20replying=20to=20it=20and=20then=20= delete=20the=20message=20from=20your=20computer. Internet=20e-mails=20are=20not=20necessarily=20secure.=20 National=20Transport=20Insurance=20does=20not=20accept=20responsibility=20= for=20changes=20made=20to=20this=20message=20after=20it=20was=20sent. ______________________________________________________________________ ------_=_NextPart_001_01C901C1.83BEC5BA--