Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Snaps Parent Application Context Not Loading
Snaps Parent Application Context Not Loading [message #856564] Wed, 25 April 2012 19:48 Go to next message
Jeremy Erdmann is currently offline Jeremy ErdmannFriend
Messages: 3
Registered: April 2012
Junior Member
I'm creating a Snap and attempting to load an application context in Web.xml:

<context-param>
<param-name>contextClass</param-name>
<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

The beans in my "applicationContext.xml" are never loaded. To double check I added some XML parsing errors to the "applicationContext.xml" file in the "org.eclipse.virgo.snaps.sample.cat-3.0.2.RELEASE.jar" example snap and deployed it. There were no errors and the snap installs fine. This indicates that the application context is not loading at all.

Is there a way to get the application context to load in a Snap?
Re: Snaps Parent Application Context Not Loading [message #865631 is a reply to message #856564] Mon, 30 April 2012 13:50 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

Hi,

Being a Snap should make no difference, to really eliminate any influence from Snaps, try deploying it on Virgo without the Snaps bundles installed. Also, what location in the WAB have you got the "applicationContext.xml" file. Unless it's the default one (under WEB-INF I think) you have to specify the location in the web.xml.

Chris.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Snaps Parent Application Context Not Loading [message #865753 is a reply to message #865631] Mon, 30 April 2012 14:56 Go to previous messageGo to next message
Jeremy Erdmann is currently offline Jeremy ErdmannFriend
Messages: 3
Registered: April 2012
Junior Member
The listener class for the application context does not load for child snaps at all. I tried modifying web.xml for the "Cat" snap in the example application to the following:


<display-name>Snaps the Complicated Cat</display-name>


<!-- CONFIGURE A PARENT APPLICATION CONTEXT -->

<context-param>
<param-name>contextClass</param-name>
<param-value>org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerBADNAME</listener-class>
</listener>

<!-- DISPATCHER SERVLET CONFIG -->

<servlet>
<servlet-name>cat</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>cat</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>


Notice the invalid class name for the listener. The snap installs fine without any errors in the logs. If I attempt to install it as a standalone WAB module it errors.

The behaviour seems to indicate that the listener is not getting fired for the child snap.
Re: Snaps Parent Application Context Not Loading [message #870787 is a reply to message #865753] Wed, 09 May 2012 16:44 Go to previous message
Paul Duffin is currently offline Paul DuffinFriend
Messages: 9
Registered: July 2009
Junior Member
Based on my analysis of the snaps 3.0.2 source code (doubt that 3.0.3 has changed it significantly) the web.xml of the snap is NOT processed fully, as would be done by Tomcat. Instead it is processed by Snaps code itself and it only uses the following parts of the web.xml, the rest is simply ignored:
* servlet
* servlet-mapping
* filter
* filter-mapping

So, servlet context listeners are not supported, and neither are mime mappings, etc..

I presume that most if not all of the excluded information make no sense within a snap. Listeners could be useful but they are listening to the state of the ServletContext and the user guide does say:
Quote:
Remember that a host and all its snaps use a single ServletContext.

As the host is created before the snap that means that the ServletContext is created before any snaps have been installed and after all snaps have been removed and so during the lifetime of a span there is no change in the state of the ServletContext and so the listener is not invoked.

It would be useful if this sort of information was made much clearer in the snaps user guide.
Previous Topic:JCE cannot authenticate provider installed as OSGi bundle
Next Topic:Problems loading ApplicatioContext file in a WAB
Goto Forum:
  


Current Time: Mon Dec 22 01:28:55 GMT 2014

Powered by FUDForum. Page generated in 0.01717 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software