Changeset 9ee106fab8ca310bad99ec4e49e9db8f3c608de7

Show
Ignore:
Timestamp:
09/22/07 15:17:59 (1 year ago)
Author:
Christopher Jung <bktheg@web.de>
git-committer:
Christopher Jung <bktheg@web.de> 1190467079 +0200
git-parent:

[740f4b34f443868b8822df7fcdc347bc1656fc14]

git-author:
Christopher Jung <bktheg@web.de> 1186924158 +0200
Message:

Abhaengigkeiten vom DS-Servlet reduziert und einige wichtige Dinge in Listener ausgelagert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/net/driftingsouls/ds2/server/framework/BasicContext.java

    rc99180b r9ee106f  
    246246                return response; 
    247247        } 
     248         
     249        public void setResponse(Response response) { 
     250                this.response = response; 
     251        } 
    248252 
    249253        /** 
  • src/net/driftingsouls/ds2/server/framework/Context.java

    r5ba971b r9ee106f  
    133133         
    134134        /** 
     135         * Setzt das zum Aufruf gehoerende Response-Objekt 
     136         * @param response Das Response-Objekt 
     137         */ 
     138        public abstract void setResponse(Response response); 
     139         
     140        /** 
    135141         * Liefert eine pro Kontext einmalige Instanz einer Klasse. 
    136142         * Sollte keine Instanz dieser Klasse im Kontext vorhanden sein, 
  • src/net/driftingsouls/ds2/server/framework/DriftingSoulsServlet.java

    r740f4b3 r9ee106f  
    3434import javax.servlet.http.HttpServletResponse; 
    3535 
    36 import net.driftingsouls.ds2.server.framework.db.HibernateFacade; 
    3736import net.driftingsouls.ds2.server.framework.pipeline.GeneratorPipeline; 
    38 import net.driftingsouls.ds2.server.framework.pipeline.HttpRequest; 
    3937import net.driftingsouls.ds2.server.framework.pipeline.HttpResponse; 
    4038import net.driftingsouls.ds2.server.framework.pipeline.Pipeline; 
    4139import net.driftingsouls.ds2.server.framework.pipeline.ReaderPipeline; 
    42 import net.driftingsouls.ds2.server.framework.pipeline.Request; 
    4340import net.driftingsouls.ds2.server.framework.pipeline.Response; 
    4441import net.driftingsouls.ds2.server.framework.pipeline.actions.Action; 
     
    4744import net.driftingsouls.ds2.server.framework.xml.XMLUtils; 
    4845 
    49 import org.apache.commons.logging.Log; 
    50 import org.apache.commons.logging.impl.LogFactoryImpl; 
    5146import org.w3c.dom.Document; 
    5247import org.w3c.dom.Node; 
     
    5853 * 
    5954 */ 
    60 public class DriftingSoulsServlet extends HttpServlet
     55public class DriftingSoulsServlet extends HttpServlet implements Loggable
    6156        private static final long serialVersionUID = -6026961401478799134L; 
    62          
    63         private transient Log LOG = null; 
     57 
    6458        private Map<String,ModuleSetting> modules = new HashMap<String,ModuleSetting>(); 
    6559        private transient ModuleSetting defaultModule = null; 
     
    419413        public void init(ServletConfig config) throws ServletException { 
    420414                super.init(config); 
    421                 if( config.getServletContext().getInitParameter("logger") == null ) { 
    422                         System.getProperties().setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog"); 
    423                 } 
    424                 else { 
    425                         System.getProperties().setProperty("org.apache.commons.logging.Log",config.getServletContext().getInitParameter("logger")); 
    426                 } 
    427                  
    428                 LOG = new LogFactoryImpl().getInstance("DS2"); 
    429                 LOG.info("Booting DS..."); 
    430                  
    431                 try { 
    432                         new DriftingSouls(LOG,  config.getServletContext().getInitParameter("configdir"), true); 
    433                 } 
    434                 catch( Throwable e ) { 
    435                         LOG.fatal(e, e); 
    436                         throw new ServletException(e); 
    437                 } 
    438415                 
    439416                // Pipeline lesen 
     
    466443                        throw new ServletException(e); 
    467444                } 
    468                  
    469                 LOG.info("DS is now ready for service"); 
    470445        } 
    471446 
     
    473448        protected void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, 
    474449                        ServletException { 
    475                 BasicContext context = null
     450                Context context = ContextMap.getContext()
    476451                try { 
    477452                        Pipeline pipeline = null; 
    478                         Request request = new HttpRequest(httpRequest);  
    479453                        Response response = new HttpResponse(httpResponse); 
    480                         context = new BasicContext(request, response); 
    481                         try { 
    482                                 context.putVariable(HttpServlet.class, "request", httpRequest); 
    483                                 context.putVariable(HttpServlet.class, "response", httpResponse); 
    484                                 context.putVariable(HttpServlet.class, "context", getServletContext()); 
    485                                 context.putVariable(HttpServlet.class, "config", getServletConfig()); 
    486                                  
    487                                 for( Rule rule : rules ) { 
    488                                         if( (pipeline = rule.execute(context)) != null ) { 
    489                                                 break; 
    490                                         } 
    491                                 } 
    492                                  
    493                                 if( pipeline != null ) { 
    494                                         pipeline.execute(context); 
    495                                 } 
    496                                 else { 
    497                                         throw new Exception("Unable to find a suitable rule for URL '"+request.getRequestURL()+(request.getQueryString() != null ? "?"+request.getQueryString() : "")+"'"); 
    498                                 } 
    499                                  
    500                                 response.send(); 
    501                         } 
    502                         catch( Throwable e ) { 
    503                                 context.rollback(); 
    504                                  
    505                                 throw e; 
    506                         } 
    507                         finally { 
    508                                 context.free(); 
    509                         } 
     454                        context.setResponse(response); 
     455                        context.putVariable(HttpServlet.class, "response", httpResponse); 
     456                        context.putVariable(HttpServlet.class, "config", getServletConfig()); 
     457                         
     458                        for( Rule rule : rules ) { 
     459                                if( (pipeline = rule.execute(context)) != null ) { 
     460                                        break; 
     461                                } 
     462                        } 
     463                         
     464                        if( pipeline != null ) { 
     465                                pipeline.execute(context); 
     466                        } 
     467                        else { 
     468                                throw new Exception("Unable to find a suitable rule for URL '"+context.getRequest().getRequestURL()+(context.getRequest().getQueryString() != null ? "?"+context.getRequest().getQueryString() : "")+"'"); 
     469                        } 
     470                         
     471                        response.send(); 
    510472                } 
    511473                catch( Throwable e ) { 
     474                        context.rollback(); 
     475                         
    512476                        StringBuilder msg = new StringBuilder(100); 
    513477                        msg.append("Time: "+new Date()+"\n"); 
     
    536500                } 
    537501        } 
    538  
    539         @Override 
    540         public void destroy() { 
    541                 HibernateFacade.free(); 
    542                  
    543                 super.destroy(); 
    544         } 
    545502} 
  • web/WEB-INF/web.sample.xml

    reb42e5a r9ee106f  
    3939        </context-param> 
    4040 
     41        <listener> 
     42                <listener-class>net.driftingsouls.ds2.server.framework.pipeline.DefaultServletRequestListener</listener-class> 
     43        </listener> 
     44 
     45        <listener> 
     46                <listener-class>net.driftingsouls.ds2.server.framework.pipeline.DefaultServletContextListener</listener-class> 
     47        </listener> 
     48 
    4149        <servlet> 
    4250                <description>Main DS Servlet</description> 
    4351                <servlet-name>ds</servlet-name> 
     52                <description> 
     53                        Main DS Servlet 
     54                </description> 
    4455                <servlet-class>net.driftingsouls.ds2.server.framework.DriftingSoulsServlet</servlet-class> 
    4556                <!-- Load this servlet at server startup time -->