I wanted all my exceptions to be logged. I thought thought that adding Logger.error
to every method would solve my problem, but luckily I discovered HandlerInterceptorAdapter
and saved time!
Now I don't want to return "regular" objects, but to return an object that contains other objects and exceptions. The reason is that in this way, I won't get HTTP Status 500
, but get an object containing the exception.
Basically: If my service would return normally - return an object containing the returned object.
If my service would return with an exception - return an object that has the children up to the exception, and the exception that caused the problem.
I hoped that using HandlerInterceptorAdapter
would be easy, but I was mistaken...
In a regular service - If I look at postHandle: modelAndView
is null.
In both postHandle
and afterCompletion
using response.getWriter().write(s)
raises
SEVERE: Servlet.service() for servlet [appServlet] threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
response.getHeaderNames()
contains only [Content-Type, Transfer-Encoding, Date].
I don't know what to do with response.getOutputStream().
Using request
/handler
gets me to no where also.
What can I do?
Aucun commentaire:
Enregistrer un commentaire