aspose file tools*
The moose likes Tomcat and the fly likes How to catch ClientAbortException in Tomcat hosted servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to catch ClientAbortException in Tomcat hosted servlets" Watch "How to catch ClientAbortException in Tomcat hosted servlets" New topic
Author

How to catch ClientAbortException in Tomcat hosted servlets

Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
Hi all,

(hope this is the correct forum...servlets was a contender...would not be surprise if it was moved, but i am pretty sure my question is tomcat specific)

How do I catch org.apache.catalina.connector.ClientAbortException? It is a subclass of IOException, which I am catching, but I'd like to be more specific so I can just log a debug or info entry as ClientAbortException are likely to occur somewhat often in my application.

On my dev platform (Java 5, Tomcat 5.5, Eclipse 3.2) it all works good after including catalina.jar in my project. But when I deploy the project I get dependencies errors, to my surprise.

Any pointers?

tia,

Stu


"This is not to say that design is unnecessary. But after a certain point, design is just speculation." --Philip Chu
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
Looking at the source code, there is nothing magical about ClientAbortException, it just extends IOException and does not add anything special.

You should be able to get at the Throwable cause and the String message with normal Exception methods.
getRootCause()
getMessage()

printStackTrace could be useful too.

Bill


Java Resources at www.wbrogden.com
Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
Hi Bill,

I should have included some code in the original post. It was just getting a bit long as it was. Let me correct that:



See, my ClientAbortException is an expected event. I don't really want to know about it. But any other IOException is noteworthy and should be logged.

To specifically catch the ClientAbortException I brought catalina.jar into my project's classpath. But when I deploy the servelet I get a dependancy issues...the webapp is marked as unavailable because it cannot resolve ClientAbortException It would seem unwise and incorrect to add a copy of catalina.jar to my ./WEB-INF/lib folder.

Stu
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
That would indicate that your deployment environment is somehow different from your compilation environment. Exactly what is the error message?

The comments in the ClientAbortException source indicate it was last changed in August 2005. What is your deployment environment?

Bill
Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
Yea, the thought crossed my mind. I am pretty keen on development/production consistancy but have double checked and confirmed explicately that both versions are 5.5.17. (April 2006)

The error with ClientAbortExcpetion catch block:



My googles have been fruitless.

Thanks for your time and effort. Appreciated.

Stu
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
Now I'm mystified totally and I am reduced to asking really simple minded questions.
1. If you remove that exception reference can you deploy the servlet?
2. If that code is in your actual servlet class as it appears from that stack trace due to servlet instance construction, what happens if you remove it to a helper class that will only be created on demand?
Bill
Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
1. If you remove that exception reference can you deploy the servlet?


Yup, it works. That was my first debugging move after seeing the class definition error.

If that code is in your actual servlet class as it appears from that stack trace due to servlet instance construction, what happens if you remove it to a helper class that will only be created on demand?


Interesting idea. After moving all the logic to a seperate ReadAndSpew class and having the actual servelet FileServer class (that extnends HttpServlet) and instances ReadAndSpew on each doGet() method call...it blows up with the same ClientAbortException class definition exception when attempting to create a ReadAndSpew instance.

Perplexed.

Thanks again,

Stu

[ November 27, 2006: Message edited by: Stu Thompson ]
[ November 27, 2006: Message edited by: Stu Thompson ]
Stu Thompson
Hooplehead
Ranch Hand

Joined: Jun 14, 2006
Posts: 136
BTW, here is the actual 'new' excpetion error log.



Edit: Ho, hum...a friend of mine who I just consulted on this has chastised me for writing tightly coupled container-specific code :roll: which is a good point. I think for now I am going to write some code that inspects ioe.getClass().getName() which will loosen things up a bit.

Not knowing why my dev environment is working and production not will bother me for ages. I might even reinstall the dev environment to re-standardize my development space.

Thanks for your help, though!

Stu

[ November 27, 2006: Message edited by: Stu Thompson ]
[ November 27, 2006: Message edited by: Stu Thompson ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
You have certainly nailed it down with those tests.
I am reduced to suggesting that the Tomcat JVM is finding the package org.apache.catalina.connector
in another, much older Jar file somewhere which does not contain that class.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to catch ClientAbortException in Tomcat hosted servlets
 
Similar Threads
Starting new project Tomcat
Tomcat and multiple eclipse projects ... desperate ! please help ...
Connection Pooling in tomcat
help in dynamic deployment
simple project