【问题标题】:Grails 2.4.4 request object loggingGrails 2.4.4 请求对象日志记录
【发布时间】:2018-06-27 09:29:26
【问题描述】:

我需要记录传入的 REST 请求 (xml)。 所以我创建了一个

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;
    }
}

现在我使用过滤器来注销传入的请求:

class XmlogFilterFilters {

def filters = {
    all(controller:'*', action:'*') {
        before = {
            RequestWrapper wrappedRequest = new RequestWrapper(request)
            log.info(wrappedRequest.reader.text)
        }
    }
}

这会按预期记录传入的请求。

但现在在我的控制器中,请求是空的,不能用于构建我的域对象:

 class InquiryHandlerController {
  def save(Inquiry inquiryInstance) {
   ... *** inquiryInstance is null here
  }
 }

我猜问题是,这个请求已经在RequestWrapper 中被读取,因此无法在magic requestToDomain 转换中再次读取。

那么我怎样才能将新的RequestWrapper Object 而不是原来的request 传递给控制器​​呢?

【问题讨论】:

    标签: grails grails-2.0


    【解决方案1】:

    终于找到了解决办法:

    使用 grailsplugin:1.1 版中的 grails-httplogger 做了正确的包装,所以日志和消费现在可以工作了。 https://github.com/prumps/grails-httplogger

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 2012-11-07
      • 1970-01-01
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多