Bug 371061 - Using JSF with snaps gives IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory
Summary: Using JSF with snaps gives IllegalStateException: Could not find backup for f...
Status: NEW
Alias: None
Product: Virgo
Classification: RT
Component: snaps (show other bugs)
Version: 3.0.2.RELEASE   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on: 371379
Blocks:
  Show dependency tree
 
Reported: 2012-02-09 06:19 EST by Moacir Cardoso CLA
Modified: 2017-02-03 16:53 EST (History)
5 users (show)

See Also:


Attachments
JSF Snap Project (15.62 KB, application/zip)
2012-02-09 06:19 EST, Moacir Cardoso CLA
no flags Details
GWT Snap Project (95.34 KB, application/zip)
2012-02-10 17:00 EST, Moacir Cardoso CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Moacir Cardoso CLA 2012-02-09 06:19:03 EST
Created attachment 210790 [details]
JSF Snap Project

You can not start a jsf web application as a snap.
The host application is a JSP WAB, the child application is JSF + RichFaces4.
Both work separately whem deployed on virgo tomcat serer. 

Details can be found here http://www.eclipse.org/forums/index.php?t=rview&goto=794248#msg_794248

TCCL is getting poped and set to 'sun.misc.Launcher$AppClassLoader@f4a24a' right before snaps start processing web.xml

[2012-02-06 09:14:51.173] INFO   TCP Connection(4)-127.0.0.1 o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManager     Thread context class loader 'KernelBundleClassLoader: [bundle=br.teste.webapp.jsf_1.0.0]' popped and set to 'KernelBundleClassLoader: [bundle=br.teste.webapp.jsf_1.0.0]' 
[2012-02-06 09:14:51.174] INFO   TCP Connection(4)-127.0.0.1 o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManager     Thread context class loader 'KernelBundleClassLoader: [bundle=br.teste.webapp.jsf_1.0.0]' popped and set to 'sun.misc.Launcher$AppClassLoader@f4a24a' 
[2012-02-06 09:14:51.739] INFO  start-signalling-2           o.e.virgo.snaps.core.internal.webapp.config.BundleWebXmlLoader    Loading configuration from 'bundleentry://109.fwk22262475/META-INF/snaps/default-web.xml' 

It seems that the listener com.sun.faces.config.ConfigureListener was not initialized. When you try to access the snap application the error below occurs

Bundle org.eclipse.osgi_3.7.0.v20110613, An unexpected runtime error has occurred. java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory. 


In attached file there are two Eclipse projects:
br.teste.webapp.core
br.teste.webapp.jsf
Jsf Mojarra javax.faces-2.1.6.jar deployed as a separeted bundle.

The snap-host is the br.teste.webapp.core.

If you deploy the project without the manifest tags Snap-Host and Snap-contextPath it works perfectly, otherwise the above error occurs.
Comment 1 Nobody - feel free to take it CLA 2012-02-10 06:51:51 EST
I agree that the popping of the TCCL to sun.misc.Launcher$AppClassLoader immediately before the loading of default-web.xml did look a bit suspicious. However, it is normal behaviour and irrelevant to the problemat hand, for two reasons.

Firstly, sun.misc.Launcher$AppClassLoader is the default TCCL and this is pushed and popped by BundleThreadContextManager as necessary. So the default value being popped is really irrelevant as the purpose of BundleThreadContextManager is to push an appropriate TCCL and later pop whatever was there previously.

Secondly, in the trace provided in the description, the TCCL pop is occurring on thread "TCP Connection(4)-127.0.0.1" which is different to the thread "start-signalling-2" which is  loading configuration from default-web.xml. So the pop won't make any difference to the TCCL in place on the thread which loads the configuration.

I am therefore changing the title of the bug to reflect that it is an issue getting JSF and snaps to work together.
Comment 2 Chris Frost CLA 2012-02-10 07:02:44 EST
Adding to Glyns comments. We have not had much luck with JSF before, the way it's packaged isn't very friendly to OSGi and people have had problems getting that going on OSGi as it is. I can't actually remember anyone that's managed to get it working on Snaps so it might not be possible without some quite fundamental changes to Snaps. 

We will have a look though and see what we can learn at the very least, thank you for the sample app to allow us to do this. Once we know just how JSF is trying to lookup its context factory we will have a better idea of the situation.

