Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 95714 invoked from network); 19 Aug 2008 06:15:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Aug 2008 06:15:04 -0000 Received: (qmail 97669 invoked by uid 500); 19 Aug 2008 06:14:58 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 97628 invoked by uid 500); 19 Aug 2008 06:14:58 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 97617 invoked by uid 99); 19 Aug 2008 06:14:58 -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:14:57 -0700 X-ASF-Spam-Status: No, hits=-0.2 required=10.0 tests=HTML_MESSAGE,MIME_QP_LONG_LINE,RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [216.82.249.179] (HELO mail44.messagelabs.com) (216.82.249.179) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 Aug 2008 06:14:00 +0000 X-VirusChecked: Checked X-Env-Sender: AdamJenkins@nti.com.au X-Msg-Ref: server-13.tower-44.messagelabs.com!1219126465!20180071!1 X-StarScan-Version: 5.5.12.14.2; banners=nti.com.au,-,- X-Originating-IP: [202.83.74.134] Received: (qmail 8863 invoked from network); 19 Aug 2008 06:14:27 -0000 Received: from unknown (HELO BNE-EXCH3.nti.internal) (202.83.74.134) by server-13.tower-44.messagelabs.com with RC4-SHA encrypted SMTP; 19 Aug 2008 06:14:27 -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:14:28 +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:14:25 +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_01C901C2.D43CE13B" Subject: FW: NullPointerException 5.5.17 Request.setAttribute(Request.java:1376) Date: Tue, 19 Aug 2008 16:13:29 +1000 Message-ID: <82A68136DC5559418D5FDB1EECBC7F9E01CFA110@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/twAAS9OG References: <82A68136DC5559418D5FDB1EECBC7F9E01CFA10A@bne-extemp1.nti.internal> From: Adam Jenkins To: X-Virus-Checked: Checked by ClamAV on apache.org ------_=_NextPart_001_01C901C2.D43CE13B Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi,=20I've=20sent=20the=20following=20to=20the=20tomcat=20mailing=20lists=20= for=20advice,=20but=20since=20it=20also=20involves=20myfaces=20I=20thought= =20I'd=20send=20it=20here=20too.=20=20I=20hope=20someone,=20somewhere=20ha= s=20some=20idea=20as=20to=20what's=20going=20on. =20 Cheers Adam ________________________________ From:=20Adam=20Jenkins=20[mailto:AdamJenkins@nti.com.au] Sent:=20Tue=2019/08/2008=204:05=20PM To:=20users@tomcat.apache.org Subject:=20NullPointerException=205.5.17=20Request.setAttribute(Request.ja= va:1376) 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); } ...and=20the=20StrutsToJsfRequestWrapper=20contains=20only=20one=20overrid= e=20method=20(it=20extends=20HttpServletRequestWrapper): @Override public=20String=20getServletPath()=20{ =20=20=20=20=20=20=20=20String=20oldPath=20=3D=20super.getServletPath(); =20=20=20=20=20=20=20=20String=20newPath=20=3D=20null; =20=20=20=20=20=20=20=20int=20index=20=3D=20oldPath.lastIndexOf(".do"); =20=20=20=20=20=20=20=20if=20(index=20>=3D=200)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20newPath=20=3D=20oldPath.su= bstring(0,=20index=20+=201)=20+=20".jsf"; =20=20=20=20=20=20=20=20}=20else=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20newPath=20=3D=20oldPath; =20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20return=20newPath; } 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: It=20looks=20like=20this: public=20class=20JSFBridge=20{ =20=20=20=20=20=20=20=20private=20abstract=20static=20class=20InnerFacesCo= ntext=20extends=20FacesContext=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20protected=20static=20void=20= setFacesContextAsCurrentInstance(final=20FacesContext=20facesContext)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Fa= cesContext.setCurrentInstance(facesContext); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20public=20static=20FacesContext=20getFacesContext(f= inal=20String=20viewId,=20final=20ServletRequest=20request,=20final=20Serv= letResponse=20response)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20FacesContext=20facesContex= t=20=3D=20FacesContext.getCurrentInstance(); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20if=20(facesContext=20!=3D=20= null)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20re= turn=20facesContext; =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20return=20getNewFacesContex= t(viewId,=20request,=20response); =20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20public=20static=20FacesContext=20getNewFacesContex= t(final=20String=20viewId,=20final=20ServletRequest=20request,=20final=20S= ervletResponse=20response)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20FacesContext=20facesContex= t; =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20FacesContextFactory=20cont= extFactory=20=3D=20(FacesContextFactory)=20FactoryFinder.getFactory(Factor= yFinder.FACES_CONTEXT_FACTORY); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20LifecycleFactory=20lifecyc= leFactory=20=3D=20(LifecycleFactory)=20FactoryFinder.getFactory(FactoryFin= der.LIFECYCLE_FACTORY); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Lifecycle=20lifecycle=20=3D= =20lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20facesContext=20=3D=20conte= xtFactory.getFacesContext(((HttpServletRequest)request).getSession().getSe= rvletContext(),request,=20response,=20lifecycle); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20InnerFacesContext.setFaces= ContextAsCurrentInstance(facesContext); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20UIViewRoot=20view=20=3D=20= facesContext.getApplication().getViewHandler().createView(facesContext,=20= viewId); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20facesContext.setViewRoot(v= iew); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20return=20facesContext; =20=20=20=20=20=20=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: public=20class=20ForwardToJSFAction=20extends=20Action=20{ =20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20public=20ActionForward=20execute(ActionMapping=20m= apping,=20ActionForm=20form,=20HttpServletRequest=20request,=20HttpServlet= Response=20response)=20throws=20Exception=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20JSFMapping=20viewMapping=20= =3D=20(JSFMapping)=20mapping; =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20FacesContext=20ctx=20=3D=20= JSFBridge.getFacesContext(viewMapping.getViewId(),=20request,=20response);= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20MethodBinding=20mb=20=3D=20= lookupMethodBinding(viewMapping,=20ctx); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20navigateToMethodBinding(vi= ewMapping,=20ctx,=20mb); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20return=20null; =20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20private=20MethodBinding=20lookupMethodBinding(JSFM= apping=20viewMapping,=20FacesContext=20ctx)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20return=20ctx.getApplicatio= n().createMethodBinding("#{"=20+=20viewMapping.getJsfAction()=20+=20"}",=20= new=20Class[]=20{}); =20=20=20=20=20=20=20=20} =20=20=20=20=20=20=20=20private=20void=20navigateToMethodBinding(JSFMappin= g=20viewMapping,=20FacesContext=20ctx,=20MethodBinding=20mb)=20{ =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20Object=20obj=20=3D=20mb.in= voke(ctx,=20new=20Object[]=20{}); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20NavigationHandler=20navHan= dler=20=3D=20ctx.getApplication().getNavigationHandler(); =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20navHandler.handleNavigatio= n(ctx,=20"#{"=20+=20viewMapping.getJsfAction()=20+=20"}",=20(String)=20obj= ); =20=20=20=20=20=20=20=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 =20=20=20=20=20=20=20=20at=20org.apache.catalina.connector.Request.setAttr= ibute(Request.java:1376) =20=20=20=20=20=20=20=20at=20org.apache.catalina.connector.RequestFacade.s= etAttribute(RequestFacade.java:500) =20=20=20=20=20=20=20=20at=20javax.servlet.ServletRequestWrapper.setAttrib= ute(ServletRequestWrapper.java:283) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.context.servlet.RequestMap= .setAttribute(RequestMap.java:46) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.context.servlet.AbstractAt= tributeMap.put(AbstractAttributeMap.java:104) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.el.VariableResolverImpl.re= solveVariable(VariableResolverImpl.java:301) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.config.LastVariableResolve= rInChain.resolveVariable(LastVariableResolverInChain.java:42) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.el.ValueBindingImpl$ELVari= ableResolver.resolveVariable(ValueBindingImpl.java:574) =20=20=20=20=20=20=20=20at=20org.apache.commons.el.NamedValue.evaluate(Nam= edValue.java:124) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.el.ValueBindingImpl.resolv= eToBaseAndProperty(ValueBindingImpl.java:455) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.el.MethodBindingImpl.resol= veToBaseAndProperty(MethodBindingImpl.java:180) =20=20=20=20=20=20=20=20at=20org.apache.myfaces.el.MethodBindingImpl.invok= e(MethodBindingImpl.java: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 not=20the=20intended=20recipient=20of=20this=20message=20you=20must=20not=20= use, 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. National=20Transport=20Insurance=20does=20not=20accept=20responsibility=20= for=20changes=20made=20to=20this=20message=20after=20it=20was=20sent. ______________________________________________________________________=20 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_01C901C2.D43CE13B Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable NullPointerException=205.5.17=20Request.setAttribute(Request.java:1= 376) Hi,=20I= 've=20sent=20the=20following=20 to=20the=20tomcat=20mailing=20lists=20for=20advice,=20but=20since=20it=20a= lso=20involves=20myfaces=20I=20 thought=20I'd=20send=20it=20here=20too. =20I=20hope=20someone,=20some= where=20has=20some=20idea=20as=20 to=20what's=20going=20on.   Cheers Adam
From:=20Adam=20Jenkins=20 [mailto:AdamJenkins@nti.com.au]
Sent:=20Tue=2019/08/2008=204:05=20= PM
To:=20users@tomcat.apache.org
Subject:=20NullPointe= rException=20 5.5.17=20Request.setAttribute(Request.java:1376)

