【发布时间】:2016-02-13 11:31:18
【问题描述】:
我有一个带有很多方法的 RESTEasy Web 服务器。我想实现 logback 来跟踪所有请求和响应,但我不想将log.info() 添加到每个方法中。
也许有办法在一个地方捕获请求和响应并记录下来。可能类似于 RESTEasy 上的 HTTP 请求流程链上的过滤器。
@Path("/rest")
@Produces("application/json")
public class CounterRestService {
//Don't want use log in controler every method to track requests and responces
static final Logger log = LoggerFactory.getLogger(CounterRestService.class);
@POST
@Path("/create")
public CounterResponce create(@QueryParam("name") String name) {
log.info("create "+name)
try {
CounterService.getInstance().put(name);
log.info("responce data"); // <- :((
return new CounterResponce();
} catch (Exception e){
log.info("responce error data"); // <- :((
return new CounterResponce("error", e.getMessage());
}
}
@POST
@Path("/insert")
public CounterResponce create(Counter counter) {
try {
CounterService.getInstance().put(counter);
return new CounterResponce();
} catch (Exception e){
return new CounterResponce("error", e.getMessage());
}
}
...
}
【问题讨论】:
-
您考虑过名称绑定过滤器吗?
-
我想,我在jersey.java.net/documentation/latest/…找到了正确的方向