Playframework 2.0 onError get request body

时间:2013-01-24 13:01:27

标签: java error-handling request playframework-2.0

我已经覆盖了方法public Result onError(RequestHeader rh, Throwable t),但此类RequestHeader似乎没有保存请求正文 - API

有人知道如何获取请求正文吗?

1 个答案:

答案 0 :(得分:4)

简单的解决方案 - 我覆盖了public Action<?> onRequest(Request request, Method actionMethod)我保存RequestBody的地方onError

:)

private RequestBody lastBody;

@Override
public Action<?> onRequest(Request request, Method actionMethod) {
    lastBody = request.body();
    return super.onRequest(request, actionMethod);
}

@Override
public Result onError(RequestHeader rh, Throwable t) {  
    //here i can get the body
    System.out.println(lastBody);

    return play.mvc.Results.internalServerError(errorPage.render());
}