Skip to main content

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

Hi Marcus,

This issue arose recently in the context of issue RESTEASY-1142 "resteasy-client thrown exceptions during resteasy-jaxrs resource invocation causes IllegalStateException indigestion" (https://issues.jboss.org/browse/RESTEASY-1142).

  1. A resource method uses a Client to contact another server and gets an exception back.

  2. A builtin ExceptionMapper tries to unwrap the Exception:

   protected Response unwrapException(HttpRequest request, Throwable e, RESTEasyTracingLogger logger)
   {
      Response jaxrsResponse = null;
      Throwable unwrappedException = e.getCause();

      /*
       *                If the response property of the exception does not
       *                contain an entity and an exception mapping provider
       *                (see section 4.4) is available for
       *                WebApplicationException an implementation MUST use the
       *                provider to create a new Response instance, otherwise
       *                the response property is used directly.
       */

      if (unwrappedException instanceof WebApplicationException) {
         WebApplicationException wae = (WebApplicationException) unwrappedException;
         Response response = wae.getResponse();
         if (response != null) {
            try { // Here's where we guard against IllegalStateExceptioin
               if (response.getEntity() != null) return response;
            }
            catch(IllegalStateException ise) {
               // IllegalStateException from ClientResponse.getEntity() means the response is closed and got no entity
            }
         }
      }
        ...

Before we wrapped the call to Response.getEntity() in try/catch, we were getting an IllegalStateException, which isn't very helpful.

-Ron


On 11/28/18 1:00 AM, Markus KARG wrote:

Can you please provide a real-worl use case where an application does not know from ist very own state that the response is closed? I mean, responses do not get closed just by incident. Typically an application does not have any need to fear that a just received response instance may become closed unless it tends to store them somewhere.

-Markus

 

From: jaxrs-dev-bounces@xxxxxxxxxxx [mailto:jaxrs-dev-bounces@xxxxxxxxxxx] On Behalf Of Ron Sigal
Sent: Mittwoch, 28. November 2018 01:31
To: jaxrs-dev@xxxxxxxxxxx
Subject: [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)

_______________________________________________
jaxrs-dev mailing list
jaxrs-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jaxrs-dev
-- 
My company's smarter than your company (unless you work for Red Hat)

Back to the top