comparison web/src/luan/modules/web/LuanServlet.java @ 467:f86bf532f87c

improve LuanServlet to allow for URL mapping
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 08 May 2015 12:10:53 -0600
parents 8f1be9704726
children
comparison
equal deleted inserted replaced
466:55a86fc4701b 467:f86bf532f87c
20 20
21 public LuanServlet(String uriPrefix) { 21 public LuanServlet(String uriPrefix) {
22 this(uriPrefix,LuanState.newInstance()); 22 this(uriPrefix,LuanState.newInstance());
23 } 23 }
24 24
25 protected void service(HttpServletRequest request,HttpServletResponse response) 25 @Override protected void service(HttpServletRequest request,HttpServletResponse response)
26 throws IOException 26 throws IOException
27 { 27 {
28 String path = request.getRequestURI(); 28 String path = request.getRequestURI();
29 service(request,response,path);
30 }
31
32 public void service(HttpServletRequest request,HttpServletResponse response,String path)
33 throws IOException
34 {
29 if( !path.endsWith(".luan") ) 35 if( !path.endsWith(".luan") )
30 throw new RuntimeException("'"+path+"' doesn't end with '.luan'"); 36 throw new RuntimeException("'"+path+"' doesn't end with '.luan'");
31 String uri = uriPrefix + path.substring(0,path.length()-5); 37 String uri = uriPrefix + path.substring(0,path.length()-5);
32 //System.out.println("qqqqqqqqqqqqqqqqqqq "+uri);
33 try { 38 try {
34 if( !HttpServicer.service(luan,request,response,uri) ) 39 if( !HttpServicer.service(luan,request,response,uri) )
35 response.sendError(HttpServletResponse.SC_NOT_FOUND); 40 response.sendError(HttpServletResponse.SC_NOT_FOUND);
36 } catch(LuanException e) { 41 } catch(LuanException e) {
37 throw new RuntimeException(e); 42 throw new RuntimeException(e);