我们最近在服务器和客户端上都从泽西岛1.x升级到了泽西岛2.22.1。我们现在看到intermittently泽西将提出/接收两个请求。
我可以通过在这个客户端POST请求上循环数千次来复制它。每个请求都发送一个唯一的“名称”,该名称将持久化在服务器上。我知道我们已经收到了一个重复的请求,当我得到一个唯一的约束违反尝试持久化相同的‘名称’两次。我排除了代码的其他部分,因为日志确认泽西收到了两个相同名称的帖子请求。
我在服务器上的org.glassfish包中启用了跟踪日志记录,并在客户机上注册了LoggingFilter()。
客户端只显示一个POST请求和响应:
Jun 21, 2016 6:02:51 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 8291 * Sending client request on thread main
8291 > POST http://localhost:9797/my-webapp/v1/data-feeds/
8291 > Accept: application/json
8291 > Content-Type: application/json
Jun 21, 2016 6:02:51 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 8291 * Client response received on thread main
8291 < 200
8291 < Cache-Control: no-cache, no-store, max-age=0, must-revalidate
8291 < Content-Length: 181
8291 < Content-Type: application/json
8291 < Date: Wed, 22 Jun 2016 00:02:51 GMT
8291 < Expires: 0
8291 < Pragma: no-cache
8291 < Server: Apache-Coyote/1.1
8291 < Set-Cookie: JSESSIONID=CFF556E7FCDB5B1F644BA04603364DFD; Path=/my-webapp/; HttpOnly
8291 < X-Content-Type-Options: nosniff
8291 < X-Frame-Options: DENY
8291 < X-XSS-Protection: 1; mode=block服务器显示两个相同“名称”的帖子:
Jun 21, 2016 6:02:51 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 8293 * Server has received a request on thread http-bio-9797-exec-21
8293 > POST http://localhost:9797/my-webapp/v1/data-feeds/
8293 > accept: application/json
8293 > authorization: Basic YWRtaW46bmltZGE=
8293 > connection: keep-alive
8293 > content-length: 181
8293 > content-type: application/json
8293 > host: localhost:9797
8293 > user-agent: Jersey/2.22.1 (HttpUrlConnection 1.8.0_31)
2016-06-21 18:02:51,964 [INFO] [c.m.c.r.r.MyResource] Received POST request /data-feeds with args [FeedData{name='pool4146'}]
Jun 21, 2016 6:02:51 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 8294 * Server has received a request on thread http-bio-9797-exec-97
8294 > POST http://localhost:9797/my-webapp/v1/data-feeds/
8294 > accept: application/json
8294 > authorization: Basic YWRtaW46bmltZGE=
8294 > connection: keep-alive
8294 > content-length: 181
8294 > content-type: application/json
8294 > host: localhost:9797
8294 > user-agent: Jersey/2.22.1 (HttpUrlConnection 1.8.0_31)
2016-06-21 18:02:51,978 [INFO] [c.m.c.r.r.MyResource] Received POST request /data-feeds with args [FeedData{name='pool4146'}]
Jun 21, 2016 6:02:51 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 8293 * Server responded with a response on thread http-bio-9797-exec-21
8293 < 200
8293 < Content-Type: application/json
Jun 21, 2016 6:02:51 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 8294 * Server responded with a response on thread http-bio-9797-exec-97
8294 < 200
8294 < Content-Type: application/json让我知道,如果有任何其他配置信息,可能是相关的这里。我们使用Tomcat 7.x和Jackson进行序列化/反序列化
发布于 2019-04-27 12:16:12
由于解决方案不是巴斯蒂安·巴斯特的答案的一部分,所以我会在这里发布。似乎泽西岛的bug跟踪器被移到了GitHub,因此作为参考,这是一个新的工作链接:https://github.com/jersey/jersey/issues/3526
要解决此问题,可以在jersey/core-client/src/main/java/org/glassfish/jersey/client/authentication/HttpAuthenticationFilter.java:中添加以下内容
static boolean repeatRequest(ClientRequestContext request, ClientResponseContext response, String newAuthorizationHeader) throws IOException {
// If the failed response has an entity stream, close it. We must do this to avoid leaking resources
// when we replace the entity stream of the failed response with that of the repeated response (see below).
// Notice that by closing the entity stream before sending the repeated request we allow resources allocated
// to the failed request (e.g., the HTTP connection) to be reused, if possible, for the repeated request.
if (response.hasEntity()) {
response.getEntityStream().close();
response.setEntityStream(null);
}
Client client = request.getClient();并删除这一行代码:
Client client = ClientBuilder.newClient(request.getConfiguration());我不觉得恼人的是,球衣维修人员似乎没有解决这个问题。
发布于 2016-09-07 19:05:49
我被同一个问题困住了,我无法复制这个问题。你试过关闭ClientResponse流吗?让我知道这是怎么回事。
Client client = new Client();
WebResource resource = client.resource(restUrl);
final ClientResponse response = resource.get(ClientResponse.class);
response.close();发布于 2017-03-27 09:07:50
这似乎是我们所犯的类似错误。我们很难解决这个问题。
我们已经在https://java.net/jira/browse/JERSEY-3254上发布了这个,并附加了这个补丁。基本上,它位于HttpAuthenticationFilter中,使摘要身份验证中断。其结果往往是得到一些错误的401代码或StreamClosed异常。我不会把我的解决方案复制到这篇文章上,我认为JIRA的问题不会被删除。
https://stackoverflow.com/questions/37956741
复制相似问题