changeset 377:a8d03e6882c6

add web/NotFound.java
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 19 Apr 2015 07:27:23 -0600
parents 0a75ed73bccc
children bf60da9298f5
files web/src/luan/modules/web/Http.luan web/src/luan/modules/web/HttpServicer.java web/src/luan/modules/web/LuanHandler.java web/src/luan/modules/web/NotFound.java web/src/luan/modules/web/Server.luan
diffstat 5 files changed, 38 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
diff -r 0a75ed73bccc -r a8d03e6882c6 web/src/luan/modules/web/Http.luan
--- a/web/src/luan/modules/web/Http.luan	Sat Apr 18 19:57:42 2015 -0600
+++ b/web/src/luan/modules/web/Http.luan	Sun Apr 19 07:27:23 2015 -0600
@@ -1,16 +1,10 @@
-java()
 local Luan = require "luan:Luan"
 local ipairs = Luan.ipairs
 local to_string = Luan.to_string
 local Table = require "luan:Table"
 require "luan:logging/Logging"  -- initialize logging
-local LuanHandler = require "java:luan.modules.web.LuanHandler"
 
 
-function new_luan_handler()
-	return LuanHandler.new()
-end
-
 
 
 function init_for_test()
diff -r 0a75ed73bccc -r a8d03e6882c6 web/src/luan/modules/web/HttpServicer.java
--- a/web/src/luan/modules/web/HttpServicer.java	Sat Apr 18 19:57:42 2015 -0600
+++ b/web/src/luan/modules/web/HttpServicer.java	Sun Apr 19 07:27:23 2015 -0600
@@ -318,6 +318,18 @@
 		add( tbl, "text_writer" );
 		add( tbl, "set_cookie", String.class, String.class, Boolean.TYPE, String.class );
 		add( tbl, "remove_cookie", String.class, String.class );
+		tbl.put( "status", new LuanProperty() {
+			@Override public Object get() {
+				return response.getStatus();
+			}
+			@Override public boolean set(Object value) {
+				Integer i = Luan.asInteger(value);
+				if( i==null )
+					throw new IllegalArgumentException("value must be an integer");
+				response.setStatus(i);
+				return true;
+			}
+		} );
 		return tbl;
 	}
 
diff -r 0a75ed73bccc -r a8d03e6882c6 web/src/luan/modules/web/LuanHandler.java
--- a/web/src/luan/modules/web/LuanHandler.java	Sat Apr 18 19:57:42 2015 -0600
+++ b/web/src/luan/modules/web/LuanHandler.java	Sun Apr 19 07:27:23 2015 -0600
@@ -30,7 +30,6 @@
 		try {
 			if( !HttpServicer.service(luan,request,response,"site:"+target) )
 				return;
-			response.setStatus(HttpServletResponse.SC_OK);
 		} catch(LuanException e) {
 			String err = e.getFullMessage();
 			logger.error(err);
diff -r 0a75ed73bccc -r a8d03e6882c6 web/src/luan/modules/web/NotFound.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/src/luan/modules/web/NotFound.java	Sun Apr 19 07:27:23 2015 -0600
@@ -0,0 +1,22 @@
+package luan.modules.web;
+
+import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jetty.server.Request;
+import luan.LuanState;
+
+
+public class NotFound extends LuanHandler {
+
+	public NotFound(LuanState luan) {
+		super(luan);
+	}
+
+	public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response) 
+		throws IOException
+	{
+		super.handle("/not_found",baseRequest,request,response);
+	}
+
+}
diff -r 0a75ed73bccc -r a8d03e6882c6 web/src/luan/modules/web/Server.luan
--- a/web/src/luan/modules/web/Server.luan	Sat Apr 18 19:57:42 2015 -0600
+++ b/web/src/luan/modules/web/Server.luan	Sun Apr 19 07:27:23 2015 -0600
@@ -16,6 +16,8 @@
 local HandlerWrapper = require "java:org.eclipse.jetty.server.handler.HandlerWrapper"
 local SessionHandler = require "java:org.eclipse.jetty.server.session.SessionHandler"
 local AuthenticationHandler = require "java:luan.modules.web.AuthenticationHandler"
+local LuanHandler = require "java:luan.modules.web.LuanHandler"
+local NotFound = require "java:luan.modules.web.NotFound"
 
 
 port = 8080
@@ -27,7 +29,7 @@
 
 authentication_handler = AuthenticationHandler.new("/private/")
 
-luan_handler = Http.new_luan_handler()
+luan_handler = LuanHandler.new()
 
 resource_handler = ResourceHandler.new()
 resource_handler.setDirectoriesListed(true)
@@ -81,6 +83,7 @@
 	resource_handler.setResourceBase(Io.Uri(base).to_string())
 	resource_handler.setWelcomeFiles {welcome_file}
 	luan_handler.setWelcomeFile(welcome_file)
+	handlers.addHandler(NotFound.new())
 	server = Server.new(port)
 	server.setHandler(hc)
 	Package.load("site:/init")