Mercurial Hosting > luan
comparison src/luan/modules/http/HttpServicer.java @ 1256:c147e2e877e3
allow subclassing of HttpServicer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 19 Sep 2018 20:15:16 -0600 |
parents | 354e661dee7f |
children | 382c444a6c77 |
comparison
equal
deleted
inserted
replaced
1255:4f571a974132 | 1256:c147e2e877e3 |
---|---|
2 | 2 |
3 import org.slf4j.Logger; | 3 import org.slf4j.Logger; |
4 import org.slf4j.LoggerFactory; | 4 import org.slf4j.LoggerFactory; |
5 import luan.webserver.Request; | 5 import luan.webserver.Request; |
6 import luan.webserver.Response; | 6 import luan.webserver.Response; |
7 import luan.webserver.Status; | |
7 import luan.LuanState; | 8 import luan.LuanState; |
8 import luan.LuanFunction; | 9 import luan.LuanFunction; |
9 import luan.LuanException; | 10 import luan.LuanException; |
10 import luan.LuanTable; | 11 import luan.LuanTable; |
11 import luan.LuanCloner; | 12 import luan.LuanCloner; |
12 import luan.modules.PackageLuan; | 13 import luan.modules.PackageLuan; |
13 | 14 |
14 | 15 |
15 public final class HttpServicer { | 16 public class HttpServicer { |
16 private static final Logger logger = LoggerFactory.getLogger(HttpServicer.class); | 17 private static final Logger logger = LoggerFactory.getLogger(HttpServicer.class); |
17 | 18 |
18 public static Response service(LuanState luan,Request request,String modName) | 19 public Response service(LuanState luan,Request request,String modName) { |
20 try { | |
21 return serviceLuan(luan,request,modName); | |
22 } catch(LuanException e) { | |
23 return handleError(request,e); | |
24 } | |
25 } | |
26 | |
27 protected Response handleError(Request request,LuanException e) { | |
28 //e.printStackTrace(); | |
29 String err = e.getLuanStackTraceString(); | |
30 logger.error(err+"\n"+request.rawHead.trim()+"\n"); | |
31 String msg = "Internel Server Error\n\n" + err; | |
32 return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg ); | |
33 } | |
34 | |
35 protected Response serviceLuan(LuanState luan,Request request,String modName) | |
19 throws LuanException | 36 throws LuanException |
20 { | 37 { |
21 LuanFunction fn; | 38 LuanFunction fn; |
22 synchronized(luan) { | 39 synchronized(luan) { |
40 inSinchronized(luan,request); | |
23 PackageLuan.enableLoad(luan,"luan:http/Http.luan",modName); | 41 PackageLuan.enableLoad(luan,"luan:http/Http.luan",modName); |
24 PackageLuan.require(luan,"luan:http/Http.luan"); | 42 PackageLuan.require(luan,"luan:http/Http.luan"); |
25 Object mod = PackageLuan.load(luan,modName); | 43 Object mod = PackageLuan.load(luan,modName); |
26 if( mod.equals(Boolean.FALSE) ) | 44 if( mod.equals(Boolean.FALSE) ) |
27 return null; | 45 return null; |
47 LuanFunction finishFn = (LuanFunction)module.rawGet("finish"); | 65 LuanFunction finishFn = (LuanFunction)module.rawGet("finish"); |
48 Response response = (Response)finishFn.call(luan); | 66 Response response = (Response)finishFn.call(luan); |
49 return response; | 67 return response; |
50 } | 68 } |
51 | 69 |
70 protected void inSinchronized(LuanState luan,Request request) | |
71 throws LuanException | |
72 {} | |
73 | |
52 } | 74 } |