• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Exception handling not working

 
Greenhorn
Posts: 8
Netbeans IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
Netbeans IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
Netbeans IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 8
Netbeans IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic