You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/06/01 16:05:53 UTC

Seeking Advice Error Handling

Hello,

I have created a site with a mysql database back-end, and full struts front end. I have a filter to ensure the creation of some session app objects, and the site is pretty clean.

But over the weekend, I found a problem that I am seeking advice from. For some reason, the mysql database went down, causing the site to be all screwed up. I have extended the RequestProcessor but can not figure out how to handle errors from the database.

I would like to in the requestProcessor extended class, possibly do a simple query against a known table, and if the result is null, switch them to a site down action class.

Can this be done in the requestProcessor area?

Any advice would be appreciated.

Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Seeking Advice Error Handling

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Scott Purcell" <sp...@vertisinc.com>
> I have created a site with a mysql database back-end, and full struts
front end. I have a filter to
> ensure the creation of some session app objects, and the site is pretty
clean.
>
> But over the weekend, I found a problem that I am seeking advice from.
> For some reason, the mysql database went down, causing the site to be all
screwed up.
> I have extended the RequestProcessor but can not figure out how to handle
errors from the database.

First, are you saying that you had database problems in the Filter code?  If
so, if it throws an exception that request will never make it to Struts.
You can configure some error handling in web.xml, but the location has to be
'a resource within the webapp' which IME seems to mean a JSP or HTML page.
(I have not tried sending them to an Action, but a Tiles def doesn't work in
web.xml.)

I don't know about extending the RequestProcessor, but you can "catch"
exceptions by using the <exception> tag in struts-config.xml.  Google for
'struts declarative exception handling' for more info.

I use it very simply, with an <exception> tag nested in the <action>
mapping:
 <exception type="edu.example.dao.DAOException"
               key="error.dao.exception"
               path="den.exception"/>
(den.exception is a Tiles definition.)

You can write your own ExceptionHandler if you need to do more than send
them to a page.


HTH,
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Seeking Advice Error Handling

Posted by Mark Benussi <ma...@hotmail.com>.
Vote +1

Scott if you want to know if your database is down and then turn it off as a 
service you can do this via an inner TimerTask. I implement somthing along 
the lines of if the database is down, set its status as down with my service 
manager.

Then you can write code to check the service manager before displaying 
database functionality if you really want to.


----Original Message Follows----
From: Dakota Jack <da...@gmail.com>
Reply-To: Dakota Jack <da...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Subject: Re: Seeking Advice Error Handling
Date: Wed, 1 Jun 2005 07:33:31 -0700

Hi, Scott,

Wherever you access the database and encounter the error is where the
error should be handled.  A rule-of-thumb I employ is to handle all
errors as soon as possible and as near to the actual error as
possible.  I think that testing to see if your database is working is
not a good idea.  You have to assume that your database is working and
then handle what to do if it is not.

Depending on some subclass of RequestProcessor really weds your code
to Struts in a way that is not good in my opinion.  If you handle the
error where it happens, then that should cover you completely.  Your
response to an error should be, I think, with a different
ActionForward and not with a different (chained) Action.  Thus, the
sequence would be: (1) use Action, (2) hand off to business logic, (3)
access to database, (4) FAILURE and consequent handling of error back
to the Action which then uses a (5) "failure" ActionForward with an
ActionMessage or ActionError delineating what happened to the client.

On 6/1/05, Scott Purcell <sp...@vertisinc.com> wrote:
 > Hello,
 >
 > I have created a site with a mysql database back-end, and full struts 
front end. I have a filter to ensure the creation of some session app 
objects, and the site is pretty clean.
 >
 > But over the weekend, I found a problem that I am seeking advice from. 
For some reason, the mysql database went down, causing the site to be all 
screwed up. I have extended the RequestProcessor but can not figure out how 
to handle errors from the database.
 >
 > I would like to in the requestProcessor extended class, possibly do a 
simple query against a known table, and if the result is null, switch them 
to a site down action class.
 >
 > Can this be done in the requestProcessor area?
 >
 > Any advice would be appreciated.
 >
 > Scott
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
 > For additional commands, e-mail: user-help@struts.apache.org
 >
 >


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Seeking Advice Error Handling

Posted by Dakota Jack <da...@gmail.com>.
Hi, Scott,

