|
Femto Web Server V1.4-F | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.lang.Thread
|
+--dfischer.femtowebserver.httpd.Httpd
This is the Femto Web Server main class which is implemented as an independent thread.
You may start as much different threads as you want - each with a different configuration.
The only thing that is common/shared between all instances is the time zone (ZoneTime)
and the log output (Stdout).
Each main thread has its own built-in multithreaded HTTP request engine, its own properties and is able to serve concurrent requests at the same time. To stop a main thread you should call the method shutdown() of the instance.
Programming Example:
...
// create new instance of the femto web server
Httpd httpdThread = new Httpd();
// configure the femto web server
String serverName = "127.0.0.1";
try { serverName = InetAddress.getLocalHost().getHostName(); } catch (Exception ex) {}
httpdThread.setServerName(serverName);
httpdThread.setServerPort(85);
httpdThread.setTimeZone("ECT");
httpdThread.addFilter("dfischer.femtowebserver.filter.HttpSessionCookieHandler");
// start the femto web server
httpdThread.start();
...
// and later if you want to stop the femto web server
httpdThread.shutdown();
httpdThread.join();
...
The Femto Web Server has no base directory for his served content - it searches all
inside the java CLASSPATH. So a good approach could be, to pack all your content to
a separate jar archive and add this archive to the CLASSPATH. The Femto Web Server is able to execute Java classes direct from the web browser - called Weblets - similar to CGI scripts or Java Servlets. It is also able to execute "Simple Server Side Includes" (SSSI) at server side direct from static HTML pages.
As additional feature HTTP Request and Response Filter, HTTP Sessions and Connection Adapters are supported.
HttpdWebletInterface,
HttpdSssiInterface,
HttpdFilter,
HttpdSession,
HttpdConnectionAdapterInterface| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
Httpd()
Creates a new instance of the Femto Web Server with its own properties and its own session hashtable. |
|
| Method Summary | |
void |
addFilter(java.lang.String className)
Adds a HttpdFilter to the current Femto Web Server instance with no filter arguments. |
void |
addFilter(java.lang.String className,
java.lang.String[] filterArguments)
Adds a HttpdFilter to the current Femto Web Server instance with filter arguments. |
void |
addMimeMapping(java.lang.String fileExtension,
java.lang.String mimeType)
Allows to add additional MIME types to the current MIME mapping. |
void |
addUrlFileMapping(java.lang.String requestFilePath,
java.lang.String mappedPath)
Maps the path of a requested file to an other (internal) path and continues further processing with the internal path. |
java.lang.String[] |
getFilterArguments(java.lang.String className)
Returns the arguments of a HttpdFilter. |
java.lang.String[] |
getFilterClassNames()
Returns a list of all HttpdFilters. |
void |
removeFilter(java.lang.String className)
Removes a HttpdFilter from the current Femto Web Server instance. |
void |
removeUrlFileMapping(java.lang.String requestFilePath)
Removes the mapping of a request file path. |
void |
run()
Starts the Femto Web Server instance (as thread). |
void |
setBindAddress(java.lang.String bindAddress)
Binds the server socket to a specific TCP/IP address. |
void |
setConnectionAdapterClass(java.lang.String className)
Allows to set an own connection adapter which wire the Femto Web Server to a specific network protocol. |
void |
setDefaultContent(java.lang.String defaultContent)
Sets the default request file, if the HTTP request points only to a directory path. |
void |
setDefaultMimeType(java.lang.String mimeType)
Sets the default MIME type if the Femto Web Server is unable determine the MIME type from the HTTP request file. |
void |
setExtendedMimeMapping()
Sets extended MIME mapping (less secure). |
static void |
setLogStream(java.io.PrintStream logStream)
Sets the log output for all instances of the Femto Web Server. |
void |
setMimeMapping(java.lang.String[][] mimeMappimg)
Allows to set an own, specific MIME mapping. |
void |
setProperty(java.lang.String key,
java.lang.Object value)
Allows to add any object to the HttpdProperties. |
void |
setRequestTimeout(int timeoutSeconds)
Sets the (processing) timeout of an URL request. |
void |
setRestrictedMimeMapping()
Sets restricted MIME mapping (more secure). |
void |
setServerName(java.lang.String serverName)
Sets the (TCP/IP) HTTP server name. |
void |
setServerPort(int serverPort)
Sets the HTTP server port. |
void |
setSessionHashtable(HttpdSessionHashtable sessionHashtable)
Allows to set an own session hashtable. |
static void |
setTimeZone(java.lang.String timeZone)
Sets the time zone for all instances of the Femto Web Server. |
void |
setWelcomePage(java.lang.String welcomePage)
Loads for HTTP requests to the top level default URL "/" to a welcome page (or a welcome Weblet). |
void |
shutdown()
Does a graceful shutdown of a Femto Web Server main thread. |
void |
updateMimeMapping(java.lang.String fileExtension,
java.lang.String mimeType)
Allows to modify the MIME type of an already existing file extension inside the current MIME mapping. |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public Httpd()
throws java.lang.Exception
HttpdProperties,
HttpdSessionHashtable| Method Detail |
public static void setTimeZone(java.lang.String timeZone)
timeZone - 3-Letter time zone ID.ZoneTime.TIME_ZONE
public void setConnectionAdapterClass(java.lang.String className)
throws java.lang.ClassNotFoundException
The HttpdSocketConnectionAdapter is used as default adapter if this method never was called.
className - the full name of the connection adapter class using '.' and not '/' as the separator and without a trailing ".class" suffixHttpdConnectionAdapterInterface,
HttpdProperties.getConnectionAdapterClass()public void setServerName(java.lang.String serverName)
serverName - HTTP server name. Used on log output and accessable also on webletsHttpdProperties.getServerName()public void setServerPort(int serverPort)
serverPort - HTTP server port numberHttpdProperties.getServerPort()
public void setBindAddress(java.lang.String bindAddress)
throws java.net.UnknownHostException
bindAddress - specific TCP/IP address to listen.HttpdProperties.getBindAddress()public static void setLogStream(java.io.PrintStream logStream)
logStream - log output stream or null, to disable loggingStdoutpublic void setDefaultContent(java.lang.String defaultContent)
defaultContent - default request file, if the HTTP request points only to a directory pathHttpdProperties.getDefaultContent()public void setWelcomePage(java.lang.String welcomePage)
welcomePage - path to welcome page. Example: mypackage/htdocspackage/welcome.classHttpdProperties.getWelcomePage()
public void addUrlFileMapping(java.lang.String requestFilePath,
java.lang.String mappedPath)
Example: /dcs/abc/a* -> /package/doit
requestFilePath - the path of the request file which will be mapped to the new pathmappedPath - the new pathremoveUrlFileMapping(java.lang.String),
HttpdProperties.getUrlFileMapping()public void removeUrlFileMapping(java.lang.String requestFilePath)
requestFilePath - the path of the request file which will be un-mapped.addUrlFileMapping(java.lang.String, java.lang.String),
HttpdProperties.getUrlFileMapping()public void setRestrictedMimeMapping()
HttpdProperties.RESTRICTED_MIME_MAPPING,
setExtendedMimeMapping(),
setMimeMapping(java.lang.String[][]),
setDefaultMimeType(java.lang.String)public void setExtendedMimeMapping()
HttpdProperties.EXTENDED_MIME_MAPPING,
setRestrictedMimeMapping(),
setMimeMapping(java.lang.String[][]),
setDefaultMimeType(java.lang.String)
public void addMimeMapping(java.lang.String fileExtension,
java.lang.String mimeType)
fileExtension - File extension without leading dot (Example: "zip")mimeType - MIME type of file extension (Example: "application/zip")updateMimeMapping(java.lang.String, java.lang.String),
setRestrictedMimeMapping(),
setExtendedMimeMapping()
public void updateMimeMapping(java.lang.String fileExtension,
java.lang.String mimeType)
addMimeMapping(java.lang.String, java.lang.String) will be called.fileExtension - An already existing file extension without leading dot (Example: "html")mimeType - The new MIME type of the file extension. Example: "text/html;charset=iso-8859-1" will replace the default "text/html".setRestrictedMimeMapping(),
setExtendedMimeMapping()public void setMimeMapping(java.lang.String[][] mimeMappimg)
mimeMappimg - MIME mapping array to set. setRestrictedMimeMapping(),
setExtendedMimeMapping(),
setDefaultMimeType(java.lang.String)public void setDefaultMimeType(java.lang.String mimeType)
SECURITY WARNING: YOU SHOULD NEVER SET A DEFAULT MIME TYPE BECAUSE THIS WILL OPEN A BIG SECURITY HOLE. THE FEMTO WEB SERVER WILL AFTERWARDS SERVE ALL INSIDE THE CLASSPATH EXCEPT NON WEBLET CLASSES !!!
mimeType - the default mime type. Example: "TEXT/HTML"HttpdProperties.getDefaultMimeType()public void setRequestTimeout(int timeoutSeconds)
timeoutSeconds - request timeout in secondsHttpdProperties.getRequestTimeout()public void addFilter(java.lang.String className)
className - full classname of the new filter. Will be loaded from the CLASSPATH of the Femto Web Server.addFilter(String, String[]),
removeFilter(java.lang.String),
getFilterClassNames(),
getFilterArguments(java.lang.String),
HttpdFilter
public void addFilter(java.lang.String className,
java.lang.String[] filterArguments)
className - full classname of the new filter. Will be loaded from the CLASSPATH of the Femto Web Server.filterArguments - filter arguments, used to control the behaviour of the filter.addFilter(String),
removeFilter(java.lang.String),
getFilterClassNames(),
getFilterArguments(java.lang.String),
HttpdFilter,
HttpdFilter.getFilterArguments()public void removeFilter(java.lang.String className)
className - full classname of the filter.addFilter(String),
addFilter(String, String[]),
getFilterClassNames(),
getFilterArguments(java.lang.String),
HttpdFilterpublic java.lang.String[] getFilterClassNames()
addFilter(String),
addFilter(String, String[]),
removeFilter(java.lang.String),
getFilterArguments(java.lang.String),
HttpdFilterpublic java.lang.String[] getFilterArguments(java.lang.String className)
className - full classname of the filter.addFilter(String),
addFilter(String, String[]),
removeFilter(java.lang.String),
getFilterClassNames(),
HttpdFilter,
HttpdFilter.getFilterArguments()public void setSessionHashtable(HttpdSessionHashtable sessionHashtable)
sessionHashtable - the own session hashtable.HttpdProperties.getSessionHashtable(),
HttpdSession,
HttpSessionCookieHandler
public void setProperty(java.lang.String key,
java.lang.Object value)
HttpdProperties.key - Unique key of the object. If more than one object with the same key is added to the properties, the old object is overwritten.value - reference to the object.HttpdProperties.getProperty(java.lang.String)public void run()
run in class java.lang.Threadshutdown()public void shutdown()
run()
|
Femto Web Server V1.4-F | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||