Mercurial Hosting > luan
comparison web/src/luan/modules/web/LuanServlet.java @ 399:199eb7f1b828
add LuanServlet
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 27 Apr 2015 16:59:35 -0600 |
parents | |
children | 8f1be9704726 |
comparison
equal
deleted
inserted
replaced
398:39c4ac11a58a | 399:199eb7f1b828 |
---|---|
1 package luan.modules.web; | |
2 | |
3 import java.io.IOException; | |
4 import javax.servlet.ServletException; | |
5 import javax.servlet.http.HttpServlet; | |
6 import javax.servlet.http.HttpServletRequest; | |
7 import javax.servlet.http.HttpServletResponse; | |
8 import luan.LuanState; | |
9 import luan.LuanException; | |
10 | |
11 | |
12 public class LuanServlet extends HttpServlet { | |
13 protected final String uriPrefix; | |
14 protected final LuanState luan; | |
15 | |
16 public LuanServlet(String uriPrefix,LuanState luan) { | |
17 this.uriPrefix = uriPrefix; | |
18 this.luan = luan; | |
19 } | |
20 | |
21 public LuanServlet(String uriPrefix) { | |
22 this(uriPrefix,LuanState.newStandard()); | |
23 } | |
24 | |
25 protected void service(HttpServletRequest request,HttpServletResponse response) | |
26 throws IOException | |
27 { | |
28 String path = request.getRequestURI(); | |
29 if( !path.endsWith(".luan") ) | |
30 throw new RuntimeException("'"+path+"' doesn't end with '.luan'"); | |
31 String uri = uriPrefix + path.substring(0,path.length()-5); | |
32 //System.out.println("qqqqqqqqqqqqqqqqqqq "+uri); | |
33 try { | |
34 if( !HttpServicer.service(luan,request,response,uri) ) | |
35 response.sendError(HttpServletResponse.SC_NOT_FOUND); | |
36 } catch(LuanException e) { | |
37 throw new RuntimeException(e); | |
38 } | |
39 } | |
40 | |
41 } |