【发布时间】:2017-07-25 17:30:45
【问题描述】:
我正在尝试为基于 jersey 构建的项目制定日志记录标准,并且我想提供一种简单的方法来记录请求信息和响应,以防发生异常。以下代码说明了我的想法:
Client client = null;
Response response = null;
try {
client = ClientBuilder.newClient();
response = client.target("<URL>")
.request(MediaType.APPLICATION_JSON)
.post(entity);
} catch( Exception ex) {
//Send information for exception mapping to a JSON log
throw new ServiceException( client,response );
}
问题是如何在我的ServiceException 类中获得以下内容:
String url = client.getUri().toString(); //only one I could get using WebTarget
MultivaluedMap<String, String> headers = client.getHeaders();
String body = client.getEntity();
MultivaluedMap<String, String> queryParams = client.getQueryParams();
String method = client.getMethod();
我尝试访问WebTarget,但没有成功。
提前致谢!
【问题讨论】:
标签: java web-services jersey jax-rs jersey-2.0