I need to log the incomming REST request (xml). So I create a
public class RequestWrapper extends HttpServletRequestWrapper {
private String _body;
public RequestWrapper(HttpServletRequest request) throws IOException {
super(request);
_body = "";
BufferedReader bufferedReader = request.getReader();
String line;
while ((line = bufferedReader.readLine()) != null){
_body += line;
}
}
Now I use a filter to log out the incomming request:
class XmlogFilterFilters {
def filters = {
all(controller:'*', action:'*') {
before = {
RequestWrapper wrappedRequest = new RequestWrapper(request)
log.info(wrappedRequest.reader.text)
}
}
}
This logs the incomming request as expected.
But now in my controller the request is empty and cannot be used to Build my Domain-Object:
class InquiryHandlerController {
def save(Inquiry inquiryInstance) {
... *** inquiryInstance is null here
}
}
I guess the problem is, that th request was already read in the RequestWrapper
, and therefor cannot be read again in the magic requestToDomain conversion.
So how can I pass the new RequestWrapper Object
instead of the original request
to the controller?
Finally found a solution:
use grailsplugin: grails-httplogger in version 1.1 do the right wrapper thing, so logging and consuming is working now. https://github.com/prumps/grails-httplogger