Resteasy 客户端未关闭连接

use*_*167 4 java jaxb resteasy

我发现了一种情况,resteasy 没有关闭连接。有没有解决的办法?我将我的客户端创建为:

ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
HttpClient httpClient = new DefaultHttpClient(cm);
ClientExecutor executor = new ApacheHttpClient4Executor(httpClient);
T proxiedService = org.jboss.resteasy.client.ProxyFactory.create(clazz, base, executor);
Run Code Online (Sandbox Code Playgroud)

我在服务上调用以下方法

@DELETE
@Path("{id}")
Response deleteObject(@PathParam("id") Long id);
Run Code Online (Sandbox Code Playgroud)

服务正在回归

HTTP/1.1 500 Internal Server Error [Content-Length: 0, Server: Jetty(8.1.2.v20120308)]
Run Code Online (Sandbox Code Playgroud)

关于我缺少什么来关闭连接的任何想法。注意:对于所有其他响应类型,连接将关闭。

我知道如果我不退还500,一切都会顺利。但如果这种情况意外发生,我希望我的客户端能够处理它,而不会耗尽连接。

小智 5

我假设以下方法属于resteasy客户端的代理接口(?):

Response deleteObject(@PathParam("id") Long id);
Run Code Online (Sandbox Code Playgroud)

如果是这样,这里的问题是您的方法返回resteasy ClientResponse 对象(这是jax-rs Response 的resteasy 实现)。当您的方法返回 ClientResponse 时,您就承担释放连接的责任。

在您的情况下,您还依赖于代理工厂,因此可能无法释放连接。在这种情况下,您应该更改方法的签名以返回 void 或您在 HTTP 响应正文中期望的对象类型:

@DELETE
@Path("{id}")
void deleteObject(@PathParam("id") Long id);
Run Code Online (Sandbox Code Playgroud)

或者如果您期望 Foo 对象返回:

@DELETE
@Path("{id}")
Foo deleteObject(@PathParam("id") Long id);
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅resteasy传输层文档。