Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jaxrs-dev] Request for extension to Response

A number of javax.ws.rs.core.Response methods, e.g., getEntity() and hasEntity(), include a line in the javadoc like

* @throws IllegalStateException in case the response has been {@link #close() closed}.

However, in the absence of a method like isClosed(), we end up writing code like

try {
   if (response.getEntity() != null) return response;
}
catch(IllegalStateException ise) {
   // IllegalStateException from ClientResponse.getEntity() means the response is closed and got no entity
}

instead of

if (!response.isClosed() && response.getEntity() != null) {
   return response;
}

The implementation of isClosed() should be simple, and it leads to nicer code.

-Ron

-- 
My company's smarter than your company (unless you work for Red Hat)

Back to the top