Wherever you access the database and encounter the error is where the
error should be handled.  A rule-of-thumb I employ is to handle all
errors as soon as possible and as near to the actual error as
possible.  I think that testing to see if your database is working is
not a good idea.  You have to assume that your database is working and
then handle what to do if it is not.

Depending on some subclass of RequestProcessor really weds your code
to Struts in a way that is not good in my opinion.  If you handle the
error where it happens, then that should cover you completely.  Your
response to an error should be, I think, with a different
ActionForward and not with a different (chained) Action.  Thus, the
sequence would be: (1) use Action, (2) hand off to business logic, (3)
access to database, (4) FAILURE and consequent handling of error back
to the Action which then uses a (5) "failure" ActionForward with an
ActionMessage or ActionError delineating what happened to the client.

On 6/1/05, Scott Purcell <sp...@vertisinc.com> wrote:
> Hello,
> 
> I have created a site with a mysql database back-end, and full struts front end. I have a filter to ensure the creation of some session app objects, and the site is pretty clean.
> 
> But over the weekend, I found a problem that I am seeking advice from. For some reason, the mysql database went down, causing the site to be all screwed up. I have extended the RequestProcessor but can not figure out how to handle errors from the database.
> 
> I would like to in the requestProcessor extended class, possibly do a simple query against a known table, and if the result is null, switch them to a site down action class.
> 
> Can this be done in the requestProcessor area?
> 
> Any advice would be appreciated.
> 
> Scott
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Seeking Advice Error Handling

Posted by Martin Gainty <mg...@hotmail.com>.
Scott-

/*courtesy of W.L. daSilva 
http://www.informit.com/articles/article.asp?p=23734&redir=1*/
Using this sample for your struts-config.xml
<data-sources>
  <data-source
    autoCommit="false"
   description="First Database Config"
   driverClass=" org.gjt.mm.mysql.Driver"
     maxCount="4"
     minCount="2"
     password="admin"
       url="jdbc:mysql://localhost/ARTICLEDB"
       user="admin"
  />
</data-sources>

Confirm the mySQL information from my.cnf is represented accurately in your 
data-sources <data-source> is correct

Confirm that mysql database listener is indeed listening on the port 
idenitified by my.cnf (netstat -a)

verify struts-config.xml data-sources <datasource> information is correct 
for your installation (see above)

and log everything that is happening within your ActionServlet 
InitModuleDataSources

HTH,
Martin-

----- Original Message ----- 
From: "Scott Purcell" <sp...@vertisinc.com>
To: <us...@struts.apache.org>
Sent: Wednesday, June 01, 2005 10:05 AM
Subject: Seeking Advice Error Handling


Hello,

I have created a site with a mysql database back-end, and full struts front 
end. I have a filter to ensure the creation of some session app objects, and 
the site is pretty clean.

But over the weekend, I found a problem that I am seeking advice from. For 
some reason, the mysql database went down, causing the site to be all 
screwed up. I have extended the RequestProcessor but can not figure out how 
to handle errors from the database.

I would like to in the requestProcessor extended class, possibly do a simple 
query against a known table, and if the result is null, switch them to a 
site down action class.

Can this be done in the requestProcessor area?

Any advice would be appreciated.

Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Seeking Advice Error Handling

Posted by gd...@cmhc-schl.gc.ca.
In what application server is your application running?
Do you have any connection pooling?

- Glenn




"Scott Purcell" <sp...@vertisinc.com> 
01/06/2005 10:05 AM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
<us...@struts.apache.org>
cc

Subject
Seeking Advice Error Handling






Hello,

I have created a site with a mysql database back-end, and full struts 
front end. I have a filter to ensure the creation of some session app 
objects, and the site is pretty clean.

But over the weekend, I found a problem that I am seeking advice from. For 
some reason, the mysql database went down, causing the site to be all 
screwed up. I have extended the RequestProcessor but can not figure out 
how to handle errors from the database.

I would like to in the requestProcessor extended class, possibly do a 
simple query against a known table, and if the result is null, switch them 
to a site down action class.

Can this be done in the requestProcessor area?

Any advice would be appreciated.

Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org