HttpdBase4J 0.2
Sponsored Links
HttpdBase4J 0.2 Ranking & Summary
File size:
3.1 MB
Platform:
Any Platform
License:
LGPL (GNU Lesser General Public License)
Price:
Downloads:
832
Date added:
2007-07-16
Publisher:
Donald Munro
HttpdBase4J 0.2 description
HttpdBase4J is an embeddable Java web server framework that supports HTTP, HTTPS, templated content and serving content from inside an archive.
The classes are easy to extend as they utilize the Hollywood dont call us, well call you principle to allow the user to overide the framework behaviour during all the different phases of the HTTP transaction.
Note:HttpdBase4J uses the Java 6 com.sun.net.httpserver classes so it wont currently work under earlier versions of Java.
Usage Examples:
The simplest use case is to create an embedded web server on port 8088 with its home directory at htdocs in the local filesystem and a root url at / ie / maps onto htdocs:
homeDir = new java.io.File("./htdocs");
httpd = new FileHttpd(homeDir, 10); // Creates a server with a threadpool of 10
httpd.setLogger(System.err); // Log to console
httpd.start(8088, "/");
Creating a HTTPS server equivalent the the HTTP server above requires passing a keystore and password to start. Passing null will generate a certificate free keystore if you only need the encryption capabilities of HTTPS and not the certificate capability:
httpd = new FileHttpd(homeDir, 10);
m_httpd.start(8089, "/", keystore, password);
Serving content from inside an archive or from a jar or zip in the Java classpath requires creating an ArchiveHttpd instance instead of a FileHttpd. To serve content located in a jar or zip in the class path you need only specify the resource directory in the classpath where the content islocated, for example:
httpd = new ArchiveHttpd("/resources/htdocs", 10);
httpd.start(8088, "/");
To serve content from within a specific archive specify the archive as a Java File when constructing the ArchiveHttpd:
httpd = new ArchiveHttpd(new File("content.zip"), "/resources/htdocs", 10);
httpd.start(8088, "/");
Creating web content using templates is also supported. Currently only the StringTemplate library (http://www.stringtemplate.org) is is supported but it should be relatively easy to create user derived classes for other template implementations. To create an HTTP embedded web server on serving templated content from resources/htdocs in the classpath and having a template file handler (A Java class implenting the Templatable interface that is used to fill the templates) in net.homeip.donaldm.test.templates.
httpd = new ArchiveHttpd("resources/htdocs", 10);
StringTemplateHandler stHandler = new ArchiveStringTemplateHandler(httpd,
"net.homeip.donaldm.test.templates");
httpd.addHandler(".st", stHandler); // .st extension = template files
httpd.start(m_port, "/");
The HTTP transaction handling can be customized at any point by overiding any of the methods in the HttpHandleable interface or by overiding onCreateRequestHandler in Httpd in order to provide your own request handler. A simple example of overiding HttpHandleable methods:
httpd = new TestOverideHttpd(m_homeDir, 10);
httpd.start(m_port, "/");
class TestOverideHttpd extends FileHttpd
{
public HttpResponse onServeHeaders(long id, HttpExchange ex, Request request)
{
//Create or amend content
}
public InputStream onServeBody(long id, HttpExchange ex, Request request)
{
//Return amended or created content
}
}
The classes are easy to extend as they utilize the Hollywood dont call us, well call you principle to allow the user to overide the framework behaviour during all the different phases of the HTTP transaction.
Note:HttpdBase4J uses the Java 6 com.sun.net.httpserver classes so it wont currently work under earlier versions of Java.
Usage Examples:
The simplest use case is to create an embedded web server on port 8088 with its home directory at htdocs in the local filesystem and a root url at / ie / maps onto htdocs:
homeDir = new java.io.File("./htdocs");
httpd = new FileHttpd(homeDir, 10); // Creates a server with a threadpool of 10
httpd.setLogger(System.err); // Log to console
httpd.start(8088, "/");
Creating a HTTPS server equivalent the the HTTP server above requires passing a keystore and password to start. Passing null will generate a certificate free keystore if you only need the encryption capabilities of HTTPS and not the certificate capability:
httpd = new FileHttpd(homeDir, 10);
m_httpd.start(8089, "/", keystore, password);
Serving content from inside an archive or from a jar or zip in the Java classpath requires creating an ArchiveHttpd instance instead of a FileHttpd. To serve content located in a jar or zip in the class path you need only specify the resource directory in the classpath where the content islocated, for example:
httpd = new ArchiveHttpd("/resources/htdocs", 10);
httpd.start(8088, "/");
To serve content from within a specific archive specify the archive as a Java File when constructing the ArchiveHttpd:
httpd = new ArchiveHttpd(new File("content.zip"), "/resources/htdocs", 10);
httpd.start(8088, "/");
Creating web content using templates is also supported. Currently only the StringTemplate library (http://www.stringtemplate.org) is is supported but it should be relatively easy to create user derived classes for other template implementations. To create an HTTP embedded web server on serving templated content from resources/htdocs in the classpath and having a template file handler (A Java class implenting the Templatable interface that is used to fill the templates) in net.homeip.donaldm.test.templates.
httpd = new ArchiveHttpd("resources/htdocs", 10);
StringTemplateHandler stHandler = new ArchiveStringTemplateHandler(httpd,
"net.homeip.donaldm.test.templates");
httpd.addHandler(".st", stHandler); // .st extension = template files
httpd.start(m_port, "/");
The HTTP transaction handling can be customized at any point by overiding any of the methods in the HttpHandleable interface or by overiding onCreateRequestHandler in Httpd in order to provide your own request handler. A simple example of overiding HttpHandleable methods:
httpd = new TestOverideHttpd(m_homeDir, 10);
httpd.start(m_port, "/");
class TestOverideHttpd extends FileHttpd
{
public HttpResponse onServeHeaders(long id, HttpExchange ex, Request request)
{
//Create or amend content
}
public InputStream onServeBody(long id, HttpExchange ex, Request request)
{
//Return amended or created content
}
}
HttpdBase4J 0.2 Screenshot
HttpdBase4J 0.2 Keywords
HttpdBase4J
HTTP
HTTPS
ArchiveHttpd
FileHttpd
HttpdBase4J 0.2
Java Web Server
web server
Supports HTTP
server framework
Java Web
content
java
server
new
httpd
Bookmark HttpdBase4J 0.2
HttpdBase4J 0.2 Copyright
WareSeeker periodically updates pricing and software information of HttpdBase4J 0.2 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of HttpdBase4J 0.2 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed
Featured Software
Want to place your software product here?
Please contact us for consideration.
Contact WareSeeker.com
Related Information
what does http stand for
http proxy
http of mathematics web sites
Sun Java System Web Server
http 404
java web server 2.0
https mypay.dfas.mil
web server monitoring
List of HTTP status codes
java web servers
apache web server
https unemployment.ohio.gov
web server extensions
abbreviation
web servers
https mycampus.phoenix.edu
web server setup
server3
Related Software
Babelj is a language server for Java. Free Download
HTTPD::Authen is a HTTP server authentication class. Free Download
TLI343-HTTPD is a small HTTPD server. Free Download
ArrowHead ASP Server is a 100% Java Servlet supporting ASP and VBScript. Free Download
Dwarf HTTP Server is a full-featured and ready-to-use web server with the Java Servlet API 2.2 and Java Server Pages 1.1. Free Download
JMud is an experimental MUD server written in Java. Free Download
DBD::JDBC is a JDBC proxy driver for the DBI module. Free Download
Panther is a lightweight, modular Java application server, suitable for embedding in a web server. Free Download
Latest Software
Popular Software
Favourite Software