org.openuat.util.ip
Class PDAHTTPServer

java.lang.Object
  extended by org.openuat.util.ip.PDAHTTPServer

public class PDAHTTPServer
extends java.lang.Object

A simple, tiny, nicely embeddable HTTP 1.0 server in Java

NanoHTTPD version 1.05, Copyright © 2001,2005,2006 Jarno Elonen (elonen@iki.fi, http://iki.fi/elonen/)

Features & limitations:

Ways to use:

See the end of the source file for distribution license (Modified BSD licence) added features by Relate Project


Nested Class Summary
 class PDAHTTPServer.Response
          HTTP response.
 
Field Summary
static java.lang.String HTTP_BADREQUEST
          Some HTTP response status codes
static java.lang.String HTTP_FORBIDDEN
          Some HTTP response status codes
static java.lang.String HTTP_INTERNALERROR
          Some HTTP response status codes
static java.lang.String HTTP_NOTFOUND
          Some HTTP response status codes
static java.lang.String HTTP_NOTIMPLEMENTED
          Some HTTP response status codes
static java.lang.String HTTP_OK
          Some HTTP response status codes
static java.lang.String HTTP_REDIRECT
          Some HTTP response status codes
static java.lang.String MIME_DEFAULT_BINARY
          Common mime types for dynamic content
static java.lang.String MIME_HTML
          Common mime types for dynamic content
static java.lang.String MIME_PLAINTEXT
          Common mime types for dynamic content
 java.io.FileOutputStream OutputStream
           
 
Constructor Summary
PDAHTTPServer(int port, boolean deamon, java.net.InetAddress ia)
          Starts a HTTP server to given port.
 
Method Summary
 void addFileTransferListener(FileTransferListener l)
           
 void close()
          to shut down the server
static void main(java.lang.String[] args)
          Starts as a standalone file server and waits for Enter.
 void removeFileTransferListener(FileTransferListener l)
           
 PDAHTTPServer.Response serve(java.lang.String uri, java.lang.String method, java.util.Properties header, java.util.Properties parms)
          Override this to customize the server.
 PDAHTTPServer.Response serveFile(java.lang.String uri, java.util.Properties header, java.io.File homeDir, boolean allowDirectoryListing)
          Serves file from homeDir and its' subdirectories (only).
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_OK

public static final java.lang.String HTTP_OK
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_REDIRECT

public static final java.lang.String HTTP_REDIRECT
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_FORBIDDEN

public static final java.lang.String HTTP_FORBIDDEN
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_NOTFOUND

public static final java.lang.String HTTP_NOTFOUND
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_BADREQUEST

public static final java.lang.String HTTP_BADREQUEST
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_INTERNALERROR

public static final java.lang.String HTTP_INTERNALERROR
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_NOTIMPLEMENTED

public static final java.lang.String HTTP_NOTIMPLEMENTED
Some HTTP response status codes

See Also:
Constant Field Values

OutputStream

public java.io.FileOutputStream OutputStream

MIME_PLAINTEXT

public static final java.lang.String MIME_PLAINTEXT
Common mime types for dynamic content

See Also:
Constant Field Values

MIME_HTML

public static final java.lang.String MIME_HTML
Common mime types for dynamic content

See Also:
Constant Field Values

MIME_DEFAULT_BINARY

public static final java.lang.String MIME_DEFAULT_BINARY
Common mime types for dynamic content

See Also:
Constant Field Values
Constructor Detail

PDAHTTPServer

public PDAHTTPServer(int port,
                     boolean deamon,
                     java.net.InetAddress ia)
              throws java.io.IOException
Starts a HTTP server to given port.

Throws an IOException if the socket is already in use

Throws:
java.io.IOException
Method Detail

addFileTransferListener

public void addFileTransferListener(FileTransferListener l)

removeFileTransferListener

public void removeFileTransferListener(FileTransferListener l)

serve

public PDAHTTPServer.Response serve(java.lang.String uri,
                                    java.lang.String method,
                                    java.util.Properties header,
                                    java.util.Properties parms)
Override this to customize the server.

(By default, this delegates to serveFile() and allows directory listing.)

Parameters:
uri - Percent-decoded URI without parameters, for example "/index.cgi"
method - "GET", "POST" etc.
parms - Parsed, percent decoded parameters from URI and, in case of POST, data.
header - Header entries, percent decoded
Returns:
HTTP response, see class Response for details

stop

public void stop()

main

public static void main(java.lang.String[] args)
Starts as a standalone file server and waits for Enter.


serveFile

public PDAHTTPServer.Response serveFile(java.lang.String uri,
                                        java.util.Properties header,
                                        java.io.File homeDir,
                                        boolean allowDirectoryListing)
Serves file from homeDir and its' subdirectories (only). Uses only URI, ignores all headers and HTTP parameters.


close

public void close()
to shut down the server



2005-2006, Rene Mayrhofer.