Hi=20All,
I'be=20been=20tearing=20my=20hair=20out=20= for=20a=20couple=20of=20weeks=20 over=20this=20one=20and=20would=20appreciate=20any=20assistance=20anyone=20= could=20give. =20It's=20 a=20bit=20of=20a=20unique=20scenario,=20so=20it'll=20take=20me=20a=20littl= e=20while=20to=20explain:
We=20 have=20a=20legacy=20struts=20app,=20forwarding=20to=20a=20jsf=20app=20(det= ails=20of=20how=20below)=20running=20 on=20tomcat=205.5.17. =2099.9%=20of=20the=20time=20everythign=20works= =20great,=20but=20every=20now=20 and=20then=20(which=20in=20users=20speak=20translates=20to=20'I=20keep=20o= n=20getting',=20hence=20we=20can't=20 ignore=20it)=20a=20NullPointerException=20gets=20thrown=20from=20 org.apache.catalina.connector.Request.setAttribute.
The=20flow=20is:Third=20 party=20application=20---<<http=20redirect>>--->=20JSFBridg= eFilter=20(will=20 explain=20later)=20----->=20Struts=20application=20---->=20JSFBridge= --->JSF=20 Application--->Response=20back=20to=20third=20party=20app.
The=20str= uts=20application=20 contains=20proprietary=20logic=20to=20interface=20with=20the=20third=20par= ty=20app,=20so=20we=20can't=20 get=20rid=20of=20it.=20Business=20wants=20all=20development=20internally=20= to=20be=20done=20in=20JSF,=20so=20 we=20can't=20get=20rid=20of=20that.
The=20JSFBridgeFilter=20instantiate= s=20the=20JSF=20Context=20 for=20later=20use,=20and=20wraps=20the=20request=20that=20is=20used=20to=20= instantiate=20it=20in=20a=20request=20 wrapper=20that=20translates=20".do"=20context=20paths=20to=20".jsf"=20cont= ext=20paths=20(otherwise=20 all=20the=20forms=20submit=20back=20to=20".do"=20after=20coming=20from=20t= he=20struts=20framework. =20 It=20looks=20like=20this:
public=20void=20doFilter(ServletRequest=20str= utsRequest,=20 ServletResponse=20response,=20FilterChain=20chain)=20throws=20IOException,= =20 ServletException=20{

HttpServletRequest=20jsfRequest=20=3D=20new=20= StrutsToJsfRequestWrapper((HttpServletRequest)strutsRequest);

JSFBr= idge.getFacesContext(viewId,=20 (HttpServletRequest)jsfRequest,=20 (HttpServletResponse)response);

chain.doFilter(strutsRequest,=20 response);

}

...and=20the=20StrutsToJsfRequestWrapper=20cont= ains=20only=20 one=20override=20method=20(it=20extends=20 HttpServletRequestWrapper):
@Override

public=20String=20getServl= etPath()=20 {

       =20String=20oldPath=20=3D= =20 super.getServletPath();

       =20= String=20 newPath=20=3D=20null;

       =20= int=20index=20=3D=20 oldPath.lastIndexOf(".do");

      &nb= sp;=20if=20 (index=20>=3D=200)=20{

       = ;=20        =20newPath=20=3D=20oldPath.subst= ring(0,=20index=20 +=201)=20+=20".jsf";

       =20}= =20else=20 {

       =20        =20newPath=20=3D=20 oldPath;

       =20 }

       =20return=20 newPath;

}



Now,=20you'll=20notice=20in=20the=20filte= r=20that=20the=20 request=20wrapper=20is=20used=20to=20instantiate=20the=20faces=20context,=20= and=20the=20original=20 request=20passed=20onto=20the=20struts=20application. =20The=20'getFa= cesContext'=20method=20 implements=20some=20code=20from=20the=20apache=20myfaces=20wiki=20that=20s= hows=20a=20way=20to=20call=20into=20 the=20JSF=20framework=20from=20non=20jsf=20artifacts:



It=20= looks=20like=20 this:



public=20class=20JSFBridge=20 {



       =20private=20ab= stract=20 static=20class=20InnerFacesContext=20extends=20FacesContext=20 {

       =20        =20protected=20static=20void=20 setFacesContextAsCurrentInstance(final=20FacesContext=20facesContext)=20 {

       =20        =20        =20 FacesContext.setCurrentInstance(facesContext);

   &n= bsp;   =20        =20 }

       =20 }



       =20public=20sta= tic=20 FacesContext=20getFacesContext(final=20String=20viewId,=20final=20ServletR= equest=20request,=20 final=20ServletResponse=20response)=20 {

       =20        =20FacesContext=20facesContext=20= =3D=20 FacesContext.getCurrentInstance();

     &n= bsp; =20        =20if=20(facesContext=20!=3D=20n= ull)=20 {

       =20        =20        =20return=20 facesContext;

       =20        =20 }

       =20        =20return=20getNewFacesContext(v= iewId,=20 request,=20response);

       =20= }



       =20public=20sta= tic=20 FacesContext=20getNewFacesContext(final=20String=20viewId,=20final=20Servl= etRequest=20 request,=20final=20ServletResponse=20response)=20 {

       =20        =20FacesContext=20 facesContext;

       =20        =20FacesContextFactory=20context= Factory=20=3D=20 (FacesContextFactory)=20 FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);

&nbs= p;      =20        =20LifecycleFactory=20lifecycleF= actory=20=3D=20 (LifecycleFactory)=20 FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);

 &n= bsp;     =20        =20Lifecycle=20lifecycle=20=3D=20= lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);

=        =20        =20facesContext=20=3D=20 contextFactory.getFacesContext(((HttpServletRequest)request).getSession().= getServletContext(),request,=20 response,=20lifecycle);

       =20=        =20 InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);

