1 50 package org.apache.avalon.fortress.examples.servlet; 51 52 import org.apache.avalon.fortress.ContainerManager; 53 import org.apache.avalon.fortress.impl.DefaultContainerManager; 54 import org.apache.avalon.framework.container.ContainerUtil; 55 56 import java.io.IOException ; 57 import java.io.File ; 58 import javax.servlet.ServletException ; 59 import javax.servlet.ServletRequest ; 60 import javax.servlet.ServletResponse ; 61 import javax.servlet.http.HttpServlet ; 62 63 69 public final class servlet extends HttpServlet 70 { 71 private ServletContainer m_container; 72 private ContainerManager m_containerManager; 73 74 79 public void init() 80 throws ServletException 81 { 82 super.init(); 83 84 try 85 { 86 final org.apache.avalon.fortress.util.FortressConfig config = new org.apache.avalon.fortress.util.FortressConfig(); 87 config.setContainerClass( ServletContainer.class ); 88 config.setContextDirectory( getServletContext().getRealPath("/") ); 89 config.setWorkDirectory( (File ) getServletContext().getAttribute( "javax.servlet.context.tempdir" ) ); 90 config.setContainerConfiguration( "resource://org/apache/avalon/fortress/examples/servlet/ServletContainer.xconf" ); 91 config.setLoggerManagerConfiguration( "resource://org/avalon/excalibur/fortress/examples/servlet/ServletContainer.xlog" ); 92 93 m_containerManager = new DefaultContainerManager( config.getContext() ); 94 ContainerUtil.initialize( m_containerManager ); 95 96 m_container = (ServletContainer)m_containerManager.getContainer(); 97 } 98 catch( Exception e ) 99 { 100 throw new ServletException ( "Error during initialization", e ); 101 } 102 } 103 104 115 public void service( ServletRequest request, ServletResponse response ) 116 throws IOException , ServletException 117 { 118 m_container.handleRequest( request, response ); 119 } 120 121 124 public void destroy() 125 { 126 ContainerUtil.dispose( m_containerManager ); 127 } 128 } 129 | Popular Tags |