For Engineers Only | ![]() |
by Andy John
What is Enhydra?
Enhydra is meant for engineers who want to create web applications (web sites with dynamic content that actually do something). We also expect a lot of interest in our Servlet technology, even from people who don't care about writing a web application.
Enhydra has three main pieces:
The framework is an abstract web application: you provide the actual content to create an application. It handles most of the overhead for you, leaving you free to decide what pages you want, what they look like, and the flow of information between them. For more information on the framework (from the point of view of what you have to write to write an Enhydra application), please see the Enhydra Application documentation.
The tools are used at compile time. GNU Make is used, with a suite of Java specific make rules. The end result is a source tree you can just type "make" on, like the C days (rather then building .o files, then .a or .so, then executables, first the .class files are built then .jar files). Some URLs are handled by classes written by hand. But most (the ones with dynamic HTML) are built with Enhydra Jolt. This is a compiler that lets you combine Java and HTML. The resulting files are compiled into Java objects, so most of the work is done at compile time. At run time the output is very quick, because you don't have to parse HTML every time. XMLC, coming soon, will be another way to serve HTML from Java. It can even be used to serve dynamic XML content (HTML is just one example of XML). DODS, coming very soon, lets you graphically create compound data objects. It then generates SQL code to create database tables, and Java classes to get/set/search the tables.
The resulting Enhydra application consists of a jar file (a Servlet) and a config file. If you have Apache and JServ, you may easily run your application in it. Or any Servlet capable web server (or any Servlet runner). If you don't have already have a Servlet server, you may use the Multiserver. Or, if you don't care about Enhydra applications, you can just use the Multiserver to serve servlets. It has a graphical administration program for adding/removing/starting/stopping servlets/applications. It can connect one servlet to the Web in multiple ways. Or it can connect one port to multiple servlets. Plus it has a built in debugger that works on servlets as well as Enhydra applications. It shows the requests to the Servlet in real time. Each request may be examined: every property of the request from the browser, a trace of every call the Servlet made to the Servlet API, and all the properties of the Servlet's response, including a copy of the output for text and HTML results! See the screen shots for an example.
The debugging capabilities of the Multiserver are also available as a stand-alone Servlet. This lets you debug any Servlet in any server. If you are debugging an Enhydra application more details are available, such as the contents of session data before and after the request. But the debugger is extremely useful for all Servlet development.
Who is Enhydra meant for?
We anticipate three categories of users:
How To Try Enhydra - The 10 Minute Tour
We've seen the web logs. We know you like to just jump in the deep end and
download the source code : ) But trust me. Try this first.
The code will still be there awaiting you : )
(This is an outline. See the Download section for instructions.)
Yes! All this can be done in 10 minutes! It will give you the best introduction to Enhydra. For full instructions, see the download section for your platform.
A Simple Sample Scenario
Here's one possible real-life example of how Enhydra could be used. This shows a day in the life of Enhydra, but it does not show how Enhydra really shines: when you have many pages that share data and interoperate.
I'm an engineer at a technology company. I have to fill out time sheet forms, which is a pain in the butt. Then the office manager has to turn around and type them in. So I decide that this would be perfect for a simple web application on our intranet.
I write a timesheet application using Enhydra. To keep things simple I keep the list of employees (name/password) in the application's config file, as well as a list of the current projects.
I decide to use http basic auth security, because it's so easy to do. In the future this would be replaced with a custom login screen for more control, but basic-auth is acceptable for post-only data. In Enhydra, basic-auth is handled by throwing a certain kind of exception, so there is no web page needed to support it.
This means I only need to support three URLs: Form.po, Submit.po and Done.html.
When users go to Form.po they see the timesheet. It is a big HTML form, built up from the list of categories read in at startup time from the config file. For each project it has 7 entry fields for the days of the week. At the bottom is a submit button, which sends the data to the second url, Submit.po. I use an HTML editor to create a nice looking page, with a placeholder form in it. I save it as Submit.jhtml in the right location in my source tree. Then I edit it to add <JOLT> tags and Java code. One of the methods looks at the data from the config file and adds HTML (the form) to the page. In the body of the HTML, I replace the form with a call to my Java method (again, using <JOLT> tags).
For Submit.po, I only need to do Java work, so I decide to write it by hand (the class Submit.java). This reads in a long list of CGI input parameters, finds the non-empty rows, and then writes out to a comma-separated file in a special directory. Then it issues a redirect (by throwing an exception) to Done.html. I like writing apps this way; all the decision/processing is done by one class, then it redirects to the next page or back if it didn't like the input. But there are many ways to lay out the flow of these things.
Our office manager, who uses Excel, has the special directory mounted on her windows box. She simply double clicks on the file and Excel opens up and the data is ready to be used, just like magic.
The final page, Done.html, gives the user feedback that her data was submitted successfully. For this simple app this can just be a static HTML page. I add the page (.html) to my application. It will get served as a static file, just like images would.
So, my application is finished. I compile it up, and end up with a jar file containing a Servlet (my app) and a config file. Since I don't want to mess with the corporate web server, I want to run it in its own server. So I use the Multiserver.
I tell my whole department about it. Everyone loves it. It saves a lot of time and hassle.
But then a new billing category needs to be added. So I connect to the Multiserver's graphical administration program, log in, then wait till no one is logged in to the app. Then I stop it, and click on "Modify". This lets me edit the contents of the application's config file remotely!! I add the new category, hit "Save", then restart the application.
Next week one of our sales guys goes on the road. But he still wants to use the timesheet app. So I add a WAI connection to our company's main web server. This is in addition to the current HTTP port. Now people can connect inside and outside the company!
My application is a huge success. I add the ability to save and restore partial timesheets. Since we already have everyone in the company in our LDAP database, I validate the username and password against that, using JDAP. Because I put all my data access code in data objects in a sub-package, switching over to the new authentication method didn't effect the rest of the program.
My application becomes so vital to the department, that our IS guy gets involved. He want to put it on the official department web site, so it is secured, backed up, monitored etc.... He has our department web site running on Apache. So he adds the JServ module (so he can run servlets), then adds my app to Apache (to Apache an Enhydra application is just another Servlet).
My boss realizes how great I am and I get a promotion and a raise* : )
*Your mileage may vary.