Logging json posts with resteasy

前端 未结 2 1267
醉梦人生
醉梦人生 2021-01-18 11:53

I\'m looking for a way to log JSON posts in a RESTEASY framework.

I woul like to log the POST body to log file to see what the client is sending to me.

Is t

2条回答
  •  执念已碎
    2021-01-18 12:34

    As supplement of excellent answer of lefloh, I suggest replace:

    !MediaType.APPLICATION_JSON_TYPE.equals(requestContext.getMediaType())
    

    with

    !MediaType.APPLICATION_JSON_TYPE.isCompatible(requestContext.getMediaType())
    

    equals method takes into account parameters of media type, eg. charset=UTF-8, and does not work in some scenarios according to intention of lefloh. isCompatible compares only type and subtype of media type and is more suitable in this case.

    PS. I know, this post should be placed as comment, but I have no enough level of reputation to do it. I also edited lefloh answer but some php and ios guys rejected it.

提交回复
热议问题