• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unavailable Exception Problem

 
Meng Tan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was not able to get the error page indicated in the web.xml to be displayed when an unAvailableException is thrown in a servlet.
My web.xml contains:
<error-page>
<exception-type>
javax.servlet.UnavailableException
</exception-type>
<location>
/MyException.html
</location>
</error-page>
My servlet's doGet() method contains:
throw new UnavailableException("Unavailable Exception thrown");
The funny thing is that is u replace UnavailableException with ServletException in both the web.xml and the Servlet code, it works fine.
Please help!!!
 
Kevin Yip
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the doGet() throw ServletException or UnavailableException? According to your description, I think it's the former.
To make your original code to work, you may try:
doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, UnavailableException { ... }
 
Meng Tan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin,
u r right.
I didnt throw UnavailableException in my doGet() method, instead I throw ServletException.
This causes the server not to capture the ServletException because I indicate the <exception-type> in web.xml as UnavailableException.
However, when I try the following case, it didnt work:
Web.xml:
<error-page>
<exception-type>
javax.servlet.ServletException
</exception-type>
<location>
/MyException.html
</location>
</error-page>
Servlet:
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
throw new UnavailableException("My Message");
}
Please advise.
Thanks a lot.
 
Jim Bertorelli
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe, if you throw UnavailabeException and specify it in the deployment descriptor, it should work...exactly as you've mentioned in the first post. If it is not working either there some typo or there is a bug.
Try <exception-type>javax.servlet.UnavailableException</exception-type>
instead of
<exception-type>
javax.servlet.UnavailableException
</exception-type>
 
Kevin Yip
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a second thought, I agreed with Jim. You original code should be fine. However, there is something particular for the UnavailableExcpetion. Here is what SRV.2.3.3.2 of the 2.3 specification said:
"If a permanent unavailability is indicated by the UnavailableException, the
servlet container must remove the servlet from service, call its destroy method,
and release the servlet instance."
If the servlet is released immediately, even before throwing out the Exception object from its doGet() method, this may explain your situation.
 
Jim Bertorelli
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah...that might be it. Try defining another exception that extends from ServletException and see if it works.
 
Kevin Yip
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried NumberFormatException ( a subclass of java.lang.RuntimeException), java.net.MalformedURLException (a subclass of IOException), ServletException, and a subclass MyException, as defined below:

All works fine. Only UnavailableException is not working.
 
Meng Tan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have also tried MyUnavailableException (a subclass of UnavailableException) and the error page indicated in the deployment descriptor does not show. Instead, the server sends its own 503 Unavailable page.
I think that the <error-page> tag in web.xml will not work (ie. the page in <location> tag will not display) when the exception thrown in the servlet is UnavailableException or its subclass.
I have been following Java Servlet Programming book and it seems to suggest that the <exception-type> tag works for UnavailableException also. Not too sure.
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic