Hi Aaron, just as a side note: It is not guaranteed that a servlet container uses only one instance of a servlet. He might even create a new instance of it with each request (I had to deal with such a beast). Therefore I propose the ApplicationListner for the Avalon initialization. This would guarantee the Avalon services beeing available for any servlet in the webapp.
Regards, J�rg Farr, Aaron wrote: >> -----Original Message----- >> From: Farr, Aaron [mailto:[EMAIL PROTECTED] >> I haven't had time to test this, since I have to run to an >> appointment, but here's a very simple avalon-struts solution: > > Apparently the attachment got stripped or something. Here's the > class: > > ---------------- AvalonActionServlet.java > ----------------------------- > > package org.apache.avalon.struts; > > import org.apache.struts.action.ActionServlet; > import org.apache.avalon.fortress.ContainerManager; > import org.apache.avalon.fortress.impl.DefaultContainerManager; > import org.apache.avalon.fortress.impl.DefaultContainer; > import org.apache.avalon.framework.container.ContainerUtil; > import org.apache.avalon.framework.service.ServiceManager; > > import java.io.IOException; > import java.io.File; > import javax.servlet.ServletException; > > > public class AvalonActionServlet extends ActionServlet { > > public static final String SERVICE_MANAGER = > "org.apache.avalon.framework.service.ServiceManager"; > protected static final String CONTAINER_CLASS = > "avalon.container.class"; > protected static final String CONTAINER_CONF = > "avalon.container.conf"; > protected static final String LOGGER_CONF = "avalon.logger.conf"; > > protected String m_containerClass = > "org.apache.avalon.fortress.impl.DefaultContainer"; > protected String m_containerConf = "/WEB-INF/system.xconf"; > protected String m_loggerConf = "/WEB-INF/system.xlog"; > protected ContainerManager m_containerManager; > protected DefaultContainer m_container; > protected ServiceManager m_manager; > > public AvalonActionServlet() > { > } > > > public void init() throws ServletException { > super.init(); > > String containerClass = getInitParameter(CONTAINER_CLASS); > String containerConf = getInitParameter(CONTAINER_CONF); > String loggerConf = getInitParameter(LOGGER_CONF); > > if(containerClass != null) > m_containerClass = containerClass; > > if(containerConf != null) > m_containerConf = containerConf; > > if(loggerConf != null) > m_loggerConf = loggerConf; > > try > { > final org.apache.avalon.fortress.util.FortressConfig config = > new org.apache.avalon.fortress.util.FortressConfig(); > config.setContainerClass( m_containerClass ); > config.setContextDirectory( > getServletContext().getRealPath("/") ); > config.setWorkDirectory( (File) > getServletContext().getAttribute( > "javax.servlet.context.tempdir" ) ); > config.setContainerConfiguration( m_containerConf ); > config.setLoggerManagerConfiguration( m_loggerConf ); > > m_containerManager = new DefaultContainerManager( > config.getContext() ); ContainerUtil.initialize( > m_containerManager ); > > m_container = (DefaultContainer) > m_containerManager.getContainer(); > m_manager = m_container.getServiceManager(); > > getServletContext().setAttribute(SERVICE_MANAGER,m_manager); > > } > catch( Exception e ) > { > throw new ServletException( "Error during > initialization", e ); > } > } > > public void destroy(){ > super.destroy(); > > ContainerUtil.dispose(m_containerManager); > > } > > } > > > ---------------- > > jaaron > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
