繁体   English   中英

Resteasy客户端没有关闭连接

[英]Resteasy client not closing connection

我找到了一个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);

我在服务上调用以下方法

@DELETE
@Path("{id}")
Response deleteObject(@PathParam("id") Long id);

服务正在回归

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

关于我缺少什么的想法,以便关闭连接。 注意:对于所有其他响应类型,连接正在关闭。

我知道,如果我不归还500,那么一切都会顺利进行。 但如果这种情况偶然发生,我希望我的客户能够处理它,而不会耗尽连接。

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

Response deleteObject(@PathParam("id") Long id);

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

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

@DELETE
@Path("{id}")
void deleteObject(@PathParam("id") Long id);

或者如果你期望Foo对象回来:

@DELETE
@Path("{id}")
Foo deleteObject(@PathParam("id") Long id);

有关详细信息,请参阅resteasy 传输层文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM