Web Server Architecture by Peter Harrison |
This article was written to provide some guidance towards implementing a Web Server that serves dynamic content. It has been designed with openness as the primary goal. This way you can plug in any number of individual products, such as different databases, without changing other components. This allows us to scale from small boxes like mine, to huge multi server environments. |
Why Servlets? |
Why Servlets? To date CGI scripts have been used to write software for
dynamic sites. CGI is very easy. Basically every request initiates a
instance of a CGI application. The CGI application uses the input stream
to gather the parameters of the request, and posts the resulting HTML out
of the output stream. Very Simple. So why use Java Servlets?
Unlike CGI scripts a Servlet once loaded into memory is retained in memory. The one Servlet can also handle multiple requests at the same time, while CGI requires separate memory for each request. Finally a servlet can take advantage of database connection pools, which means it can use an existing database connection rather than initialising a database connection for every request. In addition there are the cross platform and scaling advantages of Java which mean you don't have to rewrite your code when you move to a more powerfull machine. This means you can write your code on a Windows machine and test it, then move it directly to a high end production Solaris box for example, with no code changes. CGI would at the very least require a recompile, and may require many code changes. |
Overview of Components |
Over the last two years I have had experience putting together many
Web Servers that serve dynamic content. I have mostly used Open Source
software to do this, although there are commercial products which can
replace each of the components.
My objective was to create an environment which was as platform and vendor independent as possible. Although Open Source is also free, that is not the prime motivation for using Open Source. The primary objective is to have a system which can be easily scaled up, moving across platforms as required. I have decided to implement Java to achieve my goals, and so the solution I am presenting is based on Java. A Java Web Server solution will typically have the following components : |
Operating System : Linux / Windows |
The operating system I have implemented my production Web Server on
was Caldera Linux. I have also
implemented web servers on my Windows98 machine, Red Hat Linux, and Compaq
True64. While there are obviously differences when it comes to
installation details for various operating systems, all the components I
have chosen work equally well on most Operating systems, and should scale
well to higher end platforms such as Solaris.
Linux is available from several places online, and can also be purchased on CD. I used a Caldera 2.2 on CD, as this is a easy way to get Linux set up on a new machine quickly. Make sure you have compatible hardware before installation. Do not try to create a duel boot machine. This can be done, but assuming this machine is a production machine its better to have a clean Linux install. |
Web Server : Apache |
The Web Server I have implemented on my production Web Server is
Apache. I obtained the most recent release of Apache, and had to recompile
it on Linux to enable Tomcat (discussed below). It is reasonably easy to
install and set up. On my Windows machine I use just Tomcat, as Tomcat
also serves static web pages. Apache could easily be replaced by other Web
Servers, or perhaps even eliminated. However, Apache is the most solid and
popular Web Server available, making it the obvious choice for the
production system.
Apache can be obtained from apache.org . Both the binaries and source files can be obtained. The source contains make files which are used to compile the binaries. Switchs can be used to turn options in the build off and on. Build the version which accepts plug in modules, as you need to install Jserv to talk with Tomcat. I have also set up Microsoft IIS with Resin, which is similar to Tomcat. Resin makes configuration of IIS easy. Tomcat can also be run with IIS, but I have not tried this to date. |
Java Runtime Engine (JRE) : Sun |
Perhaps the only Closed Source component in the system, I currently
use Java 2. I had to download and install this for both my Linux and
Windows systems. Installation is simple, except for a gotcha or two on
Linux. There are competing JVM's, but I use the one from Sun for no
particularly good reason.
The JRE and JDK are available from sun.com . The JDK also comes with development environments such as Jbuilder from Inprise. Make sure that you delete the previous version of Java prior to installing the new one. The old version may have binaries in the /usr/bin directory that need to be deleted. Failure to do this may not result in immediate failure, but incompatibities between Java 1.1 and Java 1.2 will create runtime errors in Servlets. Don't have any classpath set at all. Put all packages into /usr/java/jre/lib/ext directory. Another popular JDK is from IBM. You can get IBM's JDK for Linux from here. You can get IBM's JDK for Windows from here. |
Java WebServer / Servlet Engine : Tomcat |
The Servlet Engine is the application which processes the dynamic
requests from the Web Server. The Servlet Engine I am using is Tomcat.
This is not nessasarily the fastest or the best Servlet Engine, however it
is the reference implementation that is used by Sun, so it is at least
standard.
Tomcat can be obtained from the jakarta.apache.org site. There are installations for both Windows and Linux. Change the Apache Configuration as per the script that comes with Tomcat. If this doesn't work you may need to recompile Apache to accept plug in modules. Put all the Tomcat Jar files into the /usr/java/jre/lib/ext directory. This way you don't need to mess about with classpath settings when running tomcat. If you want to run commercial servlet runners the two I recommend are Resin or JRun. Resin is probably the fastest Servlet Engine, and would be good on production servers. Resin is also Open Source. JRun is a polished product, with more features than Resin. JRun has a very nice web based configuration system. JRun is also available for a number of high end Operating Systems. |
Database : Interbase / FireBird |
The database I have used is Interbase/FireBird. This is because it has
been released as Open Source, and it is one of the highest quality
databases available. There is also a free native JDBC Driver for
Interbase/FireBird called InterClient which makes interfacing with Java
easy. There are other databases which could fit in, such as MySQL, MS-SQL, or Oracle. I have personally implemented
servlets with MS-SQL and Oracle on the back end in addition to Interbase.
Interbase 6 was originally obtainable from Borland as Open Source. Borland have now chosen to charge for their 'certified' version and have returned to the closed source model. Unfortunatly this means the Open Source community can no longer certify the security of Borlands closed source product. This is important because Borland failed to identify a serious security flaw in their previous closed source product, and it was only when it the source was opened was it discovered. There has therefore been a code fork between Borland and the Open Source community. The Open Source fork has been named FireBird. In every respect the Interbase and FireBird products are functionally identical at the moment, however there is no assurance that this will remain the case for long. I suggest that anyone wanting to use Interbase use the FireBird distribution rather than Borlands, which can be obtained from IBPhoenix.Com. For Linux there are two installs, the Classic and the SuperServer. I suggest that the Classic version is installed for a single Web Server. You will also need to download and install InterClient 1.6, which compliments Interbase 6. Copy the interclient.jar file into /usr/java/jre/lib/ext directory so that you won't require any changes to your classpath. |
Servlet Development Professionals |
Nothing But Net is a
company which specializes in developing web technology based on Java. A
substantial amount of our work is development of Dynamic Web Sites based
on Java Servlet technologies. We have developed sites for many different
platforms including Windows, Linux, True64, and Solaris.
On top of the basic Servlet Technologies we have developed software libraries which allow us to quickly deliver complex dynamic web page functionality. We also have experienced graphic artists and web designers to provide the visual impact you need to make your site stand out in the crowd. Our staff are all very experienced. Our rates are very competitive because we are based in New Zealand. New Zealand has a favorable exchange rate for US companies wanting to develop software. |
Servlet Technologies |
DevCentre Utils PackageThe DevCentre Utils Package is a Java Package which includes classes used by Nothing But Net to develop its web sites. This includes Connection Pool functionality, and Web Templating functionality. Template EnginesTemplate Engines are available which allow you to keep hard coded HTML out of your servlets. I have not used these yet, but I plan to in future. One such template system can be found at http://www.webmacro.org/. UniT - the Universal Text generatorUniT is a new category of base technology, a mixture of a text template and a very simple Java-like programming language which generates any text-based format. UniT has full access to Java and can be used to do various things that have something to do with text generation. UniT is similar to JSP, but it is more platform independant, more general, more flexible, easier, smaller, and cleaner. It can be obtained from http://www.textgenerator.com/. Java Server Pages (JSP)JSP, like ASP, allows you to embed Java Servlets directly into HTML. At runtime JSP pages are compiled into Servlets which are then run. This is similar to Templating, except instead of just having fields in the HTML there is full Java source code. It is possible to avoid having full source in th HTML by having Java Beans or other helper classes do things outside of the main servlet. Because I prefer to have Java and HTML separate I intend to use Templates rather than JSP. JSP is supported by Tomcat out of the box. StrutsStruts is a project on jakarta.apache.org . It is a framework which is used to separate your Servlets which handle Http requests from generic business code, which is kept in Java Beans. This is the framework which Richard Vowles has suggested to me. I feel it is suited to a Corporate system which has multiple interfaces to a database. Email FunctionalityThere are several packages available that provide the ability to send and receive email. While not directly relates to servlets, this functionality is common for web applications. An email sending package can be found at http://www.servlets.com/. |
Suggested Reading |
Running Linuxby Matt Welsh, Matthias Kalle Dalheimer and Lar Kaufman, published by O'Reilly This book is a very good book, both as a book that you can read fom cover to cover, and as a reference book. Developing Java Servletsby James Goodwill, published by Sams Publishing This book covers is both a good starters book, and also goes into some depth regarding how to do more sophisticated servlets with JDBC and Connection Pooling. |
Home |