Mercurial Hosting > luan
comparison web/src/luan/modules/web/HttpLuan.java @ 175:bdbd4740121f
finish web server
git-svn-id: https://luan-java.googlecode.com/svn/trunk@176 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 23 Jun 2014 07:48:17 +0000 |
parents | 58c6ca5d4524 |
children | 2c08e7e27a70 |
comparison
equal
deleted
inserted
replaced
174:609c5b3118db | 175:bdbd4740121f |
---|---|
26 | 26 |
27 public final class HttpLuan { | 27 public final class HttpLuan { |
28 | 28 |
29 public static final LuanFunction LOADER = new LuanFunction() { | 29 public static final LuanFunction LOADER = new LuanFunction() { |
30 @Override public Object call(LuanState luan,Object[] args) { | 30 @Override public Object call(LuanState luan,Object[] args) { |
31 return new LuanTable(); // starts empty | 31 LuanTable module = new LuanTable(); |
32 try { | |
33 addStatic( module, "new_luan_handler", LuanState.class ); | |
34 } catch(NoSuchMethodException e) { | |
35 throw new RuntimeException(e); | |
36 } | |
37 return module; | |
32 } | 38 } |
33 }; | 39 }; |
34 | 40 |
35 public static void service(LuanState luan,HttpServletRequest request,HttpServletResponse response,String modName) | 41 private static void addStatic(LuanTable t,String method,Class<?>... parameterTypes) throws NoSuchMethodException { |
42 t.put( method, new LuanJavaFunction(HttpLuan.class.getMethod(method,parameterTypes),null) ); | |
43 } | |
44 | |
45 public static LuanHandler new_luan_handler(LuanState luan) { | |
46 return new LuanHandler(luan); | |
47 } | |
48 | |
49 public static boolean service(LuanState luan,HttpServletRequest request,HttpServletResponse response,String modName) | |
36 throws LuanException | 50 throws LuanException |
37 { | 51 { |
38 LuanFunction fn; | 52 LuanFunction fn; |
39 synchronized(luan) { | 53 synchronized(luan) { |
40 Object mod = PackageLuan.require(luan,modName); | 54 Object mod = PackageLuan.load(luan,modName); |
55 if( mod==null ) | |
56 return false; | |
41 if( !(mod instanceof LuanTable) ) | 57 if( !(mod instanceof LuanTable) ) |
42 throw luan.exception( "module '"+modName+"' must return a table" ); | 58 throw luan.exception( "module '"+modName+"' must return a table" ); |
43 LuanTable tbl = (LuanTable)mod; | 59 LuanTable tbl = (LuanTable)mod; |
44 if( Luan.toBoolean( tbl.get("per_session") ) ) { | 60 if( Luan.toBoolean( tbl.get("per_session") ) ) { |
45 HttpSession session = request.getSession(); | 61 HttpSession session = request.getSession(); |
61 luan = cloner.deepClone(luan); | 77 luan = cloner.deepClone(luan); |
62 fn = cloner.get(fn); | 78 fn = cloner.get(fn); |
63 } | 79 } |
64 } | 80 } |
65 | 81 |
66 LuanTable module = (LuanTable)luan.loaded().get("web.Http"); | 82 LuanTable module = (LuanTable)luan.loaded().get("web/Http"); |
67 if( module == null ) | 83 if( module == null ) |
68 throw luan.exception( "module 'web.Http' not defined" ); | 84 throw luan.exception( "module 'web/Http' not defined" ); |
69 HttpLuan lib = new HttpLuan(request,response); | 85 HttpLuan lib = new HttpLuan(request,response); |
70 try { | 86 try { |
71 module.put( "request", lib.requestTable() ); | 87 module.put( "request", lib.requestTable() ); |
72 module.put( "response", lib.responseTable() ); | 88 module.put( "response", lib.responseTable() ); |
73 /* | 89 /* |
78 } catch(NoSuchMethodException e) { | 94 } catch(NoSuchMethodException e) { |
79 throw new RuntimeException(e); | 95 throw new RuntimeException(e); |
80 } | 96 } |
81 | 97 |
82 luan.call(fn,"<http>"); | 98 luan.call(fn,"<http>"); |
99 return true; | |
83 } | 100 } |
84 | 101 |
85 | 102 |
86 | 103 |
87 private final HttpServletRequest request; | 104 private final HttpServletRequest request; |