Apartment Hunting

The weekend was spent apartment hunting with my roommate. Starting this April, our new location will be in the Rosewood Plantation apartment complex right off Spalding Drive:

607 Ivy Chase Ln
Norcross, GA 30092-4646

The total estimated time from work to home will now be six minutes, at a distance of 2.47 miles. Contrast this with my current 21.08 mile drive at 27 minutes, and you can see why I’m a happy camper.

Magnolia Content Management System

Content Management Systems for J2EE are hard to come by, but Magnolia looks quite promising. I was particularly impressed by their Web user interface. A live demo of Magnolia is available on their web site.

Getting Magnolia to work under Resin is not difficult per se, but the lack of documentation and resources turned it into a week long affair. The magnolia double period bug report proved useful, and a little bit of twiddling using a similar JBoss configuration and JBoss installation eventually yielded a successful outcome. A Magnolia Wiki entry is definitely in order.

HSQLDB Lightweight Database Engine

It’s no surprise that databases are an integral part of Enteprise systems. And more often than not, Java developers will either use JDBC, directly or indirectly, to connect and interface with them. But for simply learning the JDBC interface, setting up an entire database server such as PostgreSQL or MySQL can be tiring. That’s where the HSQL Database Engine comes in. HSQL is a lightweight Java database engine that uses flat files and offers several connection modes including a simple, in-process, standalone mode that I’ll utilize today.

Installing HSQL is simply a matter of extracting the compressed archive and dropping the hsqldb.jar package in your library directory. Next, create a sample database by invoking the DatabaseManager:

java -cp hsqldb.jar org.hsqldb.util.DatabaseManagerSwing

Set the connection type to standalone and set the database/path to the location of your flat file directory. If the database does not exist, it will be created automatically.

Connect to the database. Select the options menu, and then insert test data. This will populate the database with some workable data and save us some time. Close the DatabaseManager application.

Now you’re all set to go. Sun has a great introductory JDBC Tutorial and the PostgreSQL JDBC Interface has additional information. I’ll finish by providing a small JDBC example, minus the exception handling, to get you started:

import java.sql.*;

final String URL = "jdbc:hsqldb:file://tmp/test";
Class.forName("org.hsqldb.jdbcDriver");
Connection c =
   DriverManager.getConnection(URL, "sa", "");

Statement st = c.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM Customer");

while (rs.next()) {
        /* print */
}

Hello Servlet in Tomcat

Getting a basic Hello World servlet up and running is not an easy task, primarily because much of information on the Web is out of date, and because servlet container implementations are not as standardized as they could be. In this entry, I get a basic Tomcat servlet up and running, and point out some of the traps and pitfalls I encountered along the way.

Most older tutorials will say that servlets are automatically and dynamically loaded if /servlet is specified before the name of the servlet. That’s not entirely true. In recent versions of Tomcat, the run-time invoker is disabled by default due to potential security risks. But in my opinion, it’s perfectly acceptable to enable in a testing environment when you’re twiddling with code. To turn it on, uncomment the following from server.xml:

<servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
        org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
</servlet>

Also uncomment the servlet mapping:

<servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

The servlet itself is not difficult to write. Place HelloWorldServlet.java in your WEB-INF/classes directory, though be sure to first setup a web context:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorldServlet extends HttpServlet {

  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
                    throws IOException, ServletException
  {
     response.setContentType("text/html");
     PrintWriter out = response.getWriter();
     out.println("<html>");
     out.println("<head>");
     out.println("<title>HelloWorldServlet</title>");
     out.println("</head>");
     out.println("<body><h1>Hello World</h1></body>");
     out.println("</html>");
  }
}

To compile, use the CLASSPATH option and point it to the servlet-api jar file distributed with your Tomcat installation. Tomcat 5 on Linux Step-by-Step is an excellent resource for additional information.

Random Futurama Quotes in Slashdot Headers

I just noticed that Slashdot has hidden Futurama quotes in the HTTP headers. You can view the headers using Delorie Headers or Rex Swain’s HTTP Viewer:

HTTP/1.1 200 OK
Date: Sat, 05 Mar 2005 22:22:30 GMT
Server: Apache/1.3.33 (Unix) mod_gzip/1.3.26.1a
   mod_perl/1.29
SLASH_LOG_DATA: shtml
X-Powered-By: Slash 2.003000
X-Bender: I'm tired of this room and everyone in it!
Cache-Control: private
Pragma: private
Connection: close
Content-Type: text/html; charset=iso-8859-1

Neat. I’m thinking of doing something similar with the use of the PHP header command.

Developing With Flex

The great thing about my job is that it affords me the opportunity to get a look at the latest technologies in the Enterprise market. Today I stumbled on Macromedia Flex, a presentation-tier solution for delivering Rich Internet Applications. While I don’t see it taking off in the consumer and end-user market, there’s a lot of potential here for enterprise-class business process automation. The Flex programming model is a lot like what the Mozilla project is trying to accomplish: using a simple scripting language and XML to design rich user interfaces as an alternative to the limited HTML form specification.

There’s also a wealth of Flex Documentation available on the Macromedia site. Flash has somewhat of a negative stigma, but I hope that you’ll change your mind after examining some of these Flex demos.

PostgreSQL

I finally got around to installing PostgreSQL after carefully following the PostgreSQL Fedora installation instructions. It works out of the box with UNIX domain sockets, but Aqua Data Studio requires a TCP/IP connection in order to successfully connect to the database. Fortunately, it’s not too difficult to do. First, modify the pg_hba.conf file in /var/lib/pgsql/data and enable local connections. Next, open postgresql.conf and set tcpip_socket to true. Finally, restart the server.

pgsql.png PostgreSQL is a highly-scalable, SQL compliant, open source object-relational database management system. I’m looking forward to using it in our future production systems. It’s an excellent, viable alternative to Microsoft SQL Server.

Comcast Speed Updates

A few days ago I noticed that I was pulling nearly 512 KB off Giganews. It turns out that Comcast has recently offered a speed increase update to Atlanta area customers. To activate, simply power-cycle your modem:

To power-cycle your modem, turn off your computer, unplug the power cord to the modem, wait 1 minute, re-connect power cord to the modem and wait for modem to come back online), then restart the computer.

DSL Reports has more details, scattered throughout their forums.