|
||||||||
| 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 and the log output.
Each main thread has his built-in multithreaded HTTP request engine and is able to serve concurrent requests on 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(83);
httpdThread.setWelcomePage("/dfischer/femtowebserver/test/Welcome.html");
httpdThread.setRestrictedMimeMapping();
httpdThread.setTimeZone("ECT");
// 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) from HTML pages.
HttpdWebletInterface,
HttpdSssiInterface| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
Httpd()
|
|
| Method Summary | |
void |
addMimeMapping(java.lang.String fileExtension,
java.lang.String mimeType)
Allows to add additional MIME types to the current MIME mapping. |
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 |
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 |
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. |
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 the main thread. |
| 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.io.IOException
| Method Detail |
public void shutdown()
run()public static void setTimeZone(java.lang.String timeZone)
timeZone - 3-Letter time zone ID.ZoneTime.TIME_ZONEpublic 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 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")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 run()
run in class java.lang.Threadshutdown()
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||