Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring mvc jackson: log data

I have a question regardimg spring mvc and jackson mapper: every time I call a rest service passing a wrong json (empty, wron params,...) the client correctly receives an error, but there is no way to see in detail the call on server side. Is there a way to log in a proper way this information?

Thanks in advance for the help.

Fabio

like image 956
Pirulino Avatar asked Feb 07 '14 18:02

Pirulino


1 Answers

A good place to start looking into the marshalling process is AbstractMessageConverterMethodProcessor.writeWithMessageConverters - that will give you a good overview of what's being executed.

As for the logging aspect, the first catch of the entire marshalling/unmarshalling process is ServletInvocableHandlerMethod.invokeAndHandle:

catch (Exception ex) {
   if (logger.isTraceEnabled()) {
      logger.trace(getReturnValueHandlingErrorMessage("Error handling return value", returnValue), ex);
   }
   throw ex;
}

So - enabling TRACE in your logging configuration here - on org.springframework.web.servlet.mvc.method.annotation will give you the info you need.

Further on, another good place to catch this kind of logging output - this time with DEBUG instead of TRACE is: DispatcherServlet.processHandlerException.

Hope this helps.

like image 112
Eugen Avatar answered Nov 05 '22 04:11

Eugen