com.bigdata.util.httpd
Class NanoHTTPD

java.lang.Object
  extended by com.bigdata.util.httpd.NanoHTTPD
All Implemented Interfaces:
IServiceShutdown
Direct Known Subclasses:
AbstractHTTPD

Deprecated. This is being replaced by the use of the Servlet API and embedded use of jetty as a light weight servlet container.

public class NanoHTTPD
extends Object
implements IServiceShutdown

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

NanoHTTPD version 1.1, Copyright © 2001,2005-2007 Jarno Elonen (elonen@iki.fi, http://iki.fi/elonen/)

Various modifications since supporting integration within bigdata services © 2008, SYSTAP, LLC.

Features + limitations:

Ways to use:

License (Modified BSD license)

 Copyright (C) 2001,2005 by Jarno Elonen 
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 
 Redistributions of source code must retain the above copyright notice,
 this list of conditions and the following disclaimer. Redistributions in
 binary form must reproduce the above copyright notice, this list of
 conditions and the following disclaimer in the documentation and/or other
 materials provided with the distribution. The name of the author may not
 be used to endorse or promote products derived from this software without
 specific prior written permission. 
  
 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 

Version:
$Id: NanoHTTPD.java 4702 2011-06-13 16:25:38Z thompsonbry $

Nested Class Summary
static class NanoHTTPD.Request
          Deprecated. A http request.
static class NanoHTTPD.Response
          Deprecated. HTTP response.
 
Nested classes/interfaces inherited from interface com.bigdata.service.IServiceShutdown
IServiceShutdown.Options
 
Field Summary
static String CONTENT_LENGTH
          Deprecated.  
static String CONTENT_TYPE
          Deprecated.  
static String DATE
          Deprecated.  
static String DELETE
          Deprecated.  
protected static String ERR_BAD_REQUEST
          Deprecated.  
static String GET
          Deprecated.  
static String HTTP_BADREQUEST
          Deprecated. Some HTTP response status codes
static String HTTP_FORBIDDEN
          Deprecated. Some HTTP response status codes
static String HTTP_INTERNALERROR
          Deprecated. Some HTTP response status codes
static String HTTP_METHOD_NOT_ALLOWED
          Deprecated. Some HTTP response status codes
static String HTTP_NOTFOUND
          Deprecated. Some HTTP response status codes
static String HTTP_NOTIMPLEMENTED
          Deprecated. Some HTTP response status codes
static String HTTP_OK
          Deprecated. Some HTTP response status codes
static String HTTP_REDIRECT
          Deprecated. Some HTTP response status codes
static String httpDefaultCharacterEncoding
          Deprecated. The name of the default character set encoding for HTTP which is ISO-8859-1.
static String MIME_APPLICATION_URL_ENCODED
          Deprecated. Common mime types for dynamic content
static String MIME_APPLICATION_XML
          Deprecated. Common mime types for dynamic content
static String MIME_DEFAULT_BINARY
          Deprecated. Common mime types for dynamic content
static String MIME_TEXT_HTML
          Deprecated. Common mime types for dynamic content
static String MIME_TEXT_JAVASCRIPT
          Deprecated. Common mime types for dynamic content
static String MIME_TEXT_PLAIN
          Deprecated. Common mime types for dynamic content
static String POST
          Deprecated.  
static String PUT
          Deprecated.  
static String UTF8
          Deprecated. UTF-8
 
Constructor Summary
NanoHTTPD(int port)
          Deprecated. Starts a HTTP server to given port.
 
Method Summary
static LinkedHashMap<String,Vector<String>> decodeParams(String parms, LinkedHashMap<String,Vector<String>> p)
          Deprecated. Decodes parameters in percent-encoded URI-format ( e.g.
static StringBuilder encodeParams(LinkedHashMap<String,Vector<String>> expected)
          Deprecated. Construct a percent encoded representation of the URL query parameters.
 int getPort()
          Deprecated. The port on which the service was started.
 boolean isOpen()
          Deprecated. Return true iff the service is running.
static void main(String[] args)
          Deprecated. Starts as a standalone file server and waits for Enter.
protected  NanoHTTPD.Response serve(NanoHTTPD.Request req)
          Deprecated. Override this to customize the server.
protected  NanoHTTPD.Response serveFile(String uri, Map<String,String> header, File homeDir, boolean allowDirectoryListing)
          Deprecated. Serves file from homeDir and its' subdirectories (only).
 void shutdown()
          Deprecated. The service will no longer accept new requests, but existing requests will be processed (sychronous).
 void shutdownNow()
          Deprecated. The service will no longer accept new requests and will make a best effort attempt to terminate all existing requests and return ASAP.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8

public static final String UTF8
Deprecated. 
UTF-8

See Also:
Constant Field Values

GET

public static final String GET
Deprecated. 
See Also:
Constant Field Values

PUT

public static final String PUT
Deprecated. 
See Also:
Constant Field Values

POST

public static final String POST
Deprecated. 
See Also:
Constant Field Values

DELETE

public static final String DELETE
Deprecated. 
See Also:
Constant Field Values

ERR_BAD_REQUEST

protected static final String ERR_BAD_REQUEST
Deprecated. 
See Also:
Constant Field Values

CONTENT_LENGTH

public static final String CONTENT_LENGTH
Deprecated. 
See Also:
Constant Field Values

CONTENT_TYPE

public static final String CONTENT_TYPE
Deprecated. 
See Also:
Constant Field Values

DATE

public static final String DATE
Deprecated. 
See Also:
Constant Field Values

httpDefaultCharacterEncoding

public static final String httpDefaultCharacterEncoding
Deprecated. 
The name of the default character set encoding for HTTP which is ISO-8859-1. The character set of an HTTP entity is indicated by the charset parameter on the HTTP Content-Type header. This default MUST be applied when the charset parameter is not specified.

See Also:
Constant Field Values

HTTP_OK

public static final String HTTP_OK
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_REDIRECT

public static final String HTTP_REDIRECT
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_FORBIDDEN

public static final String HTTP_FORBIDDEN
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_NOTFOUND

public static final String HTTP_NOTFOUND
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_BADREQUEST

public static final String HTTP_BADREQUEST
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_METHOD_NOT_ALLOWED

public static final String HTTP_METHOD_NOT_ALLOWED
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_INTERNALERROR

public static final String HTTP_INTERNALERROR
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

HTTP_NOTIMPLEMENTED

public static final String HTTP_NOTIMPLEMENTED
Deprecated. 
Some HTTP response status codes

See Also:
Constant Field Values

MIME_TEXT_PLAIN

public static final String MIME_TEXT_PLAIN
Deprecated. 
Common mime types for dynamic content

See Also:
Constant Field Values

MIME_TEXT_HTML

public static final String MIME_TEXT_HTML
Deprecated. 
Common mime types for dynamic content

See Also:
Constant Field Values

MIME_DEFAULT_BINARY

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

See Also:
Constant Field Values

MIME_APPLICATION_XML

public static final String MIME_APPLICATION_XML
Deprecated. 
Common mime types for dynamic content

See Also:
Constant Field Values

MIME_TEXT_JAVASCRIPT

public static final String MIME_TEXT_JAVASCRIPT
Deprecated. 
Common mime types for dynamic content

See Also:
Constant Field Values

MIME_APPLICATION_URL_ENCODED

public static final String MIME_APPLICATION_URL_ENCODED
Deprecated. 
Common mime types for dynamic content

See Also:
Constant Field Values
Constructor Detail

NanoHTTPD

public NanoHTTPD(int port)
          throws IOException
Deprecated. 
Starts a HTTP server to given port.

Throws an IOException if the socket is already in use

Parameters:
port - The port. If 0 the the server will start on a random port. The actual port is available from #getPort().
Throws:
IOException
Method Detail

serve

protected NanoHTTPD.Response serve(NanoHTTPD.Request req)
Deprecated. 
Override this to customize the server. (By default, this delegates to serveFile() and allows directory listing.)

Returns:
HTTP response, see class Response for details

isOpen

public boolean isOpen()
Deprecated. 
Description copied from interface: IServiceShutdown
Return true iff the service is running.

Specified by:
isOpen in interface IServiceShutdown

shutdown

public void shutdown()
Deprecated. 
Description copied from interface: IServiceShutdown
The service will no longer accept new requests, but existing requests will be processed (sychronous). This method should await the termination of pending requests, but no longer than the timeout specified by IServiceShutdown.Options.SHUTDOWN_TIMEOUT. Implementations SHOULD be synchronized. If the service is aleady shutdown, then this method should be a NOP.

Specified by:
shutdown in interface IServiceShutdown

shutdownNow

public void shutdownNow()
Deprecated. 
Description copied from interface: IServiceShutdown
The service will no longer accept new requests and will make a best effort attempt to terminate all existing requests and return ASAP. This method should terminate any asynchronous processing, release all resources and return immediately. Implementations SHOULD be synchronized. If the service is aleady shutdown, then this method should be a NOP.

Specified by:
shutdownNow in interface IServiceShutdown

main

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


getPort

public int getPort()
Deprecated. 
The port on which the service was started.


serveFile

protected NanoHTTPD.Response serveFile(String uri,
                                       Map<String,String> header,
                                       File homeDir,
                                       boolean allowDirectoryListing)
Deprecated. 
Serves file from homeDir and its' subdirectories (only). Uses only URI, ignores all headers and HTTP parameters. TODO This uses += for string append which is not efficient.


decodeParams

public static LinkedHashMap<String,Vector<String>> decodeParams(String parms,
                                                                LinkedHashMap<String,Vector<String>> p)
                                                         throws UnsupportedEncodingException
Deprecated. 
Decodes parameters in percent-encoded URI-format ( e.g. "name=Jack%20Daniels&pass=Single%20Malt" ) and adds them to a Map .

Parameters:
parms - The URL query parameters.
p - A map of the parsed, percent decoded parameters (required). The keys are the parameter names. Each value is a Vector of Strings containing the bindings for the named parameter. The order of the URL parameters is preserved by the insertion order of the LinkedHashMap and the elements of the Vector values.
Returns:
The caller's map.
Throws:
UnsupportedEncodingException

encodeParams

public static StringBuilder encodeParams(LinkedHashMap<String,Vector<String>> expected)
                                  throws UnsupportedEncodingException
Deprecated. 
Construct a percent encoded representation of the URL query parameters.

Parameters:
expected - The parameters.
Returns:
The encoded representation.
Throws:
UnsupportedEncodingException


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.