wood burning stoves*
The moose likes Servlets and the fly likes Servlet Exception handling not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Exception handling not working" Watch "Servlet Exception handling not working" New topic
Author

Servlet Exception handling not working

John Dalenson
Greenhorn

Joined: Feb 07, 2012
Posts: 8

Hi,

I have a simple web application with one servlet, webservice util class. I am handling the exception using deployment descriptor properties. I have a try-catch with Throwable to catch everything and re-throw as ServletException wrapped object. But, when webservice class throws nullpointerException/javax.xml.ws.soap.SOAPFaultException, they aren't handled correctly. It doesn't forward to error.jsp.

When I throw new exception in case of validation failure, the error page works fine.

Here is my code:-



My web.xml:-



Thanks,

John
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
How does SOAP get involved with this application?

Generally speaking SOAP requests go to some SOAP specific servlet code. I would bet you have a SOAP specific web application installed elsewhere on the server which is why it does not use your error page.

Bill
John Dalenson
Greenhorn

Joined: Feb 07, 2012
Posts: 8

William Brogden wrote:How does SOAP get involved with this application?

Generally speaking SOAP requests go to some SOAP specific servlet code. I would bet you have a SOAP specific web application installed elsewhere on the server which is why it does not use your error page.

Bill


This webapplication is intended to download a document using webservices and then put the byte array into the HttpServletResponse for the users to view it. I don't have other servlet for this webservice client.

This is the processRequest method in my servlet. Can you please tell me if there is a better way to implement this?



Whenever there is any exception in WebserviceClient class, it is propagated to this servlet. I see the following error in the log as well.

SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.jsp]
java.lang.IllegalStateException
at org.apache.coyote.Response.reset(Response.java:297)
at org.apache.catalina.connector.Response.reset(Response.java:653)
at org.apache.catalina.connector.Response.reset(Response.java:920)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:357)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:213)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)

Thanks,
John
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Looks to me like that last error is being thrown by the error page (error.jsp) itself, which would explain why it appears not to be called.

"IllegalStateException" suggests to me that that the error page is unable to run because your servlet has already committed the response, but just the code doesn't confirm that. It would help to know what exception the servlet threw and what line of code threw it.
John Dalenson
Greenhorn

Joined: Feb 07, 2012
Posts: 8

Paul Clapham wrote:Looks to me like that last error is being thrown by the error page (error.jsp) itself, which would explain why it appears not to be called.

"IllegalStateException" suggests to me that that the error page is unable to run because your servlet has already committed the response, but just the code doesn't confirm that. It would help to know what exception the servlet threw and what line of code threw it.


Thanks for the reply. This is the line which threw exception:


Since, I did't catch it in that method, it propagates to the following method:


I catch it here and wrap it in ServletException and throw it to the container to handle it. My error page is very simple.



I don't have any other forward or redirect which is puzzling because the exception suggests otherwise.

The error page works fine when the exception happens within servlet, but it doesn't work when the exception is thrown in the webservice client class and let it propagated to the servlet.

John
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5

Your origininal post included:

webservice class throws nullpointerException/javax.xml.ws.soap.SOAPFaultException


I asked what SOAP had to do with your application and you still have not answered that question.

Where is SOAP involved?

Bill
John Dalenson
Greenhorn

Joined: Feb 07, 2012
Posts: 8

William Brogden wrote:
Your origininal post included:

webservice class throws nullpointerException/javax.xml.ws.soap.SOAPFaultException


I asked what SOAP had to do with your application and you still have not answered that question.

Where is SOAP involved?

Bill


Bill,

The class WebserviceClient call a webservice on the remote server using SOAP over HTTP. That is why i had included the SOAPFaultException in my original post.

I have found the problem in the code and it is working fine now. The problem was outputStream = response.getOutputStream();. I was getting the outputStream before ArrayList downloadDataContents = wsClient.downloadDocument(Integer.parseInt(nodeId), Integer.parseInt(versionNo), app); which was causing the response to be committed. So, in case of any exception from the wsClient, I was getting IllegalStateException because of the "already committed response".

I moved the response.getOutputStream after the webservice client call and it solved the problem. My error forwarding is working properly.

Thanks,
John
 
 
subject: Servlet Exception handling not working
 
Similar Threads
how to know which servlet/jsp calling a particular servlet
JSF : redirect errors to error page
getting error when deploying web app in weblogic 10.0
Servlet Error Code
Help executing an EJB persistence application