Ok thank you Wouter.

Actually I found a solution and as I think it might be useful to anyone trying 
to integrate AndroMDA Spring cartridge with a web application, here it is 
(might be added as a patch to Spring cartridge).



The problem was that OpenSessionInViewFilter (which is very useful to prevent 
lazy loading exceptions in web tier) is not flexible enough to accept the 
structure of Spring configuration files generated by Spring cartridge, that is 
one beanRefFactory bean with separate applicationContext-datasource and 
applicationContext inside. By default, 
org.springframework.orm.hibernate.support.OpenSessionInViewFilter expects 
sessionFactory bean in root application context so with the following usual 
web.xml configuration :



<context-param>

&nbsp; &nbsp; &nbsp; &nbsp; <param-name>contextConfigLocation</param-name>

&nbsp; &nbsp; &nbsp; &nbsp; 
<param-value>/WEB-INF/classes/beanRefFactory.xml</param-value>

&nbsp; &nbsp; </context-param>

&nbsp; &nbsp; <listener>

&nbsp; &nbsp; &nbsp; &nbsp; <listener-class>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
org.springframework.web.context.ContextLoaderListener

&nbsp; &nbsp; &nbsp; &nbsp; </listener-class>

&nbsp; &nbsp; </listener>

&nbsp; &nbsp; <filter>

&nbsp; &nbsp; &nbsp; &nbsp; <filter-name>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OpenSessionInViewFilter

&nbsp; &nbsp; &nbsp; &nbsp; </filter-name>

&nbsp; &nbsp; &nbsp; &nbsp; <filter-class>

org.springframework.orm.hibernate.support.OpenSessionInViewFilter&nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; 

&nbsp; &nbsp; &nbsp; &nbsp; </filter-class>

&nbsp; &nbsp; &nbsp; &nbsp; <init-param>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <param-name>singleSession</param-name>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <param-value>false</param-value>

&nbsp; &nbsp; &nbsp; &nbsp; </init-param>

&nbsp; &nbsp; </filter>

&nbsp; &nbsp; <filter-mapping>

&nbsp; &nbsp; &nbsp; &nbsp; <filter-name>OpenSessionInViewFilter</filter-name>

&nbsp; &nbsp; &nbsp; &nbsp; <url-pattern>/*</url-pattern>

&nbsp; &nbsp; </filter-mapping>





The webapp initialization went right but on the first request PAF "Code 500 
Internal Server Error" because of course sessionFactory bean is not defined in 
beanRefFactory.xml

And the only flexibility allowed by OpenSessionInViewFilter is to specify a 
custom name for the sessionFactory bean, but no custom "path".

So I had to extend OpenSessionInViewFilter and override lookupSessionFactory() 
method, which gives :





package org.epseelon.andromda.utils;



import net.sf.hibernate.SessionFactory;

import org.springframework.beans.factory.BeanFactory;

import org.springframework.orm.hibernate.support.OpenSessionInViewFilter;

import org.springframework.web.context.WebApplicationContext;

import org.springframework.web.context.support.WebApplicationContextUtils;



/**

* This class extends OpenSessionInViewFilter to take into account the 
particular Spring 

&nbsp;* configuration files structure generated by AndroMDA, that is one root 
beanRefFactory application

&nbsp;* context with separated datasource and common beans sub-application 
contexts.

&nbsp;* @author S�bastien Arbogast

&nbsp;*/

public class OpenSessionInViewFilterForAndromda extends OpenSessionInViewFilter 
&#123;

&nbsp; &nbsp;

&nbsp; &nbsp;/**

&nbsp; &nbsp; * @see 
org.springframework.orm.hibernate.support.OpenSessionInViewFilter#lookupSessionFactory&#40;&#41;

&nbsp; &nbsp; */

&nbsp; &nbsp;protected SessionFactory lookupSessionFactory&#40;&#41; &#123;

&nbsp; &nbsp;&nbsp; &nbsp;// TODO Raccord de m�thode auto-g�n�r�

&nbsp; &nbsp;&nbsp; &nbsp;//return super.lookupSessionFactory&#40;&#41;;

&nbsp; &nbsp;&nbsp; &nbsp;if &#40;logger.isDebugEnabled&#40;&#41;&#41; &#123;

&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;logger.debug&#40;"Using session factory 
'" + getSessionFactoryBeanName&#40;&#41; + "' for 
OpenSessionInViewFilterForAndromda"&#41;;

&nbsp; &nbsp;&nbsp; &nbsp;&#125;

&nbsp; &nbsp;&nbsp; &nbsp;WebApplicationContext wac = 
WebApplicationContextUtils.getRequiredWebApplicationContext&#40;getServletContext&#40;&#41;&#41;;

&nbsp; &nbsp;&nbsp; &nbsp;

&nbsp; &nbsp;&nbsp; &nbsp;BeanFactory bf = 
&#40;BeanFactory&#41;wac.getBean&#40;"beanRefFactory"&#41;;

&nbsp; &nbsp;&nbsp; &nbsp;return &#40;SessionFactory&#41; 
bf.getBean&#40;getSessionFactoryBeanName&#40;&#41;&#41;;

&nbsp; &nbsp;&#125;

&#125;





Then I just had to change the filter class in web.xml and now everything works 
great.
--
S�bastien Arbogast
_________________________________________________________
Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=95#95


-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click
_______________________________________________
Andromda-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/andromda-user

Reply via email to