【发布时间】:2015-07-01 14:21:51
【问题描述】:
我想使用 Jersey 客户端从我的 Dropwizard 应用程序访问 REST 服务。相同的技术在不同的地方都可以正常工作,但在目前的情况下,服务总是返回 500,尽管我知道 URL 等是正确的。由于我无法修改服务,因此我想记录我的请求以验证它们是否正常(因为我怀疑我的实体未正确序列化)。
因此,我在客户端上注册了一个记录器,如下所示:
restClient.register(new LoggingFilter(Logger.getAnonymousLogger(), true));
但它只是从不记录我的实体。我总是这样:
INFO [2015-07-01 14:12:47,433] unknown.jul.logger: 1 * Sending client request on thread dw-admin-34
1 > POST [My URL which is correct]
1 > Accept: application/json
1 > Accept-Encoding: gzip
1 > Content-Type: application/json
?
这是否意味着它不识别任何实体?
这就是我构建客户端的方式:
this.restClient = new JerseyClientBuilder(dropwizardEnvironment)
.using(MyConfiguration.jerseyClient) // new JerseyClientConfiguration() in Dropwizard config class
.build("my client name");
这是我提出请求的方式:
Response r = restClient.target(address)
.request(MediaType.APPLICATION_JSON)
.acceptEncoding("gzip")
.post(Entity.json(entity)); //omitting entity. It's very simple and I checked that its values are fine
我对这一切都很陌生,所以这可能只是一些愚蠢的菜鸟错误。为什么没有正确记录请求正文的任何想法?
【问题讨论】:
-
使用标准泽西岛对我来说效果很好。也许有 Dropwizard 的东西。
标签: java jersey jax-rs dropwizard jersey-client