Application: JFast
JFast is a replacement library for the Java portion of the FastCGI DevKit. The DevKit does not support multi-threaded FastCGI Java applications, but JFast does. JFast is also a much cleaner collection of code, and is therefor a great deal easier to develop further.
JFast is not a full-featured library. It supports only the basic Responder
role, and it does not support multiplexed connection (does any web server, either?). If there is a feature in the FastCGI specification that JFast does not support, that you need, let me know.
Documentation
Javadoc to come.
JFast is very straightforward. After creating a singleJFast
object, you can call the acceptRequest
method to access data (a JFastRequest
object) connected the request. The JFastRequest
object can be passed to a separate thread for processing, and your primary thread can continue to accept new connections.
The JFast
constructor can be passed a single int
parameter, which represents the port number that a Web Server such as lighttpd can use to communicate with the application. If this parameter is left out, the FCGI_PORT
variable must be set in the program’s environment.
The following fields/methods of JFastRequest
are of interest:
JFastRequest.out
: aPrintStream
that allows you to send character data to the client.JFastRequest.error
: aPrintStream
that allows you to send character data to the webserver as logging information.JFastRequest.properties
: aProperties
object, containing standard CGI key/value pairs.JFastRequest.data
: any available POST data that’s associated with the current request.
Example
The following example is a complete (if slightly useless) FastCGI program.
import org.bumblescript.jfast.*; public class JFTest { public static void main(String args[]) throws Exception { JFast jfast = new JFast(); JFastRequest request; while((request = jfast.acceptRequest()) != null) { request.out.print("Content-type: text/html\n\n"); request.out.print( "<html>" + "<head><title>JFast Example</title></head>" + "<body>" + "<h1>Hello, FastCGI!</h1>" + "<h2>Environment</h2>" + "<pre>" ); request.properties.list(request.out); request.out.print( "</pre>" + "<h2>Post Data</h2>" + "<pre>" + (new String(request.data)) + "</pre>" + "</body>" + "</html>" ); request.end(); } } }