Chris.
Comment 3 Moacir Cardoso CLA 2012-02-10 17:00:06 EST
Created attachment 210876 [details]
GWT Snap Project

I do not believe that the JSF could be the problem.
The same occurs in another example that uses GWT.

I'll provide a simple example with JSP and Spring.
Comment 4 Moacir Cardoso CLA 2012-02-13 09:54:09 EST
As I said before, I do not think the problem is specifically with JSF. I tried the same with a GWT application and the problem continues.
I think the way the snap is trying to process the application web.xml has some faults.

I noticed that the servlet's configured in web.xml are being loaded correctly but the listeners responsible for proper initialization of the frameworks do not seem to work.

In the case of the JSF application the web.xml has the following listener

<listener>
     <listener-class> com.sun.faces.config.ConfigureListener </ listener-class>
</ listener>

It is responsible for parsing all relevant JavaServer Faces configuration resources, and set the Reference Implementation runtime environment. Without it the following error occurs:
java.lang.IllegalStateException: Could not find backup for factory
javax.faces.context.FacesContextFactory

The web.xml of the GWT test application has the same issues. He also uses a listener to load the applicationContext.xml and load some beans. 
Again the servlet springGwtRemoteServiceServlet is loaded but then it finds no instance of the applicationContext.

<web-app xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: web = "http :/ / java.sun.com/xml/ns/javaee/web-app_2_5.xsd "xsi: schemaLocation =" http://java.sun.com/xml/ns/javaee http://java.sun.com / xml/ns/javaee/web-app_2_5.xsd "version =" 2.5 ">
   <! - Spring context ->
<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> / WEB-INF/applicationContext.xml </ param-value>
</ context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>
   <servlet>
     <servlet-name> springGwtRemoteServiceServlet </ servlet-name>
     <servlet-class> org.spring4gwt.server.SpringGwtRemoteServiceServlet </ servlet-class>
   </ servlet>
   <servlet-mapping>
     <servlet-name> springGwtRemoteServiceServlet </ servlet-name>
<url-pattern> / gwt_teste / remote / * </ url-pattern>
   </ servlet-mapping>
   <welcome-file-list>
     <welcome-file> Gwt_teste.html </ welcome-file>
   </ welcome-file-list>
</ web-app>

For some reason no listener works with snaps.
Comment 5 Nobody - feel free to take it CLA 2012-02-13 10:47:32 EST
(In reply to comment #4)
> As I said before, I do not think the problem is specifically with JSF. I tried
> the same with a GWT application and the problem continues.

What are the symptoms of the problem with the GWT application? If it's not "IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory" then please update the bug title to reflect the symptom you would like this bug to address.
Comment 6 Dmitry Sklyut CLA 2012-02-13 11:06:23 EST
It all boils down to Snaps not supporting Listeners in web.xml.

I will update this issue when listener support is finalized (2 - 3 weeks time).

Dmitry
Comment 7 Moacir Cardoso CLA 2012-02-13 11:07:02 EST
Hi Glyn,
apparently the problem seems to be that listeners configured in web.xml are not being loaded when the application runs as a snap.

The title is good for me, because the exception that occurs is a consequence of the listener not be running.

With GWT what happens is that it uses a listener to load and initialize the applicaction context.xml. When this application runs as a snap the listener does not load.

But I only mention the GWT application on this post to indicate that not only the JSF has problems in running as a snap.

Thank you for listening, and I am available to help in whatever is needed.
Comment 8 Nobody - feel free to take it CLA 2012-02-13 11:20:05 EST
(In reply to comment #6)
> It all boils down to Snaps not supporting Listeners in web.xml.
> 
> I will update this issue when listener support is finalized (2 - 3 weeks time).
> 
> Dmitry

Thanks. For clarity, please could you raise an enhancement bug to cover adding listener support. (We could hijack this bug, but that seems a little unfair given the specific symptoms captured here.)
Comment 9 Dmitry Sklyut CLA 2012-02-13 11:26:43 EST
Created 371379

Thanks
Dmitry
Comment 10 Nobody - feel free to take it CLA 2012-02-13 11:48:44 EST
Thanks Dmitry. Given that it is now clear that snaps does not support listeners in web.xml, this bug should be fixed either by documenting the restriction or, preferably, by implementing bug 371379.
Comment 11 Nobody - feel free to take it CLA 2012-02-27 06:24:00 EST
Flagging as enhancement since the function of 371379 is not yet supported.