Hello everyone,
I have some code to contribute. I was going over configuring Turbine and
working out some bugs in my configuration and thought I would pass on some
timesaving code... Anyway here it goes.

In the servlet init() we load the TurbineResources.properties file. Just
the simple act of doing this simple procedure can fail in multiple ways.
I found four ways the code can fail, three of which are already checked
for in Turbine. The problem is that there is one error message. 

I broke this error down into four conditional checks with four separate
error messages, each error message has a recommended course of action.

1. 
Error: "properties" initialization parameter does not exist. 
Recommended Action: Add the following line to the
zone.properties file: 
'servlet.Turbine.initArgs=properties=/path/to/TurbineResources.properties'

2.
Error: "properties" initialization parameter is zero length.
Recommended Action: Add the following line to the 
zone.properties file:
'servlet.Turbine.initArgs=properties=/path/to/TurbineResources.properties'

3.
Error: The file specified in the "properties" initialization parameter
does not exist.
Recommended Action: Verify that the file exists. File name is
included in error message.

4.
Error: The file specified in the "properties" initialization parameter is
not readable.
Recommended Action: Change permissions on the file. File name is included
in the error message. User name of the user running the JServ process is
included in the error message.



I log the error to the servlet log file, but also throw a
ServletException. This gives the user the Internal Server Error every time
the properties file is unsuccessfully loaded. This is ugly, but it does
not lull the administrator into a sense that everything loaded properly
and gives the administrator another log file (mod_jserv.log) to look into. 

Some people like myself are having logging issues with the java side of
JServ. This is an issue with JServ and I will take it to the JServ list,
but fixing
logging issues are low on my list of priorities so I decided to throw the
Servlet Exception and get the info into the mod_jserv.log

I figure throwing the exception is safe since Turbine is probably not
going to work properly without the TurbineResources.properties file. I
will admit the Internal Server Error is a bit ugly to receive, but IMHO it
helps in debugging the configuration.

Could I get a vote on throwing the ServletException? What does everyone
else think.


<background ON="ERRORS AND CODE FAILURE">
A power user friend of mine once commented how great computers are when
they work but what a terrible mess debugging things can become. They went
on to say they felt almost always like they needed a degree to read the
error messages. 

For this person that meant getting IT and tech support for their purchased
software. This always cost time and money to her department. Frequently
taking days for things to get resolved.

The Morale: If we can code into our programs some simple signposts for the
user to go by when things go wrong we can help solve in minutes problems
that might have otherwise taken hours or days. This is however not simple.
The five lines of original code to load the properties file is now over a
page long.

In a world where IT departments are under the gun to get projects done
yesterday, it is to our advantage to get think about what happens when
things go wrong.

</background>

I would like to become the bells/whistles/usability guru for turbine and
possibly JServ and Jakarta. Here are the diffs for your perusal.


------------------------------------------------------------------------
Index: turbine/src/java/Turbine.java
===================================================================
RCS file: /products/cvs/turbine/turbine/src/java/Turbine.java,v
retrieving revision 1.27
diff -r1.27 Turbine.java
110c110
<         if ( props == null || props.length() == 0 || ! new File(props).exists() )
---
>         if ( props == null)
112,113c112,146
<             log ( "Properties file not found: " + props );
<             return;
---
>             log("Turbine::init(ServletConfig) - 'properties' Init Parameter" +
>                    " not found. Please specify a value for the 'properties'" +
>                    " Init Parameter by editing the servlet zone properties " +
>                    "file.  This is done by adding the " +
>                    "following line to the zone properties file: \n" +
>                    "servlet.Turbine.initArgs=properties=" +
>                    "/path/to/TurbineResources.properties");
>                    
>             throw new ServletException(       
>                    "Turbine:init(ServletConfig) - 'properties' Init Parameter" +
>                    " not found. Please specify a value for the 'properties'" +
>                    " Init Parameter by editing the servlet zone properties " +
>                    "file.  This is done by adding the " +
>                    "following line to the zone properties file: \n" +
>                    "servlet.Turbine.initArgs=properties=" +
>                    "/path/to/TurbineResources.properties");
>         }
>         else if(props.length() == 0)
>         {
>             log("Turbine::init(ServletConfig) - 'properties' Init Parameter" +
>                    " value is empty. The 'properties' Init Parameter exists" +
>                    " but it is a zero length string. Please specify a value "
>                    + "for the 'properties' Init Parameter. This is done by " +
>                    "adding the following line to the zone properties file: \n"
>                    + "servlet.Turbine.initArgs=properties=" + 
>                    "/path/to/TurbineResources.properties");
>                    
>             throw new ServletException(       
>                    "Turbine::init(ServletConfig)- 'properties' Init Parameter" +
>                    " value is empty. The 'properties' Init Parameter exists" +
>                    " but it is a zero length string. Please specify a value "
>                    + "for the 'properties' Init Parameter. This is done by " +
>                    "adding the following line to the zone properties file: \n"
>                    + "servlet.Turbine.initArgs=properties=" + 
>                    "/path/to/TurbineResources.properties");
114a148,163
>         else if(!(new File(props).exists()))
>         {
>             log("Turbine::init(ServletConfig) - The Turbine Resources Property"
>                    + " file - '" + props + "' does not exist.");
>             throw new ServletException(
>                    "Turbine::init(ServletConfig) - The Turbine Resources " +
>                    "Property"
>                    + " file - '" + props + "' does not exist.");
>         }
>         else if(!(new File(props).canRead()))
>         {
>             log("Turbine::init(ServletConfig) - The Turbine Resources Property"
>                    + " file - '" + props + "' is not readable by user " +
>                    "'" + System.getProperty("user.name") + "'. Please change"
>                    + " permissions on the file. In UNIX this is done by " +
>                    "executing the chmod command."); 
115a165,172
>             throw new ServletException(
>                    "Turbine::init(ServletConfig) - The Turbine Resources " +
>                    "Property" +
>                    " file - '" + props + "' is not readable by user " +
>                    "'" + System.getProperty("user.name") + "'. Please change"
>                    + " permissions on the file. In UNIX this is done by " +
>                    "executing the chmod command."); 
>         }           
164a222
>             



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to