An example Http implementation is provided in the demo section. It is a very basic implementation. It has minimal security (ie none). It has the ability to retrieve files from the file system as well as carry out server side logic processing.
Back to top
Go to the demo/httpServer directory that is inside the dist directory. The following scripts can be run to start the server.
For Windows execute:
demo/httpServer/run.bat
For Linux/Mac OS execute: demo/httpServer/run.sh
Raindrop will create a very small, lightweight, embedded Web Server running on port 8080.
Once the appropriate script has been executed, the Server will be available from http://localhost:8080 and will export any files under that directory. For example http://localhost:8080/img/fred.jpg will return the an image called fred.jpg in the img directory.
In addition a time service is available by calling http://localhost:8080/date and calling http://localhost:8080/headers will return a list of the headers that were passed in via the browser..
Back to top
The following URL handlers are available.
- /date
- Provides the current System time as a formatted text string and Unix epoch.
- /headers
- Returns the header values sent to the Web Server from the browser.
Back to top
The raindrop configuration file is available from:
dist/demo/httpServer/raindrop.xml
The following Handlers are used within the Http Server:
- com.ewansilver.raindrop.demo.httpserver.HttpRequestHandler
- Initialises the Web Server and sets the port and host that the server listens on and then parses all inbound Http Requests.
It passes fully formed Http Requests onto the named "delivery" TaskQueue
-
"port" : the port that the server listens on.
-
"host" : the hostname of the server socket that the server binds to.
-
"delivery" : the TaskQueue that fully formed HttpRequests will be delivered to.
- com.ewansilver.raindrop.demo.httpserver.StaticFileHandler
- Receives HttpConnection requests that relate to files on the file system.
It retrieves those files and then sends them onto the dispatcher.
The StaticFileHandler also attempts to set the correct mimetype based on file prefix.
-
"webroot" : the location of the web root directory that static files will be served from.
By default it the directory containing the start scripts and raindrop.xml configuration file.
- com.ewansilver.raindrop.demo.httpserver.HeadersHandler
- Handles the /headers requests.
- com.ewansilver.raindrop.demo.httpserver.DateHandler
- Handles the /date requests. Gets the current system time and returns that to the caller.
- com.ewansilver.raindrop.demo.httpserver.UrlDispatcher
- Receives HttpConnection requests from the HttpRequestHandler and routes them to the appropriate handler.
It is currently configured to route /date and /headers. Any other request is considered to be a file request and is sent to the StaticFileHandler.
- com.ewansilver.raindrop.demo.httpserver.FileWriter
- A test handler for writing data to the file system.
- com.ewansilver.raindrop.fileio.FileHandler
- The standard Raindrop file handler that is responsible for retrieving files from the file system.
Back to top
|