给大家推荐两个小众的精品:
logbook: An extensible Java library for HTTP request and response logging, 可以生成很漂亮的 http 请求和响应的日志,辅以日志过滤,脱敏等功能。
如 json 格式的 http 请求和响应
{
"origin": "remote",
"type": "request",
"correlation": "2d66e4bc-9a0d-11e5-a84c-1f39510f0d6b",
"protocol": "HTTP/1.1",
"sender": "127.0.0.1",
"method": "GET",
"uri": "
http://example.org/test",
"host": "
example.org",
"path": "/test",
"scheme": "http",
"port": null,
"headers": {
"Accept": ["application/json"],
"Content-Type": ["text/plain"]
},
"body": "Hello world!"
}
{
"origin": "local",
"type": "response",
"correlation": "2d66e4bc-9a0d-11e5-a84c-1f39510f0d6b",
"duration": 25,
"protocol": "HTTP/1.1",
"status": 200,
"headers": {
"Content-Type": ["text/plain"]
},
"body": "Hello world!"
}
围观---->
https://github.com/zalando/logbookproblem: is a library that implements application/problem+json 。 能够生成漂亮的 Json 异常信息。对了 jhipster 默认就使用了它。
例如:
Problem.builder()
.withType(URI.create("
https://example.org/out-of-stock"))
.withTitle("Out of Stock")
.withStatus(BAD_REQUEST)
.withDetail("Item B00027Y5QG is no longer available")
.with("product", "B00027Y5QG")
.build();
生成为这样的异常消息:
{
"type": "
https://example.org/out-of-stock",
"title": "Out of Stock",
"status": 400,
"detail": "Item B00027Y5QG is no longer available",
"product": "B00027Y5QG"
}
围观----->
https://github.com/zalando/problem