Package kilim.examples
Class HttpFileServer
- java.lang.Object
-
- kilim.Task
-
- kilim.nio.SessionTask
-
- kilim.http.HttpSession
-
- kilim.examples.HttpFileServer
-
- All Implemented Interfaces:
java.lang.Runnable,EventSubscriber,Fiber.Worker
public class HttpFileServer extends HttpSession
A simple file server over http Usage: Run java kilim.examples.HttpFileServer [base directory name] From a browser, go to "http://localhost:7262". A HttpFileServer object is a SessionTask, and is thus a thin wrapper over the socket connection. Its execute() method is called once on connection establishment. The HttpRequest and HttpResponse objects are wrappers over a bytebuffer, and unrelated to the socket. The request object is "filled in" by HttpSession.readRequest() and the response object is sent by HttpSession.sendResponse(). The rest of the code is related to the mechanics of file serving, common to Kilim and non-Kilim approaches alike. The objective of this example is merely to demonstrate Kilim API, not to have a fully functioning file server.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class kilim.http.HttpSession
HttpSession.StringRouter, HttpSession.StringSession
-
Nested classes/interfaces inherited from class kilim.Task
Task.Fork, Task.Invoke<TT>, Task.Spawn<TT>
-
-
Field Summary
Fields Modifier and Type Field Description static java.io.FilebaseDirectorystatic java.lang.StringbaseDirectoryNamestatic java.util.HashMap<java.lang.String,java.lang.String>mimeTypes-
Fields inherited from class kilim.nio.SessionTask
endpoint
-
Fields inherited from class kilim.Task
done, exitResult, fiber, id, pauseReason, running, scheduler, timer
-
-
Constructor Summary
Constructors Constructor Description HttpFileServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheck(HttpResponse resp, java.io.File file)voidexecute()private java.lang.StringgetRelPath(java.io.File file)static voidmain(java.lang.String[] args)static java.lang.StringmimeType(java.io.File file)voidproblem(java.io.File file, HttpResponse resp, byte[] statusCode, java.lang.String msg)voidsendDirectory(HttpResponse resp, java.io.File file, boolean headOnly)voidsendFile(HttpResponse resp, java.io.File file, boolean headOnly)private java.io.FileurlToPath(HttpRequest req)static voidusage()-
Methods inherited from class kilim.http.HttpSession
check, problem, readRequest, sendFile, sendResponse
-
Methods inherited from class kilim.nio.SessionTask
close
-
Methods inherited from class kilim.Task
checkKill, dump, equals, errNotWoven, errNotWoven, errorExit, errorExit, execute, exit, exit, fork, getCurrentTask, getExecutionThread, getPauseReason, getScheduler, getStackDepth, getState, getTid, hashCode, id, idledown, informOnExit, invoke, isDone, join, joinb, onEvent, pause, pause, pinToThread, prePin, resume, resumeOnScheduler, run, setPauseReason, setScheduler, setTid, shutdown, sleep, spawn, spawn, start, toString, unpinFromThread, yield, yield
-
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.io.IOException- Throws:
java.io.IOException
-
usage
public static void usage()
-
execute
public void execute() throws Pausable, java.lang.Exception- Specified by:
executein interfaceFiber.Worker- Overrides:
executein classTask- Throws:
Pausablejava.lang.Exception
-
urlToPath
private java.io.File urlToPath(HttpRequest req)
-
check
public boolean check(HttpResponse resp, java.io.File file) throws java.io.IOException, Pausable
- Throws:
java.io.IOExceptionPausable
-
sendFile
public void sendFile(HttpResponse resp, java.io.File file, boolean headOnly) throws java.io.IOException, Pausable
- Throws:
java.io.IOExceptionPausable
-
sendDirectory
public void sendDirectory(HttpResponse resp, java.io.File file, boolean headOnly) throws Pausable, java.io.IOException
- Throws:
Pausablejava.io.IOException
-
problem
public void problem(java.io.File file, HttpResponse resp, byte[] statusCode, java.lang.String msg) throws java.io.IOException, Pausable- Throws:
java.io.IOExceptionPausable
-
getRelPath
private java.lang.String getRelPath(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
mimeType
public static java.lang.String mimeType(java.io.File file)
-
-