Question on RestletResponse.release()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Question on RestletResponse.release()

Sanjay Acharya

I am curious regarding the proper mode of ensuring release() :

My code is pretty much doing the following:

Response response = ....;

try {
  .....
  return response.getStatus().equals(Status.OK);
} finally {
   if (response != null && response.getEntity() != null) {
     try {
        response.release();
     } catch (RuntimeException e) {
        log.error(e, e);
     }
  }
}

We are facing a case where the release() method is causing an exception due to wrong response returned as shown below:
null
   java.io.FilterInputStream.close(FilterInputStream.java:159)

   com.noelios.restlet.ext.httpclient.HttpMethodCall$3.close(HttpMethodCall.java:276)

   org.restlet.resource.InputRepresentation.release(InputRepresentation.java:92)

   org.restlet.data.Message.release(Message.java:209)

   
If the above occurs, then the HttpMethod will not release() the connection as can be observed below in the com.noelios.restlet.ext.httpclient.HttpMethodCall, i.e., leaking connection potentially? We would have this problem especially when pooling connections.  

  public InputStream getResponseStream() {
        InputStream result = null;

        try {
            // Return a wrapper filter that will release the connection when
            // needed
            result = new FilterInputStream(getHttpMethod()
                    .getResponseBodyAsStream()) {
                public void close() throws IOException {
                    super.close();
                    getHttpMethod().releaseConnection();
                }
            };
        } catch (IOException ioe) {
            result = null;
        }
        return result;
    }

Would it make sense to call releaseConnection() with a ARM block in the close() method above? If not, what is the preferred direction to release the connection?

Thanks,
Sanjay



_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008
Reply | Threaded
Open this post in threaded view
|

Re: Question on RestletResponse.release()

Thierry Boileau
Hello Sanjay,

Could you replace the following test:
if (response != null && response.getEntity() != null) {
by
if (response != null && response.isEntityAvailable()) {
It should ensure that the entity is still available and can be read or closed.

best regards,
Thierry Boileau

I am curious regarding the proper mode of ensuring release() :

My code is pretty much doing the following:

Response response = ....;

try {
  .....
  return response.getStatus().equals(Status.OK);
} finally {
   if (response != null && response.getEntity() != null) {
     try {
        response.release();
     } catch (RuntimeException e) {
        log.error(e, e);
     } 
  }
}

We are facing a case where the release() method is causing an exception due to wrong response returned as shown below:
null
   java.io.FilterInputStream.close(FilterInputStream.java:159)

   com.noelios.restlet.ext.httpclient.HttpMethodCall$3.close(HttpMethodCall.java:276)

   org.restlet.resource.InputRepresentation.release(InputRepresentation.java:92)

   org.restlet.data.Message.release(Message.java:209)

   
If the above occurs, then the HttpMethod will not release() the connection as can be observed below in the com.noelios.restlet.ext.httpclient.HttpMethodCall, i.e., leaking connection potentially? We would have this problem especially when pooling connections.  

  public InputStream getResponseStream() {
        InputStream result = null;

        try {
            // Return a wrapper filter that will release the connection when
            // needed
            result = new FilterInputStream(getHttpMethod()
                    .getResponseBodyAsStream()) {
                public void close() throws IOException {
                    super.close();
                    getHttpMethod().releaseConnection();
                }
            };
        } catch (IOException ioe) {
            result = null;
        }
        return result;
    }

Would it make sense to call releaseConnection() with a ARM block in the close() method above? If not, what is the preferred direction to release the connection?

Thanks,
Sanjay



_________________________________________________________________
Stay organized with simple drag and drop from Windows Live Hotmail.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_102008