简体   繁体   中英

Resteasy client not closing connection

I have found one scenario where resteasy is not closing the connection. 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. 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 (?):

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). When your method returns a ClientResponse, you assume responsibility for releasing the connection.

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:

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

or if you expected the Foo object back:

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

See the resteasy Transport Layer documentation for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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