簡體   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