Changeset 64
- Timestamp:
- 05/02/05 23:26:28 (4 years ago)
- Files:
-
- trunk/dsp/DSPGrammar.d (modified) (2 diffs)
- trunk/dsp/servlet/DSPServlet.d (modified) (2 diffs)
- trunk/dsp/servlet/ServletRegistry.d (modified) (1 diff)
- trunk/dspconf/config.xml (modified) (1 diff)
- trunk/dspconf/dsp02.dsp (modified) (1 diff)
- trunk/servertest.d (modified) (2 diffs)
- trunk/xml/dom/howto.txt (deleted)
- trunk/xml/dom/xmldom.idl (deleted)
- trunk/xml/dom/xmldom.idl,bak (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dsp/DSPGrammar.d
r53 r64 51 51 52 52 public static char[] pathToNamespace(char[] path){ 53 return replace(path,"\\",".");53 return path.replace("\\",".").replace("/","."); 54 54 } 55 55 … … 92 92 93 93 static this(){ 94 printf("servlet library init!\n");95 94 dsp.servlet.ServletRegistry.registerServletHandle(&` ~ servletFunctionName(name) ~ `,` ~ "`default`" ~ `); 96 95 }` ~ newline trunk/dsp/servlet/DSPServlet.d
r61 r64 28 28 private import misc.Library; 29 29 30 private import dsp.DSPException;31 32 30 private import dsp.servlet.DSPRequest; 33 31 private import dsp.servlet.IDSPRequest; 34 32 private import dsp.servlet.DSPResponse; 35 33 private import dsp.servlet.IDSPResponse; 34 private import dsp.servlet.DSPServletContext; 36 35 37 import mango.servlet.Servlet; 38 import mango.io.FilePath; 39 import mango.io.Uri; 40 import mango.log.Logger; 36 private import dsp.DSPException; 37 private import dsp.ServletCompiler; 38 private import dsp.RequestConfig; 39 40 private import mango.servlet.Servlet; 41 private import mango.io.FilePath; 42 private import mango.io.Uri; 43 private import mango.log.Logger; 44 45 private import std.string; 41 46 42 47 extern(C) alias void function(IDSPRequest request,IDSPResponse response) ServiceHandle; 43 48 44 49 class DSPServlet : Servlet{ 45 Library servletLibrary; 46 ServiceHandle handle; 50 Library[char[]] libs; 47 51 48 52 private static Logger logger; … … 51 55 logger = Logger.getLogger ("dsp.servlets"); 52 56 } 53 54 /* public this(Library servletLibrary){55 this.servletLibrary = servletLibrary;56 handle = cast(ServiceHandle)library.getSymbol("service");57 }58 57 59 public this(char[] libraryPath){60 servletLibrary = new Library(libraryPath);61 62 assert(servletLibrary.isLoaded());63 64 handle = cast(ServiceHandle)servletLibrary.getSymbol("service");65 assert(handle);66 }67 68 69 void service (IServletRequest request, IServletResponse response){70 char[] path = request.getServletPath();71 72 response.setContentType("text/html");73 74 IDSPRequest dspRequest = cast(IDSPRequest)request;75 IDSPResponse dspResponse = cast(IDSPResponse)response;76 77 assert(dspRequest);78 assert(dspResponse);79 80 handle(dspRequest,dspResponse);81 82 if(dspResponse.isExceptionSet){83 throw new DSPException("servlet: " ~ dspResponse.getException());84 }85 }86 */87 58 public this(){ 88 59 } 89 60 61 public ~this(){ 62 foreach(Library lib; libs){ 63 if(lib.isLoaded) lib.unload(); 64 } 65 } 66 67 Library getLibrary(DSPServletContext context,FilePath path){ 68 //TODO: make concurrent 69 70 Library lib = libs[path.toString()]; 71 72 //TODO: add check for file existence 73 //TODO: add check for library date and its validity vs the source file 74 if(!lib){ 75 RequestConfig cfg; 76 77 // configuration 78 79 cfg.pwd = context.getBasePath() ~ "\\"; 80 cfg.pwd = cfg.pwd.replace("/","\\"); 81 cfg.ext = path.getExtension(); 82 83 //HACK: filepath leaves prefixed '/' character on 84 cfg.name = path.getName()[1..$]; 85 86 cfg.modulePath = path.getPath(); 87 cfg.requestModule = cfg.modulePath ~ cfg.name; 88 cfg.dspSourceFilename = cfg.pwd ~ cfg.name ~ "." ~ cfg.ext; 89 90 cfg.tempDirectory = cfg.pwd ~ context.getConfiguration.get("temp-directory"); 91 cfg.cacheDirectory = cfg.pwd ~ context.getConfiguration.get("cache-directory"); 92 93 cfg.dSourceFilename = cfg.tempDirectory ~ cfg.name ~ ".d"; 94 cfg.destServletFilename = cfg.cacheDirectory ~ cfg.name ~ ".dll"; 95 96 cfg.runtimeDirectory = context.getConfiguration.get("runtime-directory"); 97 98 // debug 99 printf("%.*s\n",cfg.toString()); 100 101 // build the servlet library 102 ServletCompiler compiler = new ServletCompiler(); 103 compiler.CompileServlet(cfg); 104 105 // keep the library for later 106 lib = new Library(cfg.destServletFilename); 107 libs[path.toString()] = lib; 108 } 109 return lib; 110 } 111 90 112 void service (IServletRequest request, IServletResponse response){ 91 FilePath path = new FilePath(request.get Uri);113 FilePath path = new FilePath(request.getPathInfo); 92 114 93 115 if(path.getExtension == "dsp"){ 94 116 IDSPRequest dspRequest = cast(IDSPRequest)request; 95 117 IDSPResponse dspResponse = cast(IDSPResponse)response; 118 DSPServletContext context = cast(DSPServletContext)request.getContext(); 96 119 97 120 assert(dspRequest); 98 121 assert(dspResponse); 122 assert(context); 99 123 100 //TODO: bind to the needed dll on the fly 124 // bind to the needed dll on the fly 125 126 Library lib = getLibrary(context,path); 127 if(lib){ 128 ServiceHandle handle = cast(ServiceHandle)lib.getSymbol("service"); 101 129 102 dspResponse.getWriter.put("<h2>This is a test for DSP servlets</h2>"); 130 // run the service handle 131 if(handle){ 132 handle(dspRequest,dspResponse); 133 } 134 else{ 135 throw new DSPException("servlet library does not have a valid service handle"); 136 } 103 137 104 if(dspResponse.isExceptionSet){ 105 throw new DSPException("servlet: " ~ dspResponse.getException()); 138 dspResponse.getWriter.put("<h2>This is a test for DSP servlets</h2>"); 139 140 if(dspResponse.isExceptionSet){ 141 throw new DSPException("servlet: " ~ dspResponse.getException()); 142 } 143 } 144 else{ 145 throw new DSPException("could not load library"); 106 146 } 107 147 } 108 148 else{ 109 149 //TODO: use configuration and handling rules 110 //TODO: provide a listing if the file doesn't exist150 //TODO: provide a directory listing if the file doesn't exist 111 151 logger.info ("request for file: " ~ request.getUri.getPath ~ " (" ~ request.getPathInfo ~ ")"); 112 152 response.copyFile (request.getContext, request.getPathInfo); trunk/dsp/servlet/ServletRegistry.d
r54 r64 65 65 catch(Object o){ 66 66 response.setException("general exception: " ~ o.toString()); 67 } 67 } 68 68 } trunk/dspconf/config.xml
r61 r64 1 1 <?xml version="1.0"?> 2 2 <config> 3 <temp-directory value="_temp /"/>4 <cache-directory value="_cache /"/>5 <runtime-directory value=" ../runtime/"/>3 <temp-directory value="_temp\"/> 4 <cache-directory value="_cache\"/> 5 <runtime-directory value="c:\dev\dsp\trunk\runtime/"/> 6 6 <dmdopts></dmdopts> 7 7 </config> trunk/dspconf/dsp02.dsp
r57 r64 1 1 <?xml version="1.0" ?> 2 2 <?dsp 3 import mango.io.FileConduit; 4 5 FileConduit fc; 3 6 4 ?> 7 5 <html/> trunk/servertest.d
r61 r64 70 70 import dsp.servlet.DSPServletContext; 71 71 72 class FileServlet : MethodServlet73 {74 private static Logger logger;75 76 /***********************************************************************77 78 get a Logger for this class79 80 ***********************************************************************/81 82 static this ()83 {84 logger = Logger.getLogger ("mango.servlets.File");85 }86 87 /***********************************************************************88 89 support GET requests only! All other method requests will90 return an error to the user-agent91 92 ***********************************************************************/93 94 void doGet (IServletRequest request, IServletResponse response)95 {96 logger.info ("request for file: " ~ request.getUri.getPath ~ " (" ~ request.getPathInfo ~ ")");97 98 response.copyFile (request.getContext, request.getPathInfo);99 }100 }101 102 72 void testServer (IProvider provider) 103 73 { … … 131 101 132 102 // create a context for example dsp servlets 133 sp.addContext (new DSPServletContext (sp,"/dsp","c:/dev/dsp/trunk/dspconf")); 134 135 // point the default context to the same path 136 //sp.addContext (new ServletContext ("", "c:/dev/dsp/trunk/dspconf")); 137 138 // map all other requests to our file servlet 139 //sp.addMapping ("/", sp.addServlet (new FileServlet, "files")); 103 sp.addContext (new DSPServletContext (sp,"/foo/bar","c:/dev/dsp/trunk/dspconf")); 140 104 141 105 // fire up a server
