Changeset 5a73c5c6c6be071f8e9267535ca39719136f5e64

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

[b504c8833d61cbfe9352976f8e2d60aee13e101b]

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

Support fuer den Ausfuehrungsmodus 'Servlet' eingebaut

Files:

Legend:

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

    rb504c88 r5a73c5c  
    2020 
    2121import java.io.IOException; 
     22import java.io.PrintWriter; 
     23import java.util.Date; 
    2224 
    2325import javax.servlet.FilterChain; 
     
    3335 
    3436import net.driftingsouls.ds2.server.framework.BasicContext; 
     37import net.driftingsouls.ds2.server.framework.Common; 
     38import net.driftingsouls.ds2.server.framework.Context; 
     39import net.driftingsouls.ds2.server.framework.ContextMap; 
    3540import net.driftingsouls.ds2.server.framework.Loggable; 
     41import net.driftingsouls.ds2.server.framework.pipeline.configuration.PipelineConfig; 
    3642 
    3743/** 
     
    6571                context.putVariable(HttpServlet.class, "request", httpRequest); 
    6672                context.putVariable(HttpServlet.class, "context", context); 
     73                context.putVariable(HttpServlet.class, "chain", chain); 
    6774                 
    6875                try { 
    69                         chain.doFilter(req, resp); 
     76                        //chain.doFilter(req, resp); 
     77                        //Context context = ContextMap.getContext(); 
     78                        try { 
     79                                //context.putVariable(HttpServlet.class, "config", getServletConfig()); 
     80                                 
     81                                Pipeline pipeline = PipelineConfig.getPipelineForContext(context); 
     82                                 
     83                                if( pipeline != null ) { 
     84                                        pipeline.execute(context); 
     85                                } 
     86                                else { 
     87                                        throw new Exception("Unable to find a suitable rule for URL '"+context.getRequest().getRequestURL()+(context.getRequest().getQueryString() != null ? "?"+context.getRequest().getQueryString() : "")+"'"); 
     88                                } 
     89                                 
     90                                context.getResponse().send(); 
     91                        } 
     92                        catch( Throwable e ) { 
     93                                context.rollback(); 
     94                                 
     95                                StringBuilder msg = new StringBuilder(100); 
     96                                msg.append("Time: "+new Date()+"\n"); 
     97                                msg.append("URI: "+httpRequest.getRequestURI()+"\n"); 
     98                                msg.append("QUERY_STRING: "+httpRequest.getQueryString()+"\n"); 
     99                                msg.append("Session: "+httpRequest.getParameter("sess")+"\n"); 
     100                                msg.append("User: "+(context != null && context.getActiveUser() != null ? context.getActiveUser().getID() : "none")+"\n"); 
     101                                Common.mailThrowable(e, "Framework Exception", msg.toString()); 
     102                                 
     103                                e.printStackTrace(); 
     104                                httpResponse.setContentType("text/html"); 
     105                                PrintWriter writer = httpResponse.getWriter(); 
     106                                writer.append("<html><head><title>Drifting Souls Server Framework</title></head>"); 
     107                                writer.append("<body>"); 
     108                                writer.append("<table border=\"0\"><tr><td>\n"); 
     109                                writer.append("<div align=\"center\">\n"); 
     110                                writer.append("<h1>Drifting Souls Server Framework</h1>"); 
     111                                writer.append("Unhandled Exception "+e.getClass().getName()+" during pipeline execution detected<br />\n"); 
     112                                writer.append("Reason: "+e.getMessage()+"</div>\n"); 
     113                                writer.append("<hr style=\"height:1px; border:0px; background-color:#606060; color:#606060\" />"); 
     114                                StackTraceElement[] st = e.getStackTrace(); 
     115                                for( int i=0; i < st.length; i++ ) { 
     116                                        writer.append(st[i].toString()+"<br />\n"); 
     117                                } 
     118                                writer.append("</td></tr></table></body></html>"); 
     119                        } 
    70120                } 
    71121                finally { 
  • src/net/driftingsouls/ds2/server/framework/pipeline/HttpResponse.java

    r1d7d4ab r5a73c5c  
    142142                response.setHeader(name, value); 
    143143        } 
    144          
    145         /** 
    146          * Setzt den internen Status auf manuelles senden. 
    147          * In diesem Fall sendet das Objekt selbst keine Daten mehr. 
    148          * 
    149          */ 
     144 
    150145        public void setManualSendStatus() { 
    151146                this.manualSend = true; 
  • src/net/driftingsouls/ds2/server/framework/pipeline/Response.java

    r2d840b8 r5a73c5c  
    103103         */ 
    104104        public void send() throws IOException; 
     105 
     106        /** 
     107         * Setzt den internen Status auf manuelles senden. 
     108         * In diesem Fall sendet das Objekt selbst keine Daten mehr. 
     109         * 
     110         */ 
     111        public void setManualSendStatus(); 
    105112} 
  • src/net/driftingsouls/ds2/server/framework/pipeline/configuration/AbstractRule.java

    rb504c88 r5a73c5c  
    2828import net.driftingsouls.ds2.server.framework.pipeline.Pipeline; 
    2929import net.driftingsouls.ds2.server.framework.pipeline.ReaderPipeline; 
     30import net.driftingsouls.ds2.server.framework.pipeline.ServletPipeline; 
    3031import net.driftingsouls.ds2.server.framework.pipeline.actions.Action; 
    3132import net.driftingsouls.ds2.server.framework.pipeline.reader.Reader; 
     
    3536import org.w3c.dom.NodeList; 
    3637 
    37 abstract class AbstractRule implements Rule {            
    38         private static final int EXECUTE_MODULE = 0; 
    39         private static final int EXECUTE_READER = 1; 
     38// TODO: Behandlung Module, Reader und Servlet in eigene Klassen auslagern 
     39abstract class AbstractRule implements Rule { 
     40        private enum ExecMode { 
     41                /** 
     42                 * Ausfuehrungsmodus Modul 
     43                 */ 
     44                MODULE, 
     45                /** 
     46                 * Ausfuehrungsmodus Reader 
     47                 */ 
     48                READER, 
     49                /** 
     50                 * Ausfuehrungsmodus Servlet/Filterchain 
     51                 */ 
     52                SERVLET 
     53        } 
    4054         
    4155        private Node config = null; 
     
    5367        private Class<? extends Reader> readerClass = null; 
    5468         
    55         private int executionType = -1
     69        private ExecMode executionType = null
    5670         
    5771        private ParameterMap parameterMap = null; 
     
    8296                if( node != null ) { 
    8397                        setupReaderExecuter(node); 
     98                        return; 
     99                } 
     100                 
     101                node = XMLUtils.getNodeByXPath(matchNode, "execute-servlet"); 
     102                if( node != null ) { 
     103                        setupServletExecuter(node); 
    84104                        return; 
    85105                } 
     
    115135         
    116136        private void setupReaderExecuter(Node node) throws Exception { 
    117                 executionType = EXECUTE_READER; 
     137                executionType = ExecMode.READER; 
    118138 
    119139                readerClass = Class.forName(XMLUtils.getStringByXPath(node, "reader/@class")) 
     
    128148         
    129149        private void setupModuleExecuter(Node node) throws Exception { 
    130                 executionType = EXECUTE_MODULE; 
     150                executionType = ExecMode.MODULE; 
    131151 
    132152                parameter = new Parameter(node); 
    133153        } 
    134154         
    135         public boolean executeable(Context context) throws Exception{ 
     155        private void setupServletExecuter(Node node) throws Exception { 
     156                executionType = ExecMode.SERVLET; 
     157        } 
     158         
     159        public boolean executeable(Context context) throws Exception { 
    136160                if( actions.size() == 0 ) { 
    137161                        return true; 
     
    162186                Pipeline pipe = null; 
    163187                 
    164                 if( executionType == EXECUTE_MODULE ) { 
     188                switch( executionType ) { 
     189                case MODULE: 
    165190                        pipe = executeModule(context); 
    166                 } 
    167                 if( executionType == EXECUTE_READER ) { 
     191                        break; 
     192                         
     193                case READER: 
    168194                        pipe = executeReader(context); 
     195                        break; 
     196                         
     197                case SERVLET: 
     198                        pipe = executeServlet(context); 
     199                        break; 
    169200                } 
    170201                 
     
    190221                return new GeneratorPipeline( PipelineConfig.getModuleSettingByName(module).generator ); 
    191222        } 
     223         
     224        private Pipeline executeServlet(Context context) throws Exception { 
     225                return new ServletPipeline(); 
     226        } 
    192227} 
  • src/net/driftingsouls/ds2/server/framework/pipeline/configuration/MatchRule.java

    rb504c88 r5a73c5c  
    2929        private Pattern match = null; 
    3030         
    31         public MatchRule( Node matchNode ) throws Exception { 
     31        MatchRule( Node matchNode ) throws Exception { 
    3232                super(matchNode); 
    3333                match = Pattern.compile( XMLUtils.getStringByXPath(matchNode, "@pattern") ); 
  • src/net/driftingsouls/ds2/server/framework/pipeline/configuration/ModuleSetting.java

    rb504c88 r5a73c5c  
    2424        Class<? extends Generator> generator = null; 
    2525 
    26         public ModuleSetting(String generator) throws ClassNotFoundException { 
     26        ModuleSetting(String generator) throws ClassNotFoundException { 
    2727                if( (generator != null) && !"".equals(generator.trim()) ) { 
    2828                        this.generator = Class.forName(generator).asSubclass(Generator.class); 
  • src/net/driftingsouls/ds2/server/framework/pipeline/reader/WSDDReader.java

    rac6bde7 r5a73c5c  
    4343import net.driftingsouls.ds2.server.framework.Context; 
    4444import net.driftingsouls.ds2.server.framework.Loggable; 
    45 import net.driftingsouls.ds2.server.framework.pipeline.HttpResponse; 
    4645import net.driftingsouls.ds2.server.framework.pipeline.ReaderPipeline; 
     46import net.driftingsouls.ds2.server.framework.pipeline.Response; 
    4747import net.driftingsouls.ds2.server.framework.xml.XMLUtils; 
    4848 
     
    324324                readConfig(pipeline.getConfiguration()); 
    325325                 
    326                 ((HttpResponse)context.getResponse()).setManualSendStatus(); 
     326                context.getResponse().setManualSendStatus(); 
    327327 
    328328                HttpServletRequest req = (HttpServletRequest)context.getVariable(HttpServlet.class,