Menu

Tree [ca7a1f] master /
 History

HTTPS access


File Date Author Commit
 META-INF 2010-03-21 Viktor Nordell Viktor Nordell [21b41d] * Fixed a bug if a requests path ends with argu...
 docs 2009-08-26 Viktor Nordell Viktor Nordell [2cfd9c] Change docs and web for the new release
 html 2012-08-06 Viktor Nordell Viktor Nordell [ca7a1f] * Fix issues with handling of double-quotes
 jars 2009-08-25 Viktor Nordell Viktor Nordell [c59f41] Added the new jar for the new release
 libs 2009-08-01 Viktor Nordell Viktor Nordell [31b9ca] Added libs and compiled jar files
 resources 2009-08-01 Viktor Nordell Viktor Nordell [63fe3c] Inital import
 src 2012-08-06 Viktor Nordell Viktor Nordell [ca7a1f] * Fix issues with handling of double-quotes
 webroot 2012-08-06 Viktor Nordell Viktor Nordell [ca7a1f] * Fix issues with handling of double-quotes
 ChangeLog 2010-03-21 Viktor Nordell Viktor Nordell [622837] Fixed some minor stuff for the 0.7.0 release, i...
 LICENSE 2009-08-01 Viktor Nordell Viktor Nordell [377482] Added misc files...
 README 2010-03-21 Viktor Nordell Viktor Nordell [622837] Fixed some minor stuff for the 0.7.0 release, i...
 build.xml 2010-03-21 Viktor Nordell Viktor Nordell [622837] Fixed some minor stuff for the 0.7.0 release, i...
 mime.types 2010-03-21 Viktor Nordell Viktor Nordell [aa3ae0] Added missing files to git.

Read Me

--- How to run ---
Simply run the following command:
java -jar jars/json-httpd.jar

And the server will start at port 8080. The server will use the folder
"webroot" in the servers working directory. Both port and web root can
be configured via options, see "java -jar jars/json-httpd.jar --help".

--- How to use as a library ---
Example use: (Check docs for more info)

try {
	httpd = new HTTPServer(8080, 20);		// Start server at port 8080.
	httpd.addService(new ExampleService()); 	// Add an service.
	httpd.start();					// Start the server
} catch (IOException e) {
	System.out.println("Failed to start the server");
}

--- How to write a service ---

1. Create a class.
2. Create a method that takes arguments of type String, int, long, float 
   or doble, return value should be a JSON formated string.
3. Add the @JsonServiceMethod annotation to the method.
4. Write the code and generate a JSON formated return value 
   with the JSONWriter class. (For more info about JSONWriter check
   http://www.stringtree.org/stringtree-json.html).

--- How to write a custom handler ---

A custom handler is a method that takes a request and send a response to that 
request.

1. Create a class with implements CustomHandler
2. Implement the method "getPath", this is the path for which the handler will
   handle request on. For exampel "/test/".
3. Implement the method handle, it takes a HTTPRequest and a OutputStream.
   The HTTPRequest contains the request parameters (for example path).
   The OutputStream is used to send data back to the client.
   To create a response header you can use the method HTTPResponseBuilder.buildResponse
   which takes the HTTPRequest object and a HTTPPayload object. In the HTTPPayload object
   you can set the content type and the HTTP Status for example. Look in TestHandler.java
   for an example.