&= nbsp;      =20        =20UIViewRoot=20view=20=3D=20 facesContext.getApplication().getViewHandler().createView(facesContext,=20= viewId);

       =20        =20 facesContext.setViewRoot(view);

      = ; =20        =20return=20 facesContext;

       =20 }

}



And=20the=20final=20piece=20of=20the=20puzzle=20= is=20a=20struts=20action=20 that=20actually=20loads=20the=20context=20and=20forwards=20to=20the=20appr= opriate=20JSF=20 method...which=20looks=20like=20this:



public=20class=20Forw= ardToJSFAction=20 extends=20Action=20 {

       

  &nb= sp;    =20 public=20ActionForward=20execute(ActionMapping=20mapping,=20ActionForm=20f= orm,=20 HttpServletRequest=20request,=20HttpServletResponse=20response)=20throws=20= Exception=20 {

       =20        =20JSFMapping=20viewMapping=20=3D= =20(JSFMapping)=20 mapping;

       =20        =20FacesContext=20ctx=20=3D=20 JSFBridge.getFacesContext(viewMapping.getViewId(),=20request,=20 response);

       =20        =20MethodBinding=20mb=20=3D=20 lookupMethodBinding(viewMapping,=20 ctx);

       =20        =20navigateToMethodBinding(viewM= apping,=20 ctx,=20mb);

       =20        =20return=20 null;

       =20 }



       =20private=20 MethodBinding=20lookupMethodBinding(JSFMapping=20viewMapping,=20FacesConte= xt=20ctx)=20 {

       =20        =20return=20 ctx.getApplication().createMethodBinding("#{"=20+=20viewMapping.getJsfActi= on()=20+=20 "}",=20new=20Class[]=20{});

      &nb= sp;=20 }



       =20private=20vo= id=20 navigateToMethodBinding(JSFMapping=20viewMapping,=20FacesContext=20ctx,=20= MethodBinding=20 mb)=20{

       =20        =20Object=20obj=20=3D=20mb.invok= e(ctx,=20new=20 Object[]=20{});

       =20        =20NavigationHandler=20navHandle= r=20=3D=20 ctx.getApplication().getNavigationHandler();

   &nbs= p;   =20        =20navHandler.handleNavigation(c= tx,=20"#{"=20 +=20viewMapping.getJsfAction()=20+=20"}",=20(String)=20 obj);

       =20 }

}



