|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.dalsemi.tininet.http.HTTPServer
This class implements an HTTP server. This class currently only supports the
GET and POST methods.
The serviceRequests
method blocks on a ServerSocket
accept call. A new thread is spawned to service each new connection.
The method serviceRequest(Object lock)
can be used to
synchronize access, using the lock object, to a requested web page. This might be useful if the
server dynamically updates a page.
boolean webServerEnabled = true;
Object lock= new Object();
HTTPServer httpServer = new HTTPServer();
boolean loggingFailed = false;
//...
try
{
// create an instance of HTTPServer on port httpPort
httpServer = new HTTPServer(httpPort);
// override the default index page
httpServer.setIndexPage(webIndex);
// override the default HTTP root
httpServer.setHTTPRoot(webRoot);
// override the default log file name
httpServer.setLogFilename(webLog);
}
catch(HTTPServerException h)
{
System.out.println(h.toString());
}
try
{
// enable logging
// NOTE: the log file is always appended and
// will eventually consume all free memory
// if it is not managed.
httpServer.setLogging(true);
}
catch(HTTPServerException h)
{
// problem with log file
loggingFailed = true;
if(debugOn)
{
System.out.println(h.toString());
}
}
while(webServerEnabled)
{
httpServer.serviceRequests(lock);
//...
}
application/x-www-form-urlencoded
Default input max value is 1000 bytes for post. This can be increased up to 3000 bytes
by calling the setBufferSize
method. The POST handling class must either be
included in the .tini file with the server implementation, or in the TINI's file system.
The handling class must implement the interface class PostScript
, and its
method handlePost
.
handlePost
takes as a parameter the socket output stream from the connection.
This allows the designer to dynamically create an response page of any type desired. This
allow for increased flexibility.
Field Summary | |
int |
buffSize
This is the size for the incoming data buffer |
static int |
DEFAULT_HTTP_PORT
Default port number (port 80) |
static int |
DELETE
DELETE request |
static int |
GET
GET request |
static int |
HEAD
HEAD request |
static int |
HTTP_BAD_REQUEST
Standard HTTP_BAD_REQUEST response |
static int |
HTTP_CREATED
Standard HTTP_CREATED response |
static int |
HTTP_ENTITY_TOO_LARGE
Standard HTTP_ENITY_TOO_LARGE response |
static int |
HTTP_FORBIDDEN
Standard HTTP_FORBIDDEN response |
static int |
HTTP_INTERNAL_ERROR
Standard HTTP_INTERNAL_ERROR response |
static int |
HTTP_NOT_FOUND
Standard HTTP_NOT_FOUND response |
static int |
HTTP_OK
Standard HTTP_OK response |
static int |
HTTP_SERVER_ERROR
Standard HTTP_SERVER_ERROR response |
static int |
HTTP_UNAUTHORIZED
Standard HTTP_UNAUTHORIZED response |
static int |
HTTP_UNSUPPORTED_TYPE
Standard HTTP_UNSUPPORTED_TYPE response |
static java.lang.String |
MIME_APP_OS
MIME_APP_OS Content type |
static java.lang.String |
MIME_IMAGE_BMP
MIME_IMAGE_BMP Content type there seem to be multiple mime types for this so we cannot make this final |
static java.lang.String |
MIME_IMAGE_GIF
MIME_TEXT_PLAIN Content type |
static java.lang.String |
MIME_IMAGE_JPG
MIME_TEXT_PLAIN Content type |
static java.lang.String |
MIME_TEXT_HTML
MIME_TEXT_PLAIN Content type |
static java.lang.String |
MIME_TEXT_PLAIN
MIME_TEXT_PLAIN Content type |
static int |
OPTIONS
OPTIONS request |
static int |
POST
POST request |
static int |
PUT
PUT request |
static int |
TRACE
TRACE request |
static int |
TYPE_FULL_REQUEST
Standard type TYPE_FULL_REQUEST |
static int |
TYPE_FULL_RESPONSE
Standard type TYPE_FULL_RESPONSE |
static int |
TYPE_SIMPLE_REQUEST
Standard type TYPE_SIMPLE_REQUEST |
static int |
UNSUPPORTED
Request unsupported |
Constructor Summary | |
HTTPServer()
Default constructor. |
|
HTTPServer(int httpPort)
Creates an HTTPServer using port httpPort . |
|
HTTPServer(int httpPort,
boolean logEnabled)
Creates an HTTPServer using port httpPort . |
Method Summary | |
java.lang.String |
getHTTPRoot()
Returns the HTTP root of the server. |
java.lang.String |
getIndexPage()
Returns the server's default index page. |
java.lang.String |
getLogFilename()
Returns the name of the log file. |
boolean |
getLogging()
Returns the logging status. |
int |
getPortNumber()
Returns the server's current port number. |
int |
serviceRequests()
Checks for incoming client HTTP request and services supported requests that are detected. |
int |
serviceRequests(java.lang.Object lock)
Checks for incoming client HTTP request and services supported requests that are detected. |
static void |
setBitmapMimeType(java.lang.String newMimeType)
Allows user to change the mime type for bitmaps. |
void |
setBufferSize(int newSize)
This method is used to modify the size of the recive buffer. |
void |
setHTTPRoot(java.lang.String httpRoot)
Sets the http root. |
void |
setIndexPage(java.lang.String indexPage)
Sets the server's index page. |
void |
setLogFilename(java.lang.String logFileName)
Sets the log file name. |
void |
setLogging(boolean logEnabled)
Sets the logging status. |
void |
setPortNumber(int httpPort)
Sets the server's port number. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int HTTP_OK
public static final int HTTP_CREATED
public static final int HTTP_BAD_REQUEST
public static final int HTTP_UNAUTHORIZED
public static final int HTTP_FORBIDDEN
public static final int HTTP_NOT_FOUND
public static final int HTTP_ENTITY_TOO_LARGE
public static final int HTTP_UNSUPPORTED_TYPE
public static final int HTTP_SERVER_ERROR
public static final int HTTP_INTERNAL_ERROR
public static final int TYPE_SIMPLE_REQUEST
public static final int TYPE_FULL_REQUEST
public static final int TYPE_FULL_RESPONSE
public static final int DEFAULT_HTTP_PORT
public static final int UNSUPPORTED
public static final int GET
public static final int POST
public static final int HEAD
public static final int OPTIONS
public static final int PUT
public static final int DELETE
public static final int TRACE
public static final java.lang.String MIME_TEXT_PLAIN
public static final java.lang.String MIME_TEXT_HTML
public static final java.lang.String MIME_IMAGE_GIF
public static final java.lang.String MIME_IMAGE_JPG
public static java.lang.String MIME_IMAGE_BMP
public static final java.lang.String MIME_APP_OS
public int buffSize
Constructor Detail |
public HTTPServer() throws HTTPServerException
public HTTPServer(int httpPort) throws HTTPServerException
HTTPServer
using port httpPort
. Logging is disabled.httpPort
- port number for serverpublic HTTPServer(int httpPort, boolean logEnabled) throws HTTPServerException
HTTPServer
using port httpPort
. Logging is enabled
if logEnabled
is true
.httpPort
- port number for serverlogEnabled
- set logging optionMethod Detail |
public static void setBitmapMimeType(java.lang.String newMimeType)
public boolean getLogging()
true
if logging is enabledpublic void setLogging(boolean logEnabled) throws HTTPServerException
logEnabled
- true
if the server is to write to a default log filepublic java.lang.String getLogFilename()
public void setLogFilename(java.lang.String logFileName)
logFileName
- name of the log filepublic java.lang.String getHTTPRoot()
public void setHTTPRoot(java.lang.String httpRoot)
httpRoot
to the leaves of
the directory tree can be accessed by HTTP requests. Files between the
root of the file system and httpRoot
cannot be accessed with
HTTP requests.httpRoot
- path indicating the root of the serverpublic java.lang.String getIndexPage()
public void setIndexPage(java.lang.String indexPage)
indexPage
- page to be used by the server as the default index pagepublic int getPortNumber()
public void setPortNumber(int httpPort) throws HTTPServerException
httpPort
- number of the port to be openedpublic void setBufferSize(int newSize)
newSize
- the desired size of the bufferpublic int serviceRequests() throws HTTPServerException
public int serviceRequests(java.lang.Object lock) throws HTTPServerException
lock
- lock for exclusive access to web page
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |