简体   繁体   English

Resteasy客户端没有关闭连接

[英]Resteasy client not closing connection

I have found one scenario where resteasy is not closing the connection. 我找到了一个resteasy没有关闭连接的场景。 Is there a way around this? 有没有解决的办法? I have created my client as: 我创建了我的客户端:

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);

I am calling the following method on the service 我在服务上调用以下方法

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

And the service is returning 服务正在回归

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

Any ideas on what I am missing to get the connection to close. 关于我缺少什么的想法,以便关闭连接。 Note: for all other response types, the connections are closing. 注意:对于所有其他响应类型,连接正在关闭。

I know that if I don't return the 500, everything will work well. 我知道,如果我不归还500,那么一切都会顺利进行。 But should such a scenario accidentally happen, I want my client to be able to handle it, without running out of connections. 但如果这种情况偶然发生,我希望我的客户能够处理它,而不会耗尽连接。

I am assuming that the following method belongs on the resteasy client's proxied interface (?): 我假设以下方法属于resteasy客户端的代理接口(?):

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

If so, the problem here is that your method returns the resteasy ClientResponse object (which is the resteasy implementation of the jax-rs Response). 如果是这样,这里的问题是你的方法返回resteasy ClientResponse对象(这是jax-rs Response的resteasy实现)。 When your method returns a ClientResponse, you assume responsibility for releasing the connection. 当您的方法返回ClientResponse时,您将负责释放连接。

In your case, you are also relying on the proxy factory, so it may not be possible to release the connection. 在您的情况下,您也依赖于代理工厂,因此可能无法释放连接。 In that case, you should change the signature of your method to return either void or the type of the object you expect in the HTTP response body: 在这种情况下,您应该更改方法的签名,以返回void或HTTP响应主体中您期望的对象类型:

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

or if you expected the Foo object back: 或者如果你期望Foo对象回来:

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

See the resteasy Transport Layer documentation for more information. 有关详细信息,请参阅resteasy 传输层文档

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

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