Now,=20as=20odd=20as=20all=20this=20looks,=20it=20= actually=20works=20quite=20 well=20in=2099.9%=20of=20the=20cases. =20We=20get=20a=20request=20in=20= struts,=20which=20forwards=20 quite=20nicely=20onto=20a=20JSF=20method=20and=20completes=20the=20busines= s=20process=20in=20JSF. =20 Every=20now=20and=20then=20though,=20we=20get=20the=20following=20error=20= when=20we=20try=20to=20invoke=20the=20 method=20binding:

Caused=20by:=20 java.lang.NullPointerException
      &nbs= p;=20at=20 org.apache.catalina.connector.Request.setAttribute(Request.java:1376)
&= nbsp;      =20 at=20 org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.jav= a:500)
       =20 at=20 javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.jav= a:283)
       =20 at=20 org.apache.myfaces.context.servlet.RequestMap.setAttribute(RequestMap.java= :46)
       =20 at=20 org.apache.myfaces.context.servlet.AbstractAttributeMap.put(AbstractAttrib= uteMap.java:104)
       =20 at=20 org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolve= rImpl.java:301)
       =20 at=20 org.apache.myfaces.config.LastVariableResolverInChain.resolveVariable(Last= VariableResolverInChain.java:42)
      &n= bsp;=20 at=20 org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVariable(= ValueBindingImpl.java:574)
       =20= at=20 org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
 &n= bsp;     =20 at=20 org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindi= ngImpl.java:455)
       =20 at=20 org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(MethodBin= dingImpl.java:180)
       =20 at=20 org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:114)=
Diving=20 into=20Request.java(Line=201376),=20shows=20that=20it's=20happening=20on=20= this=20line:
Object=20 listeners[]=20=3D=20context.getApplicationEventListeners();
So=20I'm=20= guessing=20that=20 'context'=20is=20null=20for=20some=20reason. =20Since=20it=20is=20so=20= rare,=20it's=20almost=20 impossible=20to=20reproduce=20in=20a=20manner=20consistent=20enough=20to=20= actually=20diagnose=20and=20 debug=20it.
Can=20anyone=20see,=20from=20the=20above,=20anything=20that= =20could=20shed=20some=20light=20 on=20this?
Cheers
Adam

Number=201=20in=20Truck=20 Insurance

_________________________________________________________= _____________
CAUTION=20 -=20This=20message=20is=20intended=20for=20the=20addressee=20named=20above= .

It=20may=20contain=20 privileged=20or=20confidential=20information.=20If=20you=20are
not=20th= e=20intended=20recipient=20 of=20this=20message=20you=20must=20not=20use,
copy,=20distribute=20or=20= disclose=20it=20to=20anyone=20 other=20than=20the=20addressee.
If=20you=20have=20received=20this=20ema= il=20in=20error=20please=20 return=20the=20message=20to=20the=20sender=20by=20replying=20to=20it=20and= =20then=20delete=20the=20message=20 from=20your=20computer.

Internet=20e-mails=20are=20not=20necessaril= y=20 secure.
National=20Transport=20Insurance=20does=20not=20accept=20respon= sibility=20for=20 changes=20made=20to=20this=20message=20after=20it=20was=20 sent.
_________________________________________________________________= _____=20


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_01C901C2.D43CE13B--