Mercurial Hosting > luan
changeset 399:199eb7f1b828
add LuanServlet
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 27 Apr 2015 16:59:35 -0600 |
parents | 39c4ac11a58a |
children | 8f1be9704726 |
files | web/src/luan/modules/web/LuanServlet.java web/src/luan/modules/web/shell.luan |
diffstat | 2 files changed, 42 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
diff -r 39c4ac11a58a -r 199eb7f1b828 web/src/luan/modules/web/LuanServlet.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/src/luan/modules/web/LuanServlet.java Mon Apr 27 16:59:35 2015 -0600 @@ -0,0 +1,41 @@ +package luan.modules.web; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import luan.LuanState; +import luan.LuanException; + + +public class LuanServlet extends HttpServlet { + protected final String uriPrefix; + protected final LuanState luan; + + public LuanServlet(String uriPrefix,LuanState luan) { + this.uriPrefix = uriPrefix; + this.luan = luan; + } + + public LuanServlet(String uriPrefix) { + this(uriPrefix,LuanState.newStandard()); + } + + protected void service(HttpServletRequest request,HttpServletResponse response) + throws IOException + { + String path = request.getRequestURI(); + if( !path.endsWith(".luan") ) + throw new RuntimeException("'"+path+"' doesn't end with '.luan'"); + String uri = uriPrefix + path.substring(0,path.length()-5); +//System.out.println("qqqqqqqqqqqqqqqqqqq "+uri); + try { + if( !HttpServicer.service(luan,request,response,uri) ) + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } catch(LuanException e) { + throw new RuntimeException(e); + } + } + +}
diff -r 39c4ac11a58a -r 199eb7f1b828 web/src/luan/modules/web/shell.luan --- a/web/src/luan/modules/web/shell.luan Mon Apr 27 12:44:53 2015 -0600 +++ b/web/src/luan/modules/web/shell.luan Mon Apr 27 16:59:35 2015 -0600 @@ -11,7 +11,7 @@ per_session = true local history = {} -local env = {} +env = {} function service() if Http.request.parameters.clear ~= nil then