javax.servlet
interfaces. It was designed to be used with JRacer WebDAV server and other examples
of Web application. It can not be used as normal HTTP server, because it can not access file itself
and the only things it do - manage pool of session threads and redirects requests to servlets.JHttpServer is optimized to provide the best performance for client application. It supports persistent connections and doesn't break the connection until client will do it itself. Each connection is handled by own thread. When number of active connections exceeds limit for maximal number of threads, JHttpServer delay accepting of new connections and waits until one of the active sessions is terminated and it's thread can be used for new connection.
httpserver.jar
archive which is
included in distribution. Also the distribution contains servlet.jar package with
javax.servlet.*
interfaces, jaas.jar
which can be used to use JAAS
with JDK1.3.
If you want to perform build of httpserver.jar
yourself, then
use compile.bat
or build.xml
files. First one
is DOS batch file which performs compilation of source using javac
compiler. Another one is project file for ANT building tool.
If you have ANT installed and be available through the PATH environment variable,
then just execution of ant
will build the project.
httpserver.jar
in classpath.
All parameters to the server are passed though the command line using system
properties and list of arguments consisting of <servlet-path servlet-class>
pairs. Currently JHttpServer recognize the following properties:
Property name | Property description | Default value |
---|---|---|
port | Port at which server will listen for clients connections | 8080 |
linger | Socket linger time | 10 |
maxThreads | Maximal number of threads which server can spawn | 64 |
debug | JRacer will dump received queries and send replies | false |
authType | Authentication type (anonymous, everyone, jaas ) | anonymous |
config | Configuration file with properties | jhttpserver.properties |
sessionTimeout | Timeout in milliseconds for waiting request by the server after which session will be closed and thread returned in thread pool | 0 (disabled) |
ssl-support | Enables SSL connections | false |
ssl-port | Port used by SSL | 443 |
ssl-authenticate | Accept or reject unauthenicated users | false |
ssl-cert-file | File generated by keytool | keystore |
ssl-cert-password | Certificate passowrd | - |
Properties can be also specified in "jhttpserver.properties"
file.
Servlet configuration properties are taken either from file
"SERVLET-NAME.properties
", or, if this file doesn't exists, from JHttpServer
properties.
Example of running JHttpServer:
java -Dport=80 -DmaxThreads=100 org.garret.httpserver.JHttpServer /webdav webdav.WebdavServlet
Create a new keystore and self-signed certificate with corresponding public/private keys. % keytool -genkey -alias duke -keyalg RSA \ -validity 7 -keystore keystore Enter keystore password: password What is your first and last name? [Unknown]: Duke What is the name of your organizational unit? [Unknown]: Java Software What is the name of your organization? [Unknown]: Sun Microsystems, Inc. What is the name of your City or Locality? [Unknown]: Palo Alto What is the name of your State or Province? [Unknown]: CA What is the two-letter country code for this unit? [Unknown]: US Is CN=Duke, OU=Java Software, O="Sun Microsystems, Inc.", L=Palo Alto, ST=CA, C=US correct? [no]: yes Enter key password forTo enable SSL connections you should specify the following properties to JHttpServer:(RETURN if same as keystore password): This is the keystore that the server will use.
Property | Comment |
---|---|
-Dssl-support=true | Enables SSL connections |
-Dssl-port=PORT | Port used by SSL (by default 443) |
-Dssl-authenticate=BOOLEAN | By default SSL accept unauthenicated users |
-Dssl-cert-file=FILE | File generated by keytool |
-Dssl-cert-password=PASSWORD | Certificate password |
Command name | Command description |
---|---|
help | output list of accepted commands |
info | output some information about the current server state |
exit | shutdown the server |
compile.bat
file and run it StartServer.bat
script. If will start JHttpServer on your computer using port 80.
If this port is used, please specify alternative port in StartServer.bat
.
Then in your browser specify url of your computer - for example http://localhost
.
You will see content of the content of root directory (if you have permissions to list it).