You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by sbalustar <bs...@gmail.com> on 2017/08/15 22:20:43 UTC

Re: Closing of WebClient and Response objects

HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the below
issue.

AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
javax.ws.rs.ProcessingException: java.lang.IllegalStateException: Entity is
not available
    at
org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
    at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
    at
org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
    at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
    at
com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
 ... 78 more

I have gone through this ticket
https://issues.apache.org/jira/browse/CXF-5144 which you mentioned that Set
this property: "response.stream.auto.close" to true. This is done even
though we are getting the same issue.

When i debug the code, in WebClient.invoke method this exception is occured.

  protected Response handleResponse(Message outMessage, Class<?>
responseClass, Type genericType) {
        try {
            ResponseBuilder rb = setResponseBuilder(outMessage,
outMessage.getExchange());
            Response currentResponse = rb.clone().build();
            ((ResponseImpl)currentResponse).setOutMessage(outMessage);
            
            Object entity = readBody(currentResponse, outMessage,
responseClass, genericType,
                                     new Annotation[]{});
            
            if (entity == null) {
                int status = currentResponse.getStatus();
                if (status >= 400) {
                    entity = currentResponse.getEntity();
                }
            }
            rb = JAXRSUtils.fromResponse(currentResponse);
            
            rb.entity(entity instanceof Response 
                      ? ((Response)entity).getEntity() : entity);
            
            Response r = rb.build();
            getState().setResponse(r);
            ((ResponseImpl)r).setOutMessage(outMessage);
            return r;
        } catch (Throwable ex) {
            throw (ex instanceof ProcessingException) ?
(ProcessingException)ex
                                                  : new
ProcessingException(ex);
        } finally {
           
ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
        }
    }


  public static ResponseBuilder fromResponse(Response response) {
        ResponseBuilder rb = toResponseBuilder(response.getStatus());
*        rb.entity(response.getEntity());
*        for (Map.Entry<String, List&lt;Object>> entry :
response.getMetadata().entrySet()) {
            List values = entry.getValue();
            for (Object value : values) {
                rb.header(entry.getKey(), value);
            }
        }
        return rb;
    }

* rb.entity(response.getEntity());
* seems like , entity is null in ResponseBuilder rb from the fromResponse
method.

Please let me know, what could be the solution to fix this issue?



--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
So readEntity is read somewhere in your code before Response.getEntity 
is called which is what my point is. If readEntity is not called then no 
auto-close will be called...

Sergey


On 16/08/17 22:18, sbalustar wrote:
> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like below
> 
> 
>      public Object getEntity() {
>          return InjectionUtils.getEntity(getActualEntity());
>      }
> 
> 
>    public Object getActualEntity() {
>          checkEntityIsClosed();
>          return lastEntity != null ? lastEntity : entity;
>      }
> 
>    private void checkEntityIsClosed() {
> 
>          if (entityClosed) {
> 
>              throw new IllegalStateException("Entity is not available");
> 
>          }
> 
>      }
> 
> 
>   public void close() throws ProcessingException {
> 
>          if (!entityClosed) {
> 
>              if (!entityBufferred && entity instanceof InputStream) {
> 
>                  try {
> 
>                      ((InputStream)entity).close();
> 
>                  } catch (IOException ex) {
> 
>                      throw new ResponseProcessingException(this, ex);
> 
>                  }
> 
>              }
> 
>              entity = null;
> 
>              entityClosed = true;
> 
>          }
> 
> 
> 
>      }
> In the readEntity method, there is a call to close() method which the
> entityClosed variable value is set to true. When calling the getEntity()
> method , there is a another method call checkEntityIsClosed is throwing the
> exception because the entityClosed is set to true in readEntity.
> 
> 
> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
> simply it returns the entity
> 
> public Object getEntity() {
>          return lastEntity != null ? lastEntity : entity;
>      }
> 
> 
> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
> ml+s547215n5782757h1@n5.nabble.com> wrote:
> 
>> Hi, that will need to be measured for a concrete flow.
>> I'm still not sure why you are seeing the failure with the auto close
>> being on - it only takes effect after the entity has been consumed...
>>
>> Sergey
>> On 16/08/17 19:03, sbalustar wrote:
>>
>>> Hi Sergey,
>>>
>>>      At runtime,  in Debug mode Changed the response.stream.auto.close=false.
>>
>>> Later on , i am not facing the Entity Not available Exception.
>>>
>>>     Is there any impact on the performance when we disabled the flag?
>>>
>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>> wrote:
>>>
>>>> Hi
>>>>
>>>> I don't quite understand what the issue is, does it happen when you
>>>> enable "response.stream.auto.close" ? If yes - what happens if you do
>>>> not enable this property ?
>>>>
>>>> CXF does not auto-close the input stream by default given of the few
>>>> well-known side-effects.
>>>>
>>>> Given you have already tried to debug - it is better to set a
>> breakpoint
>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why
>>>> InputStream is not available in your case
>>>>
>>>> Cheers, Sergey
>>>>
>>>> On 15/08/17 23:20, sbalustar wrote:
>>>>
>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
>>>> below
>>>>> issue.
>>>>>
>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>>>> Entity is
>>>>> not available
>>>>>        at
>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>
>>>>
>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>
>>>>
>>>>>        at
>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>
>>>>
>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>
>>>>
>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>
>>>>
>>>>>        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>
>>>>
>>>>>        at
>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>
>>>>>     ... 78 more
>>>>>
>>>>> I have gone through this ticket
>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
>> that
>>>> Set
>>>>> this property: "response.stream.auto.close" to true. This is done even
>>>>> though we are getting the same issue.
>>>>>
>>>>> When i debug the code, in WebClient.invoke method this exception is
>>>> occured.
>>>>>
>>>>>      protected Response handleResponse(Message outMessage, Class<?>
>>>>> responseClass, Type genericType) {
>>>>>            try {
>>>>>                ResponseBuilder rb = setResponseBuilder(outMessage,
>>>>> outMessage.getExchange());
>>>>>                Response currentResponse = rb.clone().build();
>>>>>                ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>
>>>>>
>>>>>                Object entity = readBody(currentResponse, outMessage,
>>>>> responseClass, genericType,
>>>>>                                         new Annotation[]{});
>>>>>
>>>>>                if (entity == null) {
>>>>>                    int status = currentResponse.getStatus();
>>>>>                    if (status >= 400) {
>>>>>                        entity = currentResponse.getEntity();
>>>>>                    }
>>>>>                }
>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
>>>>>
>>>>>                rb.entity(entity instanceof Response
>>>>>                          ? ((Response)entity).getEntity() : entity);
>>>>>
>>>>>                Response r = rb.build();
>>>>>                getState().setResponse(r);
>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
>>>>>                return r;
>>>>>            } catch (Throwable ex) {
>>>>>                throw (ex instanceof ProcessingException) ?
>>>>> (ProcessingException)ex
>>>>>                                                      : new
>>>>> ProcessingException(ex);
>>>>>            } finally {
>>>>>
>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>
>>>>
>>>>>            }
>>>>>        }
>>>>>
>>>>>
>>>>>      public static ResponseBuilder fromResponse(Response response) {
>>>>>            ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>
>>>>> *        rb.entity(response.getEntity());
>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>>>> response.getMetadata().entrySet()) {
>>>>>                List values = entry.getValue();
>>>>>                for (Object value : values) {
>>>>>                    rb.header(entry.getKey(), value);
>>>>>                }
>>>>>            }
>>>>>            return rb;
>>>>>        }
>>>>>
>>>>> * rb.entity(response.getEntity());
>>>>> * seems like , entity is null in ResponseBuilder rb from the
>>>> fromResponse
>>>>> method.
>>>>>
>>>>> Please let me know, what could be the solution to fix this issue?
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>
>>>>
>>>>
>>>> --
>>>> Sergey Beryozkin
>>>>
>>>> Talend Community Coders
>>>> http://coders.talend.com/
>>>>
>>>>
>>>> ------------------------------
>>>> If you reply to this email, your message will be added to the
>> discussion
>>>> below:
>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
>> Response-objects-
>>>> tp5748134p5782725.html
>>>> To unsubscribe from Closing of WebClient and Response objects, click
>> here
>>>> <
>>>> .
>>>> NAML
>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
>> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
>> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
>> web.template.NabbleNamespace-nabble.view.web.template.
>> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
>> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
>> instant_email%21nabble%3Aemail.naml>
>>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context: http://cxf.547215.n5.nabble.
>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
>> tp5748134p5782757.html
>> To unsubscribe from Closing of WebClient and Response objects, click here
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>> .
>> NAML
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
This was already resolved in 3.1.13-SNAPSHOT (CXF-7478)

A couple of comments.

This is not a blocker given that 1) in the version you are migrating 
from the notion of the auto-closing the stream did not exist and 2) I 
showed the way this feature can still be effective in CXF 3.1.x

The other point is that if you see what seems to be a blocker then do 
consider creating a patch to make things faster - in this case I had a 
time to do a quick fix, on other cases it may be possible to prioritize...

Cheers Sergey

On 19/08/17 19:24, sbalustar wrote:
> Sergey,
> 
> Did you get any chance to open a ticket on this issue? This is a blocker
> for us.
> 
> On Thu, Aug 17, 2017 at 11:36 AM Balakrishna Sudabathula <
> bsudabathula@gmail.com> wrote:
> 
>> Sergey,
>>
>>    We have not created any client from our side. We are using  jar  file in
>> our project which is developed by some other team was implemented this
>> functionality. But  in CXF 3.1.8 WebClient, handleResponse method first it
>> is calling readEntity which it is closing the entity and later calling
>> getEntity which is checking the  entity is closed or not. If it is closed ,
>> Entity is not available Exception is throwing.
>>
>>
>> On Thu, Aug 17, 2017 at 12:15 AM, Jose María Zaragoza [via CXF] <
>> ml+s547215n5782769h73@n5.nabble.com> wrote:
>>
>>> 2017-08-16 23:18 GMT+02:00 sbalustar <[hidden email]
>>> <http:///user/SendEmail.jtp?type=node&node=5782769&i=0>>:
>>>
>>>> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
>>> below
>>>>
>>>>
>>>>      public Object getEntity() {
>>>>          return InjectionUtils.getEntity(getActualEntity());
>>>>      }
>>>>
>>>>
>>>>    public Object getActualEntity() {
>>>>          checkEntityIsClosed();
>>>>          return lastEntity != null ? lastEntity : entity;
>>>>      }
>>>>
>>>>    private void checkEntityIsClosed() {
>>>>
>>>>          if (entityClosed) {
>>>>
>>>>              throw new IllegalStateException("Entity is not available");
>>>>
>>>>          }
>>>>
>>>>      }
>>>>
>>>>
>>>>   public void close() throws ProcessingException {
>>>>
>>>>          if (!entityClosed) {
>>>>
>>>>              if (!entityBufferred && entity instanceof InputStream) {
>>>>
>>>>                  try {
>>>>
>>>>                      ((InputStream)entity).close();
>>>>
>>>>                  } catch (IOException ex) {
>>>>
>>>>                      throw new ResponseProcessingException(this, ex);
>>>>
>>>>                  }
>>>>
>>>>              }
>>>>
>>>>              entity = null;
>>>>
>>>>              entityClosed = true;
>>>>
>>>>          }
>>>>
>>>>
>>>>
>>>>      }
>>>
>>>
>>>
>>> Hi:
>>>
>>> Sorry for this semi-offtopic, but there is something I don't understand
>>>
>>> I thought that Response.close() method performed a close in InputStream
>>> object
>>> associated to the underlying HttpURLConnection object.
>>>
>>> But I see that Response.close() only closes entity  **if entity is an
>>> InputStream**
>>> The beginning of the thread was about if it was necessary to close
>>> Response instance explicitly.
>>>
>>> What about if I do
>>>
>>> Book book = response.readEntity(Book.class)
>>>
>>> ?
>>>
>>> Should I close the response object ?
>>> I see that autoclose() only is called if class is not InputStream ,
>>> but close() required that entity be InputStream
>>>
>>> I know I'm loosing something ( maybe mixing concepts )
>>>
>>> Regards
>>>
>>>
>>>> In the readEntity method, there is a call to close() method which the
>>>> entityClosed variable value is set to true. When calling the
>>> getEntity()
>>>> method , there is a another method call checkEntityIsClosed is throwing
>>> the
>>>> exception because the entityClosed is set to true in readEntity.
>>>>
>>>>
>>>> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
>>>> simply it returns the entity
>>>>
>>>> public Object getEntity() {
>>>>          return lastEntity != null ? lastEntity : entity;
>>>>      }
>>>>
>>>>
>>>> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>>>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782769&i=1>>
>>> wrote:
>>>>
>>>>> Hi, that will need to be measured for a concrete flow.
>>>>> I'm still not sure why you are seeing the failure with the auto close
>>>>> being on - it only takes effect after the entity has been consumed...
>>>>>
>>>>> Sergey
>>>>> On 16/08/17 19:03, sbalustar wrote:
>>>>>
>>>>>> Hi Sergey,
>>>>>>
>>>>>>      At runtime,  in Debug mode Changed the
>>> response.stream.auto.close=false.
>>>>>
>>>>>> Later on , i am not facing the Entity Not available Exception.
>>>>>>
>>>>>>     Is there any impact on the performance when we disabled the flag?
>>>>>>
>>>>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>>>>>> [hidden email] <
>>> http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>>>>> wrote:
>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> I don't quite understand what the issue is, does it happen when you
>>>>>>> enable "response.stream.auto.close" ? If yes - what happens if you
>>> do
>>>>>>> not enable this property ?
>>>>>>>
>>>>>>> CXF does not auto-close the input stream by default given of the
>>> few
>>>>>>> well-known side-effects.
>>>>>>>
>>>>>>> Given you have already tried to debug - it is better to set a
>>>>> breakpoint
>>>>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
>>> why
>>>>>>> InputStream is not available in your case
>>>>>>>
>>>>>>> Cheers, Sergey
>>>>>>>
>>>>>>> On 15/08/17 23:20, sbalustar wrote:
>>>>>>>
>>>>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
>>> the
>>>>>>> below
>>>>>>>> issue.
>>>>>>>>
>>>>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>>>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>>>>>>> Entity is
>>>>>>>> not available
>>>>>>>>        at
>>>>>>>>
>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>>>>
>>>>>>>
>>>>>>>>        at
>>> org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>>>>
>>>>>>>
>>>>>>>>        at
>>>>>>>>
>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>>
>>>>>
>>>>>>>
>>>>>>>>        at
>>> org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>>>>
>>>>>>>
>>>>>>>>        at
>>> org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>>>>
>>>>>>>
>>>>>>>>        at
>>> org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>>>>
>>>>>>>
>>>>>>>>        at
>>>>>>>>
>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>>>>
>>>>>>>>     ... 78 more
>>>>>>>>
>>>>>>>> I have gone through this ticket
>>>>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you
>>> mentioned
>>>>> that
>>>>>>> Set
>>>>>>>> this property: "response.stream.auto.close" to true. This is done
>>> even
>>>>>>>> though we are getting the same issue.
>>>>>>>>
>>>>>>>> When i debug the code, in WebClient.invoke method this exception
>>> is
>>>>>>> occured.
>>>>>>>>
>>>>>>>>      protected Response handleResponse(Message outMessage, Class<?>
>>>>>>>> responseClass, Type genericType) {
>>>>>>>>            try {
>>>>>>>>                ResponseBuilder rb = setResponseBuilder(outMessage,
>>>>>>>> outMessage.getExchange());
>>>>>>>>                Response currentResponse = rb.clone().build();
>>>>>>>>
>>> ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>>>>
>>>>>>>>
>>>>>>>>                Object entity = readBody(currentResponse,
>>> outMessage,
>>>>>>>> responseClass, genericType,
>>>>>>>>                                         new Annotation[]{});
>>>>>>>>
>>>>>>>>                if (entity == null) {
>>>>>>>>                    int status = currentResponse.getStatus();
>>>>>>>>                    if (status >= 400) {
>>>>>>>>                        entity = currentResponse.getEntity();
>>>>>>>>                    }
>>>>>>>>                }
>>>>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
>>>>>>>>
>>>>>>>>                rb.entity(entity instanceof Response
>>>>>>>>                          ? ((Response)entity).getEntity() :
>>> entity);
>>>>>>>>
>>>>>>>>                Response r = rb.build();
>>>>>>>>                getState().setResponse(r);
>>>>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
>>>>>>>>                return r;
>>>>>>>>            } catch (Throwable ex) {
>>>>>>>>                throw (ex instanceof ProcessingException) ?
>>>>>>>> (ProcessingException)ex
>>>>>>>>                                                      : new
>>>>>>>> ProcessingException(ex);
>>>>>>>>            } finally {
>>>>>>>>
>>>>>>>>
>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>>>>
>>>>>>>
>>>>>>>>            }
>>>>>>>>        }
>>>>>>>>
>>>>>>>>
>>>>>>>>      public static ResponseBuilder fromResponse(Response response)
>>> {
>>>>>>>>            ResponseBuilder rb =
>>> toResponseBuilder(response.getStatus());
>>>>>
>>>>>>>> *        rb.entity(response.getEntity());
>>>>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>>>>>>> response.getMetadata().entrySet()) {
>>>>>>>>                List values = entry.getValue();
>>>>>>>>                for (Object value : values) {
>>>>>>>>                    rb.header(entry.getKey(), value);
>>>>>>>>                }
>>>>>>>>            }
>>>>>>>>            return rb;
>>>>>>>>        }
>>>>>>>>
>>>>>>>> * rb.entity(response.getEntity());
>>>>>>>> * seems like , entity is null in ResponseBuilder rb from the
>>>>>>> fromResponse
>>>>>>>> method.
>>>>>>>>
>>>>>>>> Please let me know, what could be the solution to fix this issue?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>>>>>>
>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Sergey Beryozkin
>>>>>>>
>>>>>>> Talend Community Coders
>>>>>>> http://coders.talend.com/
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------
>>>>>>> If you reply to this email, your message will be added to the
>>>>> discussion
>>>>>>> below:
>>>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
>>>>> Response-objects-
>>>>>>> tp5748134p5782725.html
>>>>>>> To unsubscribe from Closing of WebClient and Response objects,
>>> click
>>>>> here
>>>>>>> <
>>>>>>> .
>>>>>>> NAML
>>>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
>>>>> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
>>>>> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
>>>>> web.template.NabbleNamespace-nabble.view.web.template.
>>>>> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
>>>>> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
>>>>> instant_email%21nabble%3Aemail.naml>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>>
>>>>>
>>>>>
>>>>> ------------------------------
>>>>> If you reply to this email, your message will be added to the
>>> discussion
>>>>> below:
>>>>>
>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
>>>>> tp5748134p5782757.html
>>>>> To unsubscribe from Closing of WebClient and Response objects, click
>>> here
>>>>> <
>>>>> .
>>>>> NAML
>>>>> <
>>> http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>>
>>> ------------------------------
>>> If you reply to this email, your message will be added to the discussion
>>> below:
>>>
>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782769.html
>>> To unsubscribe from Closing of WebClient and Response objects, click here
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>>> .
>>> NAML
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>
>>
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782871.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Sergey,

Did you get any chance to open a ticket on this issue? This is a blocker
for us.

On Thu, Aug 17, 2017 at 11:36 AM Balakrishna Sudabathula <
bsudabathula@gmail.com> wrote:

> Sergey,
>
>   We have not created any client from our side. We are using  jar  file in
> our project which is developed by some other team was implemented this
> functionality. But  in CXF 3.1.8 WebClient, handleResponse method first it
> is calling readEntity which it is closing the entity and later calling
> getEntity which is checking the  entity is closed or not. If it is closed ,
> Entity is not available Exception is throwing.
>
>
> On Thu, Aug 17, 2017 at 12:15 AM, Jose María Zaragoza [via CXF] <
> ml+s547215n5782769h73@n5.nabble.com> wrote:
>
>> 2017-08-16 23:18 GMT+02:00 sbalustar <[hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=5782769&i=0>>:
>>
>> > Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
>> below
>> >
>> >
>> >     public Object getEntity() {
>> >         return InjectionUtils.getEntity(getActualEntity());
>> >     }
>> >
>> >
>> >   public Object getActualEntity() {
>> >         checkEntityIsClosed();
>> >         return lastEntity != null ? lastEntity : entity;
>> >     }
>> >
>> >   private void checkEntityIsClosed() {
>> >
>> >         if (entityClosed) {
>> >
>> >             throw new IllegalStateException("Entity is not available");
>> >
>> >         }
>> >
>> >     }
>> >
>> >
>> >  public void close() throws ProcessingException {
>> >
>> >         if (!entityClosed) {
>> >
>> >             if (!entityBufferred && entity instanceof InputStream) {
>> >
>> >                 try {
>> >
>> >                     ((InputStream)entity).close();
>> >
>> >                 } catch (IOException ex) {
>> >
>> >                     throw new ResponseProcessingException(this, ex);
>> >
>> >                 }
>> >
>> >             }
>> >
>> >             entity = null;
>> >
>> >             entityClosed = true;
>> >
>> >         }
>> >
>> >
>> >
>> >     }
>>
>>
>>
>> Hi:
>>
>> Sorry for this semi-offtopic, but there is something I don't understand
>>
>> I thought that Response.close() method performed a close in InputStream
>> object
>> associated to the underlying HttpURLConnection object.
>>
>> But I see that Response.close() only closes entity  **if entity is an
>> InputStream**
>> The beginning of the thread was about if it was necessary to close
>> Response instance explicitly.
>>
>> What about if I do
>>
>> Book book = response.readEntity(Book.class)
>>
>> ?
>>
>> Should I close the response object ?
>> I see that autoclose() only is called if class is not InputStream ,
>> but close() required that entity be InputStream
>>
>> I know I'm loosing something ( maybe mixing concepts )
>>
>> Regards
>>
>>
>> > In the readEntity method, there is a call to close() method which the
>> > entityClosed variable value is set to true. When calling the
>> getEntity()
>> > method , there is a another method call checkEntityIsClosed is throwing
>> the
>> > exception because the entityClosed is set to true in readEntity.
>> >
>> >
>> > But In CXF 2.7.7,  there is no method call in the getEntity() method ,
>> > simply it returns the entity
>> >
>> > public Object getEntity() {
>> >         return lastEntity != null ? lastEntity : entity;
>> >     }
>> >
>> >
>> > On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782769&i=1>>
>> wrote:
>> >
>> >> Hi, that will need to be measured for a concrete flow.
>> >> I'm still not sure why you are seeing the failure with the auto close
>> >> being on - it only takes effect after the entity has been consumed...
>> >>
>> >> Sergey
>> >> On 16/08/17 19:03, sbalustar wrote:
>> >>
>> >> > Hi Sergey,
>> >> >
>> >> >     At runtime,  in Debug mode Changed the
>> response.stream.auto.close=false.
>> >>
>> >> > Later on , i am not facing the Entity Not available Exception.
>> >> >
>> >> >    Is there any impact on the performance when we disabled the flag?
>> >> >
>> >> > On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>> >> > [hidden email] <
>> http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>> >> wrote:
>> >> >
>> >> >> Hi
>> >> >>
>> >> >> I don't quite understand what the issue is, does it happen when you
>> >> >> enable "response.stream.auto.close" ? If yes - what happens if you
>> do
>> >> >> not enable this property ?
>> >> >>
>> >> >> CXF does not auto-close the input stream by default given of the
>> few
>> >> >> well-known side-effects.
>> >> >>
>> >> >> Given you have already tried to debug - it is better to set a
>> >> breakpoint
>> >> >> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
>> why
>> >> >> InputStream is not available in your case
>> >> >>
>> >> >> Cheers, Sergey
>> >> >>
>> >> >> On 15/08/17 23:20, sbalustar wrote:
>> >> >>
>> >> >>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
>> the
>> >> >> below
>> >> >>> issue.
>> >> >>>
>> >> >>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>> >> >>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>> >> >> Entity is
>> >> >>> not available
>> >> >>>       at
>> >> >>>
>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>> >>
>> >> >>
>> >> >>>       at
>> org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>> >>
>> >> >>
>> >> >>>       at
>> >> >>>
>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>
>> >>
>> >> >>
>> >> >>>       at
>> org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>> >>
>> >> >>
>> >> >>>       at
>> org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>> >>
>> >> >>
>> >> >>>       at
>> org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>> >>
>> >> >>
>> >> >>>       at
>> >> >>>
>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>> >>
>> >> >>>    ... 78 more
>> >> >>>
>> >> >>> I have gone through this ticket
>> >> >>> https://issues.apache.org/jira/browse/CXF-5144 which you
>> mentioned
>> >> that
>> >> >> Set
>> >> >>> this property: "response.stream.auto.close" to true. This is done
>> even
>> >> >>> though we are getting the same issue.
>> >> >>>
>> >> >>> When i debug the code, in WebClient.invoke method this exception
>> is
>> >> >> occured.
>> >> >>>
>> >> >>>     protected Response handleResponse(Message outMessage, Class<?>
>> >> >>> responseClass, Type genericType) {
>> >> >>>           try {
>> >> >>>               ResponseBuilder rb = setResponseBuilder(outMessage,
>> >> >>> outMessage.getExchange());
>> >> >>>               Response currentResponse = rb.clone().build();
>> >> >>>
>> ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>> >>
>> >> >>>
>> >> >>>               Object entity = readBody(currentResponse,
>> outMessage,
>> >> >>> responseClass, genericType,
>> >> >>>                                        new Annotation[]{});
>> >> >>>
>> >> >>>               if (entity == null) {
>> >> >>>                   int status = currentResponse.getStatus();
>> >> >>>                   if (status >= 400) {
>> >> >>>                       entity = currentResponse.getEntity();
>> >> >>>                   }
>> >> >>>               }
>> >> >>>               rb = JAXRSUtils.fromResponse(currentResponse);
>> >> >>>
>> >> >>>               rb.entity(entity instanceof Response
>> >> >>>                         ? ((Response)entity).getEntity() :
>> entity);
>> >> >>>
>> >> >>>               Response r = rb.build();
>> >> >>>               getState().setResponse(r);
>> >> >>>               ((ResponseImpl)r).setOutMessage(outMessage);
>> >> >>>               return r;
>> >> >>>           } catch (Throwable ex) {
>> >> >>>               throw (ex instanceof ProcessingException) ?
>> >> >>> (ProcessingException)ex
>> >> >>>                                                     : new
>> >> >>> ProcessingException(ex);
>> >> >>>           } finally {
>> >> >>>
>> >> >>>
>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>> >>
>> >> >>
>> >> >>>           }
>> >> >>>       }
>> >> >>>
>> >> >>>
>> >> >>>     public static ResponseBuilder fromResponse(Response response)
>> {
>> >> >>>           ResponseBuilder rb =
>> toResponseBuilder(response.getStatus());
>> >>
>> >> >>> *        rb.entity(response.getEntity());
>> >> >>> *        for (Map.Entry<String, List&lt;Object>> entry :
>> >> >>> response.getMetadata().entrySet()) {
>> >> >>>               List values = entry.getValue();
>> >> >>>               for (Object value : values) {
>> >> >>>                   rb.header(entry.getKey(), value);
>> >> >>>               }
>> >> >>>           }
>> >> >>>           return rb;
>> >> >>>       }
>> >> >>>
>> >> >>> * rb.entity(response.getEntity());
>> >> >>> * seems like , entity is null in ResponseBuilder rb from the
>> >> >> fromResponse
>> >> >>> method.
>> >> >>>
>> >> >>> Please let me know, what could be the solution to fix this issue?
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> View this message in context: http://cxf.547215.n5.nabble.
>> >> >>
>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>> >> >>> Sent from the cxf-user mailing list archive at Nabble.com.
>> >> >>>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Sergey Beryozkin
>> >> >>
>> >> >> Talend Community Coders
>> >> >> http://coders.talend.com/
>> >> >>
>> >> >>
>> >> >> ------------------------------
>> >> >> If you reply to this email, your message will be added to the
>> >> discussion
>> >> >> below:
>> >> >> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
>> >> Response-objects-
>> >> >> tp5748134p5782725.html
>> >> >> To unsubscribe from Closing of WebClient and Response objects,
>> click
>> >> here
>> >> >> <
>> >> >> .
>> >> >> NAML
>> >> >> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
>> >> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
>> >> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
>> >> web.template.NabbleNamespace-nabble.view.web.template.
>> >> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
>> >> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
>> >> instant_email%21nabble%3Aemail.naml>
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > View this message in context: http://cxf.547215.n5.nabble.
>> >> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>> >> > Sent from the cxf-user mailing list archive at Nabble.com.
>> >> >
>> >>
>> >>
>> >> ------------------------------
>> >> If you reply to this email, your message will be added to the
>> discussion
>> >> below:
>> >>
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
>> >> tp5748134p5782757.html
>> >> To unsubscribe from Closing of WebClient and Response objects, click
>> here
>> >> <
>> >> .
>> >> NAML
>> >> <
>> http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>> >>
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
>> > Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782769.html
>> To unsubscribe from Closing of WebClient and Response objects, click here
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>> .
>> NAML
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782871.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Sergey,

  We have not created any client from our side. We are using  jar  file in
our project which is developed by some other team was implemented this
functionality. But  in CXF 3.1.8 WebClient, handleResponse method first it
is calling readEntity which it is closing the entity and later calling
getEntity which is checking the  entity is closed or not. If it is closed ,
Entity is not available Exception is throwing.


On Thu, Aug 17, 2017 at 12:15 AM, Jose María Zaragoza [via CXF] <
ml+s547215n5782769h73@n5.nabble.com> wrote:

> 2017-08-16 23:18 GMT+02:00 sbalustar <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5782769&i=0>>:
>
> > Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
> below
> >
> >
> >     public Object getEntity() {
> >         return InjectionUtils.getEntity(getActualEntity());
> >     }
> >
> >
> >   public Object getActualEntity() {
> >         checkEntityIsClosed();
> >         return lastEntity != null ? lastEntity : entity;
> >     }
> >
> >   private void checkEntityIsClosed() {
> >
> >         if (entityClosed) {
> >
> >             throw new IllegalStateException("Entity is not available");
> >
> >         }
> >
> >     }
> >
> >
> >  public void close() throws ProcessingException {
> >
> >         if (!entityClosed) {
> >
> >             if (!entityBufferred && entity instanceof InputStream) {
> >
> >                 try {
> >
> >                     ((InputStream)entity).close();
> >
> >                 } catch (IOException ex) {
> >
> >                     throw new ResponseProcessingException(this, ex);
> >
> >                 }
> >
> >             }
> >
> >             entity = null;
> >
> >             entityClosed = true;
> >
> >         }
> >
> >
> >
> >     }
>
>
>
> Hi:
>
> Sorry for this semi-offtopic, but there is something I don't understand
>
> I thought that Response.close() method performed a close in InputStream
> object
> associated to the underlying HttpURLConnection object.
>
> But I see that Response.close() only closes entity  **if entity is an
> InputStream**
> The beginning of the thread was about if it was necessary to close
> Response instance explicitly.
>
> What about if I do
>
> Book book = response.readEntity(Book.class)
>
> ?
>
> Should I close the response object ?
> I see that autoclose() only is called if class is not InputStream ,
> but close() required that entity be InputStream
>
> I know I'm loosing something ( maybe mixing concepts )
>
> Regards
>
>
> > In the readEntity method, there is a call to close() method which the
> > entityClosed variable value is set to true. When calling the getEntity()
> > method , there is a another method call checkEntityIsClosed is throwing
> the
> > exception because the entityClosed is set to true in readEntity.
> >
> >
> > But In CXF 2.7.7,  there is no method call in the getEntity() method ,
> > simply it returns the entity
> >
> > public Object getEntity() {
> >         return lastEntity != null ? lastEntity : entity;
> >     }
> >
> >
> > On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782769&i=1>>
> wrote:
> >
> >> Hi, that will need to be measured for a concrete flow.
> >> I'm still not sure why you are seeing the failure with the auto close
> >> being on - it only takes effect after the entity has been consumed...
> >>
> >> Sergey
> >> On 16/08/17 19:03, sbalustar wrote:
> >>
> >> > Hi Sergey,
> >> >
> >> >     At runtime,  in Debug mode Changed the response.stream.auto.close=false.
>
> >>
> >> > Later on , i am not facing the Entity Not available Exception.
> >> >
> >> >    Is there any impact on the performance when we disabled the flag?
> >> >
> >> > On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
> >> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>
> >> wrote:
> >> >
> >> >> Hi
> >> >>
> >> >> I don't quite understand what the issue is, does it happen when you
> >> >> enable "response.stream.auto.close" ? If yes - what happens if you
> do
> >> >> not enable this property ?
> >> >>
> >> >> CXF does not auto-close the input stream by default given of the few
> >> >> well-known side-effects.
> >> >>
> >> >> Given you have already tried to debug - it is better to set a
> >> breakpoint
> >> >> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
> why
> >> >> InputStream is not available in your case
> >> >>
> >> >> Cheers, Sergey
> >> >>
> >> >> On 15/08/17 23:20, sbalustar wrote:
> >> >>
> >> >>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
> the
> >> >> below
> >> >>> issue.
> >> >>>
> >> >>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
> >> >>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
> >> >> Entity is
> >> >>> not available
> >> >>>       at
> >> >>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>
> >>
> >> >>
> >> >>>       at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>
> >>
> >> >>
> >> >>>       at
> >> >>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>
> >>
> >> >>
> >> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>
> >>
> >> >>
> >> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>
> >>
> >> >>
> >> >>>       at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>
> >>
> >> >>
> >> >>>       at
> >> >>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>
> >>
> >> >>>    ... 78 more
> >> >>>
> >> >>> I have gone through this ticket
> >> >>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
> >> that
> >> >> Set
> >> >>> this property: "response.stream.auto.close" to true. This is done
> even
> >> >>> though we are getting the same issue.
> >> >>>
> >> >>> When i debug the code, in WebClient.invoke method this exception is
> >> >> occured.
> >> >>>
> >> >>>     protected Response handleResponse(Message outMessage, Class<?>
> >> >>> responseClass, Type genericType) {
> >> >>>           try {
> >> >>>               ResponseBuilder rb = setResponseBuilder(outMessage,
> >> >>> outMessage.getExchange());
> >> >>>               Response currentResponse = rb.clone().build();
> >> >>>               ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>
> >>
> >> >>>
> >> >>>               Object entity = readBody(currentResponse, outMessage,
> >> >>> responseClass, genericType,
> >> >>>                                        new Annotation[]{});
> >> >>>
> >> >>>               if (entity == null) {
> >> >>>                   int status = currentResponse.getStatus();
> >> >>>                   if (status >= 400) {
> >> >>>                       entity = currentResponse.getEntity();
> >> >>>                   }
> >> >>>               }
> >> >>>               rb = JAXRSUtils.fromResponse(currentResponse);
> >> >>>
> >> >>>               rb.entity(entity instanceof Response
> >> >>>                         ? ((Response)entity).getEntity() : entity);
> >> >>>
> >> >>>               Response r = rb.build();
> >> >>>               getState().setResponse(r);
> >> >>>               ((ResponseImpl)r).setOutMessage(outMessage);
> >> >>>               return r;
> >> >>>           } catch (Throwable ex) {
> >> >>>               throw (ex instanceof ProcessingException) ?
> >> >>> (ProcessingException)ex
> >> >>>                                                     : new
> >> >>> ProcessingException(ex);
> >> >>>           } finally {
> >> >>>
> >> >>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>
> >>
> >> >>
> >> >>>           }
> >> >>>       }
> >> >>>
> >> >>>
> >> >>>     public static ResponseBuilder fromResponse(Response response) {
> >> >>>           ResponseBuilder rb = toResponseBuilder(response.getStatus());
>
> >>
> >> >>> *        rb.entity(response.getEntity());
> >> >>> *        for (Map.Entry<String, List&lt;Object>> entry :
> >> >>> response.getMetadata().entrySet()) {
> >> >>>               List values = entry.getValue();
> >> >>>               for (Object value : values) {
> >> >>>                   rb.header(entry.getKey(), value);
> >> >>>               }
> >> >>>           }
> >> >>>           return rb;
> >> >>>       }
> >> >>>
> >> >>> * rb.entity(response.getEntity());
> >> >>> * seems like , entity is null in ResponseBuilder rb from the
> >> >> fromResponse
> >> >>> method.
> >> >>>
> >> >>> Please let me know, what could be the solution to fix this issue?
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> View this message in context: http://cxf.547215.n5.nabble.
> >> >> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>
> >> >>> Sent from the cxf-user mailing list archive at Nabble.com.
> >> >>>
> >> >>
> >> >>
> >> >> --
> >> >> Sergey Beryozkin
> >> >>
> >> >> Talend Community Coders
> >> >> http://coders.talend.com/
> >> >>
> >> >>
> >> >> ------------------------------
> >> >> If you reply to this email, your message will be added to the
> >> discussion
> >> >> below:
> >> >> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
> >> Response-objects-
> >> >> tp5748134p5782725.html
> >> >> To unsubscribe from Closing of WebClient and Response objects, click
> >> here
> >> >> <
> >> >> .
> >> >> NAML
> >> >> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
> >> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
> >> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
> >> web.template.NabbleNamespace-nabble.view.web.template.
> >> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
> >> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
> >> instant_email%21nabble%3Aemail.naml>
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > View this message in context: http://cxf.547215.n5.nabble.
> >> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
> >> > Sent from the cxf-user mailing list archive at Nabble.com.
> >> >
> >>
> >>
> >> ------------------------------
> >> If you reply to this email, your message will be added to the
> discussion
> >> below:
> >> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
> Response-objects-
> >> tp5748134p5782757.html
> >> To unsubscribe from Closing of WebClient and Response objects, click
> here
> >> <
> >> .
> >> NAML
> >> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
> web.template.NabbleNamespace-nabble.view.web.template.
> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
> instant_email%21nabble%3Aemail.naml>
> >>
> >
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.
> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
> tp5748134p5782769.html
> To unsubscribe from Closing of WebClient and Response objects, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782841.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
When .readEntity is called, it is supposed to close InputStream 
immediately after it has been consumed, ex, read and Book instance 
constructed.
Closing it immediately caused some production issues in cases where the 
InputStream is consumed lazily. Ex, if DOM(4J) object is returned.

If auto-close is enabled then the stream will be closed inside 
readEntity, otherwise - if you call .close() - internally it is still 
input stream, I vaguely recall that some TCK tests terminate the request 
with String or something like that and hence you see the checks if the 
entity is instance of InputStream...

Sergey
On 17/08/17 08:14, Jose María Zaragoza wrote:
> 2017-08-16 23:18 GMT+02:00 sbalustar <bs...@gmail.com>:
>> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like below
>>
>>
>>      public Object getEntity() {
>>          return InjectionUtils.getEntity(getActualEntity());
>>      }
>>
>>
>>    public Object getActualEntity() {
>>          checkEntityIsClosed();
>>          return lastEntity != null ? lastEntity : entity;
>>      }
>>
>>    private void checkEntityIsClosed() {
>>
>>          if (entityClosed) {
>>
>>              throw new IllegalStateException("Entity is not available");
>>
>>          }
>>
>>      }
>>
>>
>>   public void close() throws ProcessingException {
>>
>>          if (!entityClosed) {
>>
>>              if (!entityBufferred && entity instanceof InputStream) {
>>
>>                  try {
>>
>>                      ((InputStream)entity).close();
>>
>>                  } catch (IOException ex) {
>>
>>                      throw new ResponseProcessingException(this, ex);
>>
>>                  }
>>
>>              }
>>
>>              entity = null;
>>
>>              entityClosed = true;
>>
>>          }
>>
>>
>>
>>      }
> 
> 
> 
> Hi:
> 
> Sorry for this semi-offtopic, but there is something I don't understand
> 
> I thought that Response.close() method performed a close in InputStream object
> associated to the underlying HttpURLConnection object.
> 
> But I see that Response.close() only closes entity  **if entity is an
> InputStream**
> The beginning of the thread was about if it was necessary to close
> Response instance explicitly.
> 
> What about if I do
> 
> Book book = response.readEntity(Book.class)
> 
> ?
> 
> Should I close the response object ?
> I see that autoclose() only is called if class is not InputStream ,
> but close() required that entity be InputStream
> 
> I know I'm loosing something ( maybe mixing concepts )
> 
> Regards
> 
> 
>> In the readEntity method, there is a call to close() method which the
>> entityClosed variable value is set to true. When calling the getEntity()
>> method , there is a another method call checkEntityIsClosed is throwing the
>> exception because the entityClosed is set to true in readEntity.
>>
>>
>> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
>> simply it returns the entity
>>
>> public Object getEntity() {
>>          return lastEntity != null ? lastEntity : entity;
>>      }
>>
>>
>> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>> ml+s547215n5782757h1@n5.nabble.com> wrote:
>>
>>> Hi, that will need to be measured for a concrete flow.
>>> I'm still not sure why you are seeing the failure with the auto close
>>> being on - it only takes effect after the entity has been consumed...
>>>
>>> Sergey
>>> On 16/08/17 19:03, sbalustar wrote:
>>>
>>>> Hi Sergey,
>>>>
>>>>      At runtime,  in Debug mode Changed the response.stream.auto.close=false.
>>>
>>>> Later on , i am not facing the Entity Not available Exception.
>>>>
>>>>     Is there any impact on the performance when we disabled the flag?
>>>>
>>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>>>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>>> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> I don't quite understand what the issue is, does it happen when you
>>>>> enable "response.stream.auto.close" ? If yes - what happens if you do
>>>>> not enable this property ?
>>>>>
>>>>> CXF does not auto-close the input stream by default given of the few
>>>>> well-known side-effects.
>>>>>
>>>>> Given you have already tried to debug - it is better to set a
>>> breakpoint
>>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why
>>>>> InputStream is not available in your case
>>>>>
>>>>> Cheers, Sergey
>>>>>
>>>>> On 15/08/17 23:20, sbalustar wrote:
>>>>>
>>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
>>>>> below
>>>>>> issue.
>>>>>>
>>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>>>>> Entity is
>>>>>> not available
>>>>>>        at
>>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>>
>>>>>
>>>>>>        at
>>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>>
>>>>>
>>>>>>        at
>>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>>
>>>>>>     ... 78 more
>>>>>>
>>>>>> I have gone through this ticket
>>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
>>> that
>>>>> Set
>>>>>> this property: "response.stream.auto.close" to true. This is done even
>>>>>> though we are getting the same issue.
>>>>>>
>>>>>> When i debug the code, in WebClient.invoke method this exception is
>>>>> occured.
>>>>>>
>>>>>>      protected Response handleResponse(Message outMessage, Class<?>
>>>>>> responseClass, Type genericType) {
>>>>>>            try {
>>>>>>                ResponseBuilder rb = setResponseBuilder(outMessage,
>>>>>> outMessage.getExchange());
>>>>>>                Response currentResponse = rb.clone().build();
>>>>>>                ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>>
>>>>>>
>>>>>>                Object entity = readBody(currentResponse, outMessage,
>>>>>> responseClass, genericType,
>>>>>>                                         new Annotation[]{});
>>>>>>
>>>>>>                if (entity == null) {
>>>>>>                    int status = currentResponse.getStatus();
>>>>>>                    if (status >= 400) {
>>>>>>                        entity = currentResponse.getEntity();
>>>>>>                    }
>>>>>>                }
>>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
>>>>>>
>>>>>>                rb.entity(entity instanceof Response
>>>>>>                          ? ((Response)entity).getEntity() : entity);
>>>>>>
>>>>>>                Response r = rb.build();
>>>>>>                getState().setResponse(r);
>>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
>>>>>>                return r;
>>>>>>            } catch (Throwable ex) {
>>>>>>                throw (ex instanceof ProcessingException) ?
>>>>>> (ProcessingException)ex
>>>>>>                                                      : new
>>>>>> ProcessingException(ex);
>>>>>>            } finally {
>>>>>>
>>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>>
>>>>>
>>>>>>            }
>>>>>>        }
>>>>>>
>>>>>>
>>>>>>      public static ResponseBuilder fromResponse(Response response) {
>>>>>>            ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>>
>>>>>> *        rb.entity(response.getEntity());
>>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>>>>> response.getMetadata().entrySet()) {
>>>>>>                List values = entry.getValue();
>>>>>>                for (Object value : values) {
>>>>>>                    rb.header(entry.getKey(), value);
>>>>>>                }
>>>>>>            }
>>>>>>            return rb;
>>>>>>        }
>>>>>>
>>>>>> * rb.entity(response.getEntity());
>>>>>> * seems like , entity is null in ResponseBuilder rb from the
>>>>> fromResponse
>>>>>> method.
>>>>>>
>>>>>> Please let me know, what could be the solution to fix this issue?
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Sergey Beryozkin
>>>>>
>>>>> Talend Community Coders
>>>>> http://coders.talend.com/
>>>>>
>>>>>
>>>>> ------------------------------
>>>>> If you reply to this email, your message will be added to the
>>> discussion
>>>>> below:
>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
>>> Response-objects-
>>>>> tp5748134p5782725.html
>>>>> To unsubscribe from Closing of WebClient and Response objects, click
>>> here
>>>>> <
>>>>> .
>>>>> NAML
>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
>>> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
>>> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
>>> web.template.NabbleNamespace-nabble.view.web.template.
>>> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
>>> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
>>> instant_email%21nabble%3Aemail.naml>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://cxf.547215.n5.nabble.
>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>
>>>
>>>
>>> ------------------------------
>>> If you reply to this email, your message will be added to the discussion
>>> below:
>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
>>> tp5748134p5782757.html
>>> To unsubscribe from Closing of WebClient and Response objects, click here
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>>> .
>>> NAML
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>
>>
>>
>>
>> --
>> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
>> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Closing of WebClient and Response objects

Posted by Jose María Zaragoza <de...@gmail.com>.
2017-08-16 23:18 GMT+02:00 sbalustar <bs...@gmail.com>:
> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like below
>
>
>     public Object getEntity() {
>         return InjectionUtils.getEntity(getActualEntity());
>     }
>
>
>   public Object getActualEntity() {
>         checkEntityIsClosed();
>         return lastEntity != null ? lastEntity : entity;
>     }
>
>   private void checkEntityIsClosed() {
>
>         if (entityClosed) {
>
>             throw new IllegalStateException("Entity is not available");
>
>         }
>
>     }
>
>
>  public void close() throws ProcessingException {
>
>         if (!entityClosed) {
>
>             if (!entityBufferred && entity instanceof InputStream) {
>
>                 try {
>
>                     ((InputStream)entity).close();
>
>                 } catch (IOException ex) {
>
>                     throw new ResponseProcessingException(this, ex);
>
>                 }
>
>             }
>
>             entity = null;
>
>             entityClosed = true;
>
>         }
>
>
>
>     }



Hi:

Sorry for this semi-offtopic, but there is something I don't understand

I thought that Response.close() method performed a close in InputStream object
associated to the underlying HttpURLConnection object.

But I see that Response.close() only closes entity  **if entity is an
InputStream**
The beginning of the thread was about if it was necessary to close
Response instance explicitly.

What about if I do

Book book = response.readEntity(Book.class)

?

Should I close the response object ?
I see that autoclose() only is called if class is not InputStream ,
but close() required that entity be InputStream

I know I'm loosing something ( maybe mixing concepts )

Regards


> In the readEntity method, there is a call to close() method which the
> entityClosed variable value is set to true. When calling the getEntity()
> method , there is a another method call checkEntityIsClosed is throwing the
> exception because the entityClosed is set to true in readEntity.
>
>
> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
> simply it returns the entity
>
> public Object getEntity() {
>         return lastEntity != null ? lastEntity : entity;
>     }
>
>
> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
> ml+s547215n5782757h1@n5.nabble.com> wrote:
>
>> Hi, that will need to be measured for a concrete flow.
>> I'm still not sure why you are seeing the failure with the auto close
>> being on - it only takes effect after the entity has been consumed...
>>
>> Sergey
>> On 16/08/17 19:03, sbalustar wrote:
>>
>> > Hi Sergey,
>> >
>> >     At runtime,  in Debug mode Changed the response.stream.auto.close=false.
>>
>> > Later on , i am not facing the Entity Not available Exception.
>> >
>> >    Is there any impact on the performance when we disabled the flag?
>> >
>> > On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>> wrote:
>> >
>> >> Hi
>> >>
>> >> I don't quite understand what the issue is, does it happen when you
>> >> enable "response.stream.auto.close" ? If yes - what happens if you do
>> >> not enable this property ?
>> >>
>> >> CXF does not auto-close the input stream by default given of the few
>> >> well-known side-effects.
>> >>
>> >> Given you have already tried to debug - it is better to set a
>> breakpoint
>> >> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why
>> >> InputStream is not available in your case
>> >>
>> >> Cheers, Sergey
>> >>
>> >> On 15/08/17 23:20, sbalustar wrote:
>> >>
>> >>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
>> >> below
>> >>> issue.
>> >>>
>> >>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>> >>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>> >> Entity is
>> >>> not available
>> >>>       at
>> >>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>
>> >>
>> >>>       at
>> >>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>
>> >>
>> >>>       at
>> >>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>
>> >>>    ... 78 more
>> >>>
>> >>> I have gone through this ticket
>> >>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
>> that
>> >> Set
>> >>> this property: "response.stream.auto.close" to true. This is done even
>> >>> though we are getting the same issue.
>> >>>
>> >>> When i debug the code, in WebClient.invoke method this exception is
>> >> occured.
>> >>>
>> >>>     protected Response handleResponse(Message outMessage, Class<?>
>> >>> responseClass, Type genericType) {
>> >>>           try {
>> >>>               ResponseBuilder rb = setResponseBuilder(outMessage,
>> >>> outMessage.getExchange());
>> >>>               Response currentResponse = rb.clone().build();
>> >>>               ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>
>> >>>
>> >>>               Object entity = readBody(currentResponse, outMessage,
>> >>> responseClass, genericType,
>> >>>                                        new Annotation[]{});
>> >>>
>> >>>               if (entity == null) {
>> >>>                   int status = currentResponse.getStatus();
>> >>>                   if (status >= 400) {
>> >>>                       entity = currentResponse.getEntity();
>> >>>                   }
>> >>>               }
>> >>>               rb = JAXRSUtils.fromResponse(currentResponse);
>> >>>
>> >>>               rb.entity(entity instanceof Response
>> >>>                         ? ((Response)entity).getEntity() : entity);
>> >>>
>> >>>               Response r = rb.build();
>> >>>               getState().setResponse(r);
>> >>>               ((ResponseImpl)r).setOutMessage(outMessage);
>> >>>               return r;
>> >>>           } catch (Throwable ex) {
>> >>>               throw (ex instanceof ProcessingException) ?
>> >>> (ProcessingException)ex
>> >>>                                                     : new
>> >>> ProcessingException(ex);
>> >>>           } finally {
>> >>>
>> >>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>
>> >>
>> >>>           }
>> >>>       }
>> >>>
>> >>>
>> >>>     public static ResponseBuilder fromResponse(Response response) {
>> >>>           ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>
>> >>> *        rb.entity(response.getEntity());
>> >>> *        for (Map.Entry<String, List&lt;Object>> entry :
>> >>> response.getMetadata().entrySet()) {
>> >>>               List values = entry.getValue();
>> >>>               for (Object value : values) {
>> >>>                   rb.header(entry.getKey(), value);
>> >>>               }
>> >>>           }
>> >>>           return rb;
>> >>>       }
>> >>>
>> >>> * rb.entity(response.getEntity());
>> >>> * seems like , entity is null in ResponseBuilder rb from the
>> >> fromResponse
>> >>> method.
>> >>>
>> >>> Please let me know, what could be the solution to fix this issue?
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> View this message in context: http://cxf.547215.n5.nabble.
>> >> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>> >>> Sent from the cxf-user mailing list archive at Nabble.com.
>> >>>
>> >>
>> >>
>> >> --
>> >> Sergey Beryozkin
>> >>
>> >> Talend Community Coders
>> >> http://coders.talend.com/
>> >>
>> >>
>> >> ------------------------------
>> >> If you reply to this email, your message will be added to the
>> discussion
>> >> below:
>> >> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
>> Response-objects-
>> >> tp5748134p5782725.html
>> >> To unsubscribe from Closing of WebClient and Response objects, click
>> here
>> >> <
>> >> .
>> >> NAML
>> >> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
>> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
>> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
>> web.template.NabbleNamespace-nabble.view.web.template.
>> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
>> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
>> instant_email%21nabble%3Aemail.naml>
>> >>
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context: http://cxf.547215.n5.nabble.
>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>> > Sent from the cxf-user mailing list archive at Nabble.com.
>> >
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
>> tp5748134p5782757.html
>> To unsubscribe from Closing of WebClient and Response objects, click here
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>> .
>> NAML
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like below


    public Object getEntity() {
        return InjectionUtils.getEntity(getActualEntity());
    }


  public Object getActualEntity() {
        checkEntityIsClosed();
        return lastEntity != null ? lastEntity : entity;
    }

  private void checkEntityIsClosed() {

        if (entityClosed) {

            throw new IllegalStateException("Entity is not available");

        }

    }


 public void close() throws ProcessingException {

        if (!entityClosed) {

            if (!entityBufferred && entity instanceof InputStream) {

                try {

                    ((InputStream)entity).close();

                } catch (IOException ex) {

                    throw new ResponseProcessingException(this, ex);

                }

            }

            entity = null;

            entityClosed = true;

        }



    }
In the readEntity method, there is a call to close() method which the
entityClosed variable value is set to true. When calling the getEntity()
method , there is a another method call checkEntityIsClosed is throwing the
exception because the entityClosed is set to true in readEntity.


But In CXF 2.7.7,  there is no method call in the getEntity() method ,
simply it returns the entity

public Object getEntity() {
        return lastEntity != null ? lastEntity : entity;
    }


On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
ml+s547215n5782757h1@n5.nabble.com> wrote:

> Hi, that will need to be measured for a concrete flow.
> I'm still not sure why you are seeing the failure with the auto close
> being on - it only takes effect after the entity has been consumed...
>
> Sergey
> On 16/08/17 19:03, sbalustar wrote:
>
> > Hi Sergey,
> >
> >     At runtime,  in Debug mode Changed the response.stream.auto.close=false.
>
> > Later on , i am not facing the Entity Not available Exception.
> >
> >    Is there any impact on the performance when we disabled the flag?
> >
> > On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
> wrote:
> >
> >> Hi
> >>
> >> I don't quite understand what the issue is, does it happen when you
> >> enable "response.stream.auto.close" ? If yes - what happens if you do
> >> not enable this property ?
> >>
> >> CXF does not auto-close the input stream by default given of the few
> >> well-known side-effects.
> >>
> >> Given you have already tried to debug - it is better to set a
> breakpoint
> >> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why
> >> InputStream is not available in your case
> >>
> >> Cheers, Sergey
> >>
> >> On 15/08/17 23:20, sbalustar wrote:
> >>
> >>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
> >> below
> >>> issue.
> >>>
> >>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
> >>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
> >> Entity is
> >>> not available
> >>>       at
> >>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>
> >>
> >>>       at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>
> >>
> >>>       at
> >>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>
> >>
> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>
> >>
> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>
> >>
> >>>       at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>
> >>
> >>>       at
> >>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>
> >>>    ... 78 more
> >>>
> >>> I have gone through this ticket
> >>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
> that
> >> Set
> >>> this property: "response.stream.auto.close" to true. This is done even
> >>> though we are getting the same issue.
> >>>
> >>> When i debug the code, in WebClient.invoke method this exception is
> >> occured.
> >>>
> >>>     protected Response handleResponse(Message outMessage, Class<?>
> >>> responseClass, Type genericType) {
> >>>           try {
> >>>               ResponseBuilder rb = setResponseBuilder(outMessage,
> >>> outMessage.getExchange());
> >>>               Response currentResponse = rb.clone().build();
> >>>               ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>
> >>>
> >>>               Object entity = readBody(currentResponse, outMessage,
> >>> responseClass, genericType,
> >>>                                        new Annotation[]{});
> >>>
> >>>               if (entity == null) {
> >>>                   int status = currentResponse.getStatus();
> >>>                   if (status >= 400) {
> >>>                       entity = currentResponse.getEntity();
> >>>                   }
> >>>               }
> >>>               rb = JAXRSUtils.fromResponse(currentResponse);
> >>>
> >>>               rb.entity(entity instanceof Response
> >>>                         ? ((Response)entity).getEntity() : entity);
> >>>
> >>>               Response r = rb.build();
> >>>               getState().setResponse(r);
> >>>               ((ResponseImpl)r).setOutMessage(outMessage);
> >>>               return r;
> >>>           } catch (Throwable ex) {
> >>>               throw (ex instanceof ProcessingException) ?
> >>> (ProcessingException)ex
> >>>                                                     : new
> >>> ProcessingException(ex);
> >>>           } finally {
> >>>
> >>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>
> >>
> >>>           }
> >>>       }
> >>>
> >>>
> >>>     public static ResponseBuilder fromResponse(Response response) {
> >>>           ResponseBuilder rb = toResponseBuilder(response.getStatus());
>
> >>> *        rb.entity(response.getEntity());
> >>> *        for (Map.Entry<String, List&lt;Object>> entry :
> >>> response.getMetadata().entrySet()) {
> >>>               List values = entry.getValue();
> >>>               for (Object value : values) {
> >>>                   rb.header(entry.getKey(), value);
> >>>               }
> >>>           }
> >>>           return rb;
> >>>       }
> >>>
> >>> * rb.entity(response.getEntity());
> >>> * seems like , entity is null in ResponseBuilder rb from the
> >> fromResponse
> >>> method.
> >>>
> >>> Please let me know, what could be the solution to fix this issue?
> >>>
> >>>
> >>>
> >>> --
> >>> View this message in context: http://cxf.547215.n5.nabble.
> >> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
> >>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>
> >>
> >>
> >> --
> >> Sergey Beryozkin
> >>
> >> Talend Community Coders
> >> http://coders.talend.com/
> >>
> >>
> >> ------------------------------
> >> If you reply to this email, your message will be added to the
> discussion
> >> below:
> >> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-
> Response-objects-
> >> tp5748134p5782725.html
> >> To unsubscribe from Closing of WebClient and Response objects, click
> here
> >> <
> >> .
> >> NAML
> >> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
> web.template.NabbleNamespace-nabble.view.web.template.
> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
> instant_email%21nabble%3Aemail.naml>
> >>
> >
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.
> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
> tp5748134p5782757.html
> To unsubscribe from Closing of WebClient and Response objects, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782758.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Thanks Sergey .
Can you please release a patch for this fix.


On Wed, Aug 16, 2017 at 3:37 PM, Sergey Beryozkin [via CXF] <
ml+s547215n5782765h49@n5.nabble.com> wrote:

> Yes, I see "response.stream.auto.close" does not work if you do
> something like
>
> webCliemt.get(Book.class)
>
> but does work if you do
>
> webCliemt.get().readEntity(Book.class)
>
> I recall now I might've implemented this property while working on
> JAX-RS 2.0 impl of Response which talks about this auto-closing in its
> docs, while the usage of this property in a case where response is read
> implicitly was not taken care of
>
> So if you'd do to continue doing the auto-closing just follow
>
> webCliemt.get().readEntity(Book.class) pattern
>
> in meantime I'll have a look at this property working in a
>
> webCliemt.get(Book.class)
>
> Sergey
>
> On 16/08/17 23:04, sbalustar wrote:
>
> > Sergey ,
> >
> > In CXF 2.7.7, in readBody method, there is no call for readEntity, thats
> > why it is not throwing any exception . But in 3.1.8 , first readEntity
> > method is called and later getEntity method is called.   Seems like it
> is
> > Bug in AbstractClient.java in 3.1.8 version. What do you say?
> >
> > On Wed, Aug 16, 2017 at 2:51 PM, Balakrishna Sudabathula <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782765&i=0>>
> wrote:
> >
> >> readBody method code ()
> >>
> >>      protected <T> T readBody(Response r, Message outMessage, Class<T>
> cls,
> >>
> >>
> >>                               Type type, Annotation[] anns) {
> >>
> >>
> >>
> >>          if (cls == Response.class) {
> >>
> >>              return cls.cast(r);
> >>
> >>          }
> >>
> >>
> >>
> >>          int status = r.getStatus();
> >>
> >>          if ((status < 200 || status == 204) && r.getLength() <= 0 ||
> >> status >= 300) {
> >>
> >>              return null;
> >>
> >>          }
> >>
> >>          return ((ResponseImpl)r).doReadEntity(cls, type, anns);
> >>
> >>
> >>      }
> >>
> >> On Wed, Aug 16, 2017 at 2:48 PM, Balakrishna Sudabathula <
> >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782765&i=1>>
> wrote:
> >>
> >>> Please find the attachement. In WebClient handle handleResponse ()
> method
> >>> there is method call readBody (), in that method readEntity method is
> >>> called. After that there is another method call
>  JAXRSUtils.fromRespons
> >>> which is calling getEntity method
> >>>
> >>>
> >>>
> >>> On Wed, Aug 16, 2017 at 2:29 PM, Sergey Beryozkin [via CXF] <
> >>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782765&i=2>>
> wrote:
> >>>
> >>>> So where is readEntity is called from ?
> >>>> On 16/08/17 22:26, sbalustar wrote:
> >>>>
> >>>>> In CXF 3.1.8
> >>>>>
> >>>>> There is a call in readEntity menthod autoClose(), but in cxf 2.7.7
> >>>>   there
> >>>>> is no such method call.
> >>>>>
> >>>>>      protected void autoClose(Class<?> cls, boolean exception) {
> >>>>>
> >>>>>           if (!entityBufferred && cls != InputStream.class
> >>>>>
> >>>>>               && (exception || MessageUtils.isTrue(outMessage
> >>>>> .getContextualProperty("response.stream.auto.close")))) {
> >>>>>
> >>>>>               close();
> >>>>>
> >>>>>           }
> >>>>>
> >>>>>       }
> >>>>>
> >>>>>
> >>>>> If the auto close is set to true , then it is calling close method ,
> >>>> and
> >>>>> changing the entityClosed value to true.
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
> >>>>> [hidden email] <http:///user/SendEmail.jtp?
> type=node&node=5782761&i=0>>
> >>>> wrote:
> >>>>>
> >>>>>> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is
> like
> >>>> below
> >>>>>>
> >>>>>>
> >>>>>>       public Object getEntity() {
> >>>>>>           return InjectionUtils.getEntity(getActualEntity());
> >>>>>>       }
> >>>>>>
> >>>>>>
> >>>>>>     public Object getActualEntity() {
> >>>>>>           checkEntityIsClosed();
> >>>>>>           return lastEntity != null ? lastEntity : entity;
> >>>>>>       }
> >>>>>>
> >>>>>>     private void checkEntityIsClosed() {
> >>>>>>
> >>>>>>           if (entityClosed) {
> >>>>>>
> >>>>>>               throw new IllegalStateException("Entity is not
> >>>> available");
> >>>>>>
> >>>>>>           }
> >>>>>>
> >>>>>>       }
> >>>>>>
> >>>>>>
> >>>>>>    public void close() throws ProcessingException {
> >>>>>>
> >>>>>>           if (!entityClosed) {
> >>>>>>
> >>>>>>               if (!entityBufferred && entity instanceof
> InputStream) {
> >>>>>>
> >>>>>>                   try {
> >>>>>>
> >>>>>>                       ((InputStream)entity).close();
> >>>>>>
> >>>>>>                   } catch (IOException ex) {
> >>>>>>
> >>>>>>                       throw new ResponseProcessingException(this,
> >>>> ex);
> >>>>>>
> >>>>>>                   }
> >>>>>>
> >>>>>>               }
> >>>>>>
> >>>>>>               entity = null;
> >>>>>>
> >>>>>>               entityClosed = true;
> >>>>>>
> >>>>>>           }
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>       }
> >>>>>> In the readEntity method, there is a call to close() method which
> the
> >>>>>> entityClosed variable value is set to true. When calling the
> >>>> getEntity()
> >>>>>> method , there is a another method call checkEntityIsClosed is
> >>>> throwing the
> >>>>>> exception because the entityClosed is set to true in readEntity.
> >>>>>>
> >>>>>>
> >>>>>> But In CXF 2.7.7,  there is no method call in the getEntity()
> method
> >>>> ,
> >>>>>> simply it returns the entity
> >>>>>>
> >>>>>> public Object getEntity() {
> >>>>>>           return lastEntity != null ? lastEntity : entity;
> >>>>>>       }
> >>>>>>
> >>>>>>
> >>>>>> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
> >>>>>> [hidden email]
> >>>> <http:///user/SendEmail.jtp?type=node&node=5782761&i=1>> wrote:
> >>>>>>
> >>>>>>> Hi, that will need to be measured for a concrete flow.
> >>>>>>> I'm still not sure why you are seeing the failure with the auto
> >>>> close
> >>>>>>> being on - it only takes effect after the entity has been
> >>>> consumed...
> >>>>>>>
> >>>>>>> Sergey
> >>>>>>> On 16/08/17 19:03, sbalustar wrote:
> >>>>>>>
> >>>>>>>> Hi Sergey,
> >>>>>>>>
> >>>>>>>>       At runtime,  in Debug mode Changed the
> >>>>>>> response.stream.auto.close=false.
> >>>>>>>> Later on , i am not facing the Entity Not available Exception.
> >>>>>>>>
> >>>>>>>>      Is there any impact on the performance when we disabled the
> >>>> flag?
> >>>>>>>>
> >>>>>>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
> >>>>>>>> [hidden email] <http:///user/SendEmail.jtp?ty
> >>>> pe=node&node=5782757&i=0>>
> >>>>>>> wrote:
> >>>>>>>>
> >>>>>>>>> Hi
> >>>>>>>>>
> >>>>>>>>> I don't quite understand what the issue is, does it happen when
> >>>> you
> >>>>>>>>> enable "response.stream.auto.close" ? If yes - what happens if
> you
> >>>> do
> >>>>>>>>> not enable this property ?
> >>>>>>>>>
> >>>>>>>>> CXF does not auto-close the input stream by default given of the
> >>>> few
> >>>>>>>>> well-known side-effects.
> >>>>>>>>>
> >>>>>>>>> Given you have already tried to debug - it is better to set a
> >>>>>>> breakpoint
> >>>>>>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will
> >>>> see
> >>>>>>> why
> >>>>>>>>> InputStream is not available in your case
> >>>>>>>>>
> >>>>>>>>> Cheers, Sergey
> >>>>>>>>>
> >>>>>>>>> On 15/08/17 23:20, sbalustar wrote:
> >>>>>>>>>
> >>>>>>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and
> facing
> >>>> the
> >>>>>>>>> below
> >>>>>>>>>> issue.
> >>>>>>>>>>
> >>>>>>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
> >>>>>>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>
> >>>>
> >>>>>>>>> Entity is
> >>>>>>>>>> not available
> >>>>>>>>>>         at
> >>>>>>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>
> >>>>
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
> >>>> bClient.doResponse(WebClient.java:1110)
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>         at
> >>>>>>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>
> >>>>
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
> >>>> bClient.doInvoke(WebClient.java:892)
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
> >>>> bClient.doInvoke(WebClient.java:863)
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
> >>>> bClient.invoke(WebClient.java:413)
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>         at
> >>>>>>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>
> >>>>
> >>>>>>>
> >>>>>>>>>>      ... 78 more
> >>>>>>>>>>
> >>>>>>>>>> I have gone through this ticket
> >>>>>>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you
> >>>> mentioned
> >>>>>>> that
> >>>>>>>>> Set
> >>>>>>>>>> this property: "response.stream.auto.close" to true. This is
> done
> >>>>>>> even
> >>>>>>>>>> though we are getting the same issue.
> >>>>>>>>>>
> >>>>>>>>>> When i debug the code, in WebClient.invoke method this
> exception
> >>>> is
> >>>>>>>>> occured.
> >>>>>>>>>>
> >>>>>>>>>>       protected Response handleResponse(Message outMessage,
> >>>> Class<?>
> >>>>>>>>>> responseClass, Type genericType) {
> >>>>>>>>>>             try {
> >>>>>>>>>>                 ResponseBuilder rb =
> >>>> setResponseBuilder(outMessage,
> >>>>>>>>>> outMessage.getExchange());
> >>>>>>>>>>                 Response currentResponse = rb.clone().build();
> >>>>>>>>>>                 ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>
> >>>>
> >>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>                 Object entity = readBody(currentResponse,
> >>>> outMessage,
> >>>>>>>>>> responseClass, genericType,
> >>>>>>>>>>                                          new Annotation[]{});
> >>>>>>>>>>
> >>>>>>>>>>                 if (entity == null) {
> >>>>>>>>>>                     int status = currentResponse.getStatus();
> >>>>>>>>>>                     if (status >= 400) {
> >>>>>>>>>>                         entity = currentResponse.getEntity();
> >>>>>>>>>>                     }
> >>>>>>>>>>                 }
> >>>>>>>>>>                 rb = JAXRSUtils.fromResponse(currentResponse);
> >>>>>>>>>>
> >>>>>>>>>>                 rb.entity(entity instanceof Response
> >>>>>>>>>>                           ? ((Response)entity).getEntity() :
> >>>> entity);
> >>>>>>>>>>
> >>>>>>>>>>                 Response r = rb.build();
> >>>>>>>>>>                 getState().setResponse(r);
> >>>>>>>>>>                 ((ResponseImpl)r).setOutMessage(outMessage);
> >>>>>>>>>>                 return r;
> >>>>>>>>>>             } catch (Throwable ex) {
> >>>>>>>>>>                 throw (ex instanceof ProcessingException) ?
> >>>>>>>>>> (ProcessingException)ex
> >>>>>>>>>>                                                       : new
> >>>>>>>>>> ProcessingException(ex);
> >>>>>>>>>>             } finally {
> >>>>>>>>>>
> >>>>>>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>
> >>>>
> >>>>>>>
> >>>>>>>>>
> >>>>>>>>>>             }
> >>>>>>>>>>         }
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>       public static ResponseBuilder fromResponse(Response
> >>>> response) {
> >>>>>>>>>>             ResponseBuilder rb = toResponseBuilder(response.getStatus());
>
> >>>>
> >>>>>>>
> >>>>>>>>>> *        rb.entity(response.getEntity());
> >>>>>>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
> >>>>>>>>>> response.getMetadata().entrySet()) {
> >>>>>>>>>>                 List values = entry.getValue();
> >>>>>>>>>>                 for (Object value : values) {
> >>>>>>>>>>                     rb.header(entry.getKey(), value);
> >>>>>>>>>>                 }
> >>>>>>>>>>             }
> >>>>>>>>>>             return rb;
> >>>>>>>>>>         }
> >>>>>>>>>>
> >>>>>>>>>> * rb.entity(response.getEntity());
> >>>>>>>>>> * seems like , entity is null in ResponseBuilder rb from the
> >>>>>>>>> fromResponse
> >>>>>>>>>> method.
> >>>>>>>>>>
> >>>>>>>>>> Please let me know, what could be the solution to fix this
> issue?
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>> --
> >>>>>>>>>> View this message in context: http://cxf.547215.n5.nabble.
> >>>>>>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>
> >>>>
> >>>>>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> --
> >>>>>>>>> Sergey Beryozkin
> >>>>>>>>>
> >>>>>>>>> Talend Community Coders
> >>>>>>>>> http://coders.talend.com/
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>> ------------------------------
> >>>>>>>>> If you reply to this email, your message will be added to the
> >>>>>>> discussion
> >>>>>>>>> below:
> >>>>>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
> >>>>>>> ponse-objects-
> >>>>>>>>> tp5748134p5782725.html
> >>>>>>>>> To unsubscribe from Closing of WebClient and Response objects,
> >>>> click
> >>>>>>> here
> >>>>>>>>> <
> >>>>>>>>> .
> >>>>>>>>> NAML
> >>>>>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
> >>>>>>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
> >>>>>>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
> >>>>>>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
> >>>>>>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
> >>>>>>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
> >>>>>>> email%21nabble%3Aemail.naml>
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>> --
> >>>>>>>> View this message in context: http://cxf.547215.n5.nabble.co
> >>>>>>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>
> >>>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> ------------------------------
> >>>>>>> If you reply to this email, your message will be added to the
> >>>> discussion
> >>>>>>> below:
> >>>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
> >>>>>>> ponse-objects-tp5748134p5782757.html
> >>>>>>> To unsubscribe from Closing of WebClient and Response objects,
> click
> >>>> here
> >>>>>>> <
> >>>>>>> .
> >>>>>>> NAML
> >>>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
> >>>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
> >>>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.templa
> >>>> te.NabbleNamespace-nabble.view.web.template.NodeNamespac
> >>>> e&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-
> >>>> instant_emails%21nabble%3Aemail.naml-send_instant_email%
> >>>> 21nabble%3Aemail.naml>
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> View this message in context: http://cxf.547215.n5.nabble.co
> >>>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
> >>>>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>>>
> >>>>
> >>>>
> >>>> --
> >>>> Sergey Beryozkin
> >>>>
> >>>> Talend Community Coders
> >>>> http://coders.talend.com/
> >>>>
> >>>>
> >>>> ------------------------------
> >>>> If you reply to this email, your message will be added to the
> discussion
> >>>> below:
> >>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
> >>>> ponse-objects-tp5748134p5782761.html
> >>>> To unsubscribe from Closing of WebClient and Response objects, click
> >>>> here
> >>>> <
> >>>> .
> >>>> NAML
> >>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
> web.template.NabbleNamespace-nabble.view.web.template.
> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
> instant_email%21nabble%3Aemail.naml>
> >>>>
> >>>
> >>>
> >>
> >
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.
> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782764.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
> tp5748134p5782765.html
> To unsubscribe from Closing of WebClient and Response objects, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782766.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
Yes, I see "response.stream.auto.close" does not work if you do 
something like

webCliemt.get(Book.class)

but does work if you do

webCliemt.get().readEntity(Book.class)

I recall now I might've implemented this property while working on 
JAX-RS 2.0 impl of Response which talks about this auto-closing in its 
docs, while the usage of this property in a case where response is read 
implicitly was not taken care of

So if you'd do to continue doing the auto-closing just follow

webCliemt.get().readEntity(Book.class) pattern

in meantime I'll have a look at this property working in a

webCliemt.get(Book.class)

Sergey

On 16/08/17 23:04, sbalustar wrote:
> Sergey ,
> 
> In CXF 2.7.7, in readBody method, there is no call for readEntity, thats
> why it is not throwing any exception . But in 3.1.8 , first readEntity
> method is called and later getEntity method is called.   Seems like it is
> Bug in AbstractClient.java in 3.1.8 version. What do you say?
> 
> On Wed, Aug 16, 2017 at 2:51 PM, Balakrishna Sudabathula <
> bsudabathula@gmail.com> wrote:
> 
>> readBody method code ()
>>
>>      protected <T> T readBody(Response r, Message outMessage, Class<T> cls,
>>
>>
>>                               Type type, Annotation[] anns) {
>>
>>
>>
>>          if (cls == Response.class) {
>>
>>              return cls.cast(r);
>>
>>          }
>>
>>
>>
>>          int status = r.getStatus();
>>
>>          if ((status < 200 || status == 204) && r.getLength() <= 0 ||
>> status >= 300) {
>>
>>              return null;
>>
>>          }
>>
>>          return ((ResponseImpl)r).doReadEntity(cls, type, anns);
>>
>>
>>      }
>>
>> On Wed, Aug 16, 2017 at 2:48 PM, Balakrishna Sudabathula <
>> bsudabathula@gmail.com> wrote:
>>
>>> Please find the attachement. In WebClient handle handleResponse () method
>>> there is method call readBody (), in that method readEntity method is
>>> called. After that there is another method call  JAXRSUtils.fromRespons
>>> which is calling getEntity method
>>>
>>>
>>>
>>> On Wed, Aug 16, 2017 at 2:29 PM, Sergey Beryozkin [via CXF] <
>>> ml+s547215n5782761h25@n5.nabble.com> wrote:
>>>
>>>> So where is readEntity is called from ?
>>>> On 16/08/17 22:26, sbalustar wrote:
>>>>
>>>>> In CXF 3.1.8
>>>>>
>>>>> There is a call in readEntity menthod autoClose(), but in cxf 2.7.7
>>>>   there
>>>>> is no such method call.
>>>>>
>>>>>      protected void autoClose(Class<?> cls, boolean exception) {
>>>>>
>>>>>           if (!entityBufferred && cls != InputStream.class
>>>>>
>>>>>               && (exception || MessageUtils.isTrue(outMessage
>>>>> .getContextualProperty("response.stream.auto.close")))) {
>>>>>
>>>>>               close();
>>>>>
>>>>>           }
>>>>>
>>>>>       }
>>>>>
>>>>>
>>>>> If the auto close is set to true , then it is calling close method ,
>>>> and
>>>>> changing the entityClosed value to true.
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
>>>>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782761&i=0>>
>>>> wrote:
>>>>>
>>>>>> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
>>>> below
>>>>>>
>>>>>>
>>>>>>       public Object getEntity() {
>>>>>>           return InjectionUtils.getEntity(getActualEntity());
>>>>>>       }
>>>>>>
>>>>>>
>>>>>>     public Object getActualEntity() {
>>>>>>           checkEntityIsClosed();
>>>>>>           return lastEntity != null ? lastEntity : entity;
>>>>>>       }
>>>>>>
>>>>>>     private void checkEntityIsClosed() {
>>>>>>
>>>>>>           if (entityClosed) {
>>>>>>
>>>>>>               throw new IllegalStateException("Entity is not
>>>> available");
>>>>>>
>>>>>>           }
>>>>>>
>>>>>>       }
>>>>>>
>>>>>>
>>>>>>    public void close() throws ProcessingException {
>>>>>>
>>>>>>           if (!entityClosed) {
>>>>>>
>>>>>>               if (!entityBufferred && entity instanceof InputStream) {
>>>>>>
>>>>>>                   try {
>>>>>>
>>>>>>                       ((InputStream)entity).close();
>>>>>>
>>>>>>                   } catch (IOException ex) {
>>>>>>
>>>>>>                       throw new ResponseProcessingException(this,
>>>> ex);
>>>>>>
>>>>>>                   }
>>>>>>
>>>>>>               }
>>>>>>
>>>>>>               entity = null;
>>>>>>
>>>>>>               entityClosed = true;
>>>>>>
>>>>>>           }
>>>>>>
>>>>>>
>>>>>>
>>>>>>       }
>>>>>> In the readEntity method, there is a call to close() method which the
>>>>>> entityClosed variable value is set to true. When calling the
>>>> getEntity()
>>>>>> method , there is a another method call checkEntityIsClosed is
>>>> throwing the
>>>>>> exception because the entityClosed is set to true in readEntity.
>>>>>>
>>>>>>
>>>>>> But In CXF 2.7.7,  there is no method call in the getEntity() method
>>>> ,
>>>>>> simply it returns the entity
>>>>>>
>>>>>> public Object getEntity() {
>>>>>>           return lastEntity != null ? lastEntity : entity;
>>>>>>       }
>>>>>>
>>>>>>
>>>>>> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>>>>>> [hidden email]
>>>> <http:///user/SendEmail.jtp?type=node&node=5782761&i=1>> wrote:
>>>>>>
>>>>>>> Hi, that will need to be measured for a concrete flow.
>>>>>>> I'm still not sure why you are seeing the failure with the auto
>>>> close
>>>>>>> being on - it only takes effect after the entity has been
>>>> consumed...
>>>>>>>
>>>>>>> Sergey
>>>>>>> On 16/08/17 19:03, sbalustar wrote:
>>>>>>>
>>>>>>>> Hi Sergey,
>>>>>>>>
>>>>>>>>       At runtime,  in Debug mode Changed the
>>>>>>> response.stream.auto.close=false.
>>>>>>>> Later on , i am not facing the Entity Not available Exception.
>>>>>>>>
>>>>>>>>      Is there any impact on the performance when we disabled the
>>>> flag?
>>>>>>>>
>>>>>>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>>>>>>>> [hidden email] <http:///user/SendEmail.jtp?ty
>>>> pe=node&node=5782757&i=0>>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Hi
>>>>>>>>>
>>>>>>>>> I don't quite understand what the issue is, does it happen when
>>>> you
>>>>>>>>> enable "response.stream.auto.close" ? If yes - what happens if you
>>>> do
>>>>>>>>> not enable this property ?
>>>>>>>>>
>>>>>>>>> CXF does not auto-close the input stream by default given of the
>>>> few
>>>>>>>>> well-known side-effects.
>>>>>>>>>
>>>>>>>>> Given you have already tried to debug - it is better to set a
>>>>>>> breakpoint
>>>>>>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will
>>>> see
>>>>>>> why
>>>>>>>>> InputStream is not available in your case
>>>>>>>>>
>>>>>>>>> Cheers, Sergey
>>>>>>>>>
>>>>>>>>> On 15/08/17 23:20, sbalustar wrote:
>>>>>>>>>
>>>>>>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
>>>> the
>>>>>>>>> below
>>>>>>>>>> issue.
>>>>>>>>>>
>>>>>>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>>>>>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>>>>
>>>>>>>>> Entity is
>>>>>>>>>> not available
>>>>>>>>>>         at
>>>>>>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
>>>> bClient.doResponse(WebClient.java:1110)
>>>>>>>
>>>>>>>>>
>>>>>>>>>>         at
>>>>>>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
>>>> bClient.doInvoke(WebClient.java:892)
>>>>>>>
>>>>>>>>>
>>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
>>>> bClient.doInvoke(WebClient.java:863)
>>>>>>>
>>>>>>>>>
>>>>>>>>>>         at org.apache.cxf.jaxrs.client.We
>>>> bClient.invoke(WebClient.java:413)
>>>>>>>
>>>>>>>>>
>>>>>>>>>>         at
>>>>>>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>>>
>>>>>>>
>>>>>>>>>>      ... 78 more
>>>>>>>>>>
>>>>>>>>>> I have gone through this ticket
>>>>>>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you
>>>> mentioned
>>>>>>> that
>>>>>>>>> Set
>>>>>>>>>> this property: "response.stream.auto.close" to true. This is done
>>>>>>> even
>>>>>>>>>> though we are getting the same issue.
>>>>>>>>>>
>>>>>>>>>> When i debug the code, in WebClient.invoke method this exception
>>>> is
>>>>>>>>> occured.
>>>>>>>>>>
>>>>>>>>>>       protected Response handleResponse(Message outMessage,
>>>> Class<?>
>>>>>>>>>> responseClass, Type genericType) {
>>>>>>>>>>             try {
>>>>>>>>>>                 ResponseBuilder rb =
>>>> setResponseBuilder(outMessage,
>>>>>>>>>> outMessage.getExchange());
>>>>>>>>>>                 Response currentResponse = rb.clone().build();
>>>>>>>>>>                 ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>>>
>>>>>>>
>>>>>>>>>>
>>>>>>>>>>                 Object entity = readBody(currentResponse,
>>>> outMessage,
>>>>>>>>>> responseClass, genericType,
>>>>>>>>>>                                          new Annotation[]{});
>>>>>>>>>>
>>>>>>>>>>                 if (entity == null) {
>>>>>>>>>>                     int status = currentResponse.getStatus();
>>>>>>>>>>                     if (status >= 400) {
>>>>>>>>>>                         entity = currentResponse.getEntity();
>>>>>>>>>>                     }
>>>>>>>>>>                 }
>>>>>>>>>>                 rb = JAXRSUtils.fromResponse(currentResponse);
>>>>>>>>>>
>>>>>>>>>>                 rb.entity(entity instanceof Response
>>>>>>>>>>                           ? ((Response)entity).getEntity() :
>>>> entity);
>>>>>>>>>>
>>>>>>>>>>                 Response r = rb.build();
>>>>>>>>>>                 getState().setResponse(r);
>>>>>>>>>>                 ((ResponseImpl)r).setOutMessage(outMessage);
>>>>>>>>>>                 return r;
>>>>>>>>>>             } catch (Throwable ex) {
>>>>>>>>>>                 throw (ex instanceof ProcessingException) ?
>>>>>>>>>> (ProcessingException)ex
>>>>>>>>>>                                                       : new
>>>>>>>>>> ProcessingException(ex);
>>>>>>>>>>             } finally {
>>>>>>>>>>
>>>>>>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>>>
>>>>>>>
>>>>>>>>>
>>>>>>>>>>             }
>>>>>>>>>>         }
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>       public static ResponseBuilder fromResponse(Response
>>>> response) {
>>>>>>>>>>             ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>>>
>>>>>>>
>>>>>>>>>> *        rb.entity(response.getEntity());
>>>>>>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>>>>>>>>> response.getMetadata().entrySet()) {
>>>>>>>>>>                 List values = entry.getValue();
>>>>>>>>>>                 for (Object value : values) {
>>>>>>>>>>                     rb.header(entry.getKey(), value);
>>>>>>>>>>                 }
>>>>>>>>>>             }
>>>>>>>>>>             return rb;
>>>>>>>>>>         }
>>>>>>>>>>
>>>>>>>>>> * rb.entity(response.getEntity());
>>>>>>>>>> * seems like , entity is null in ResponseBuilder rb from the
>>>>>>>>> fromResponse
>>>>>>>>>> method.
>>>>>>>>>>
>>>>>>>>>> Please let me know, what could be the solution to fix this issue?
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>>>>>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>>>
>>>>>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Sergey Beryozkin
>>>>>>>>>
>>>>>>>>> Talend Community Coders
>>>>>>>>> http://coders.talend.com/
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ------------------------------
>>>>>>>>> If you reply to this email, your message will be added to the
>>>>>>> discussion
>>>>>>>>> below:
>>>>>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>>>>>> ponse-objects-
>>>>>>>>> tp5748134p5782725.html
>>>>>>>>> To unsubscribe from Closing of WebClient and Response objects,
>>>> click
>>>>>>> here
>>>>>>>>> <
>>>>>>>>> .
>>>>>>>>> NAML
>>>>>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>>>>>>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>>>>>>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
>>>>>>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
>>>>>>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
>>>>>>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
>>>>>>> email%21nabble%3Aemail.naml>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> View this message in context: http://cxf.547215.n5.nabble.co
>>>>>>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>>>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------
>>>>>>> If you reply to this email, your message will be added to the
>>>> discussion
>>>>>>> below:
>>>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>>>>>> ponse-objects-tp5748134p5782757.html
>>>>>>> To unsubscribe from Closing of WebClient and Response objects, click
>>>> here
>>>>>>> <
>>>>>>> .
>>>>>>> NAML
>>>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>>>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>>>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.templa
>>>> te.NabbleNamespace-nabble.view.web.template.NodeNamespac
>>>> e&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-
>>>> instant_emails%21nabble%3Aemail.naml-send_instant_email%
>>>> 21nabble%3Aemail.naml>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context: http://cxf.547215.n5.nabble.co
>>>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>
>>>>
>>>>
>>>> --
>>>> Sergey Beryozkin
>>>>
>>>> Talend Community Coders
>>>> http://coders.talend.com/
>>>>
>>>>
>>>> ------------------------------
>>>> If you reply to this email, your message will be added to the discussion
>>>> below:
>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>>> ponse-objects-tp5748134p5782761.html
>>>> To unsubscribe from Closing of WebClient and Response objects, click
>>>> here
>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>>>> .
>>>> NAML
>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>>
>>>
>>>
>>
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782764.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Sergey ,

In CXF 2.7.7, in readBody method, there is no call for readEntity, thats
why it is not throwing any exception . But in 3.1.8 , first readEntity
method is called and later getEntity method is called.   Seems like it is
Bug in AbstractClient.java in 3.1.8 version. What do you say?

On Wed, Aug 16, 2017 at 2:51 PM, Balakrishna Sudabathula <
bsudabathula@gmail.com> wrote:

> readBody method code ()
>
>     protected <T> T readBody(Response r, Message outMessage, Class<T> cls,
>
>
>                              Type type, Annotation[] anns) {
>
>
>
>         if (cls == Response.class) {
>
>             return cls.cast(r);
>
>         }
>
>
>
>         int status = r.getStatus();
>
>         if ((status < 200 || status == 204) && r.getLength() <= 0 ||
> status >= 300) {
>
>             return null;
>
>         }
>
>         return ((ResponseImpl)r).doReadEntity(cls, type, anns);
>
>
>     }
>
> On Wed, Aug 16, 2017 at 2:48 PM, Balakrishna Sudabathula <
> bsudabathula@gmail.com> wrote:
>
>> Please find the attachement. In WebClient handle handleResponse () method
>> there is method call readBody (), in that method readEntity method is
>> called. After that there is another method call  JAXRSUtils.fromRespons
>> which is calling getEntity method
>>
>>
>>
>> On Wed, Aug 16, 2017 at 2:29 PM, Sergey Beryozkin [via CXF] <
>> ml+s547215n5782761h25@n5.nabble.com> wrote:
>>
>>> So where is readEntity is called from ?
>>> On 16/08/17 22:26, sbalustar wrote:
>>>
>>> > In CXF 3.1.8
>>> >
>>> > There is a call in readEntity menthod autoClose(), but in cxf 2.7.7
>>>  there
>>> > is no such method call.
>>> >
>>> >     protected void autoClose(Class<?> cls, boolean exception) {
>>> >
>>> >          if (!entityBufferred && cls != InputStream.class
>>> >
>>> >              && (exception || MessageUtils.isTrue(outMessage
>>> > .getContextualProperty("response.stream.auto.close")))) {
>>> >
>>> >              close();
>>> >
>>> >          }
>>> >
>>> >      }
>>> >
>>> >
>>> > If the auto close is set to true , then it is calling close method ,
>>> and
>>> > changing the entityClosed value to true.
>>> >
>>> >
>>> >
>>> > On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
>>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782761&i=0>>
>>> wrote:
>>> >
>>> >> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
>>> below
>>> >>
>>> >>
>>> >>      public Object getEntity() {
>>> >>          return InjectionUtils.getEntity(getActualEntity());
>>> >>      }
>>> >>
>>> >>
>>> >>    public Object getActualEntity() {
>>> >>          checkEntityIsClosed();
>>> >>          return lastEntity != null ? lastEntity : entity;
>>> >>      }
>>> >>
>>> >>    private void checkEntityIsClosed() {
>>> >>
>>> >>          if (entityClosed) {
>>> >>
>>> >>              throw new IllegalStateException("Entity is not
>>> available");
>>> >>
>>> >>          }
>>> >>
>>> >>      }
>>> >>
>>> >>
>>> >>   public void close() throws ProcessingException {
>>> >>
>>> >>          if (!entityClosed) {
>>> >>
>>> >>              if (!entityBufferred && entity instanceof InputStream) {
>>> >>
>>> >>                  try {
>>> >>
>>> >>                      ((InputStream)entity).close();
>>> >>
>>> >>                  } catch (IOException ex) {
>>> >>
>>> >>                      throw new ResponseProcessingException(this,
>>> ex);
>>> >>
>>> >>                  }
>>> >>
>>> >>              }
>>> >>
>>> >>              entity = null;
>>> >>
>>> >>              entityClosed = true;
>>> >>
>>> >>          }
>>> >>
>>> >>
>>> >>
>>> >>      }
>>> >> In the readEntity method, there is a call to close() method which the
>>> >> entityClosed variable value is set to true. When calling the
>>> getEntity()
>>> >> method , there is a another method call checkEntityIsClosed is
>>> throwing the
>>> >> exception because the entityClosed is set to true in readEntity.
>>> >>
>>> >>
>>> >> But In CXF 2.7.7,  there is no method call in the getEntity() method
>>> ,
>>> >> simply it returns the entity
>>> >>
>>> >> public Object getEntity() {
>>> >>          return lastEntity != null ? lastEntity : entity;
>>> >>      }
>>> >>
>>> >>
>>> >> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>>> >> [hidden email]
>>> <http:///user/SendEmail.jtp?type=node&node=5782761&i=1>> wrote:
>>> >>
>>> >>> Hi, that will need to be measured for a concrete flow.
>>> >>> I'm still not sure why you are seeing the failure with the auto
>>> close
>>> >>> being on - it only takes effect after the entity has been
>>> consumed...
>>> >>>
>>> >>> Sergey
>>> >>> On 16/08/17 19:03, sbalustar wrote:
>>> >>>
>>> >>>> Hi Sergey,
>>> >>>>
>>> >>>>      At runtime,  in Debug mode Changed the
>>> >>> response.stream.auto.close=false.
>>> >>>> Later on , i am not facing the Entity Not available Exception.
>>> >>>>
>>> >>>>     Is there any impact on the performance when we disabled the
>>> flag?
>>> >>>>
>>> >>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>>> >>>> [hidden email] <http:///user/SendEmail.jtp?ty
>>> pe=node&node=5782757&i=0>>
>>> >>> wrote:
>>> >>>>
>>> >>>>> Hi
>>> >>>>>
>>> >>>>> I don't quite understand what the issue is, does it happen when
>>> you
>>> >>>>> enable "response.stream.auto.close" ? If yes - what happens if you
>>> do
>>> >>>>> not enable this property ?
>>> >>>>>
>>> >>>>> CXF does not auto-close the input stream by default given of the
>>> few
>>> >>>>> well-known side-effects.
>>> >>>>>
>>> >>>>> Given you have already tried to debug - it is better to set a
>>> >>> breakpoint
>>> >>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will
>>> see
>>> >>> why
>>> >>>>> InputStream is not available in your case
>>> >>>>>
>>> >>>>> Cheers, Sergey
>>> >>>>>
>>> >>>>> On 15/08/17 23:20, sbalustar wrote:
>>> >>>>>
>>> >>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
>>> the
>>> >>>>> below
>>> >>>>>> issue.
>>> >>>>>>
>>> >>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>> >>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>>>
>>> >>>>> Entity is
>>> >>>>>> not available
>>> >>>>>>        at
>>> >>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>>
>>> >>>
>>> >>>>>
>>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>>> bClient.doResponse(WebClient.java:1110)
>>> >>>
>>> >>>>>
>>> >>>>>>        at
>>> >>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>>
>>> >>>
>>> >>>>>
>>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>>> bClient.doInvoke(WebClient.java:892)
>>> >>>
>>> >>>>>
>>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>>> bClient.doInvoke(WebClient.java:863)
>>> >>>
>>> >>>>>
>>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>>> bClient.invoke(WebClient.java:413)
>>> >>>
>>> >>>>>
>>> >>>>>>        at
>>> >>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>>
>>> >>>
>>> >>>>>>     ... 78 more
>>> >>>>>>
>>> >>>>>> I have gone through this ticket
>>> >>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you
>>> mentioned
>>> >>> that
>>> >>>>> Set
>>> >>>>>> this property: "response.stream.auto.close" to true. This is done
>>> >>> even
>>> >>>>>> though we are getting the same issue.
>>> >>>>>>
>>> >>>>>> When i debug the code, in WebClient.invoke method this exception
>>> is
>>> >>>>> occured.
>>> >>>>>>
>>> >>>>>>      protected Response handleResponse(Message outMessage,
>>> Class<?>
>>> >>>>>> responseClass, Type genericType) {
>>> >>>>>>            try {
>>> >>>>>>                ResponseBuilder rb =
>>> setResponseBuilder(outMessage,
>>> >>>>>> outMessage.getExchange());
>>> >>>>>>                Response currentResponse = rb.clone().build();
>>> >>>>>>                ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>>
>>> >>>
>>> >>>>>>
>>> >>>>>>                Object entity = readBody(currentResponse,
>>> outMessage,
>>> >>>>>> responseClass, genericType,
>>> >>>>>>                                         new Annotation[]{});
>>> >>>>>>
>>> >>>>>>                if (entity == null) {
>>> >>>>>>                    int status = currentResponse.getStatus();
>>> >>>>>>                    if (status >= 400) {
>>> >>>>>>                        entity = currentResponse.getEntity();
>>> >>>>>>                    }
>>> >>>>>>                }
>>> >>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
>>> >>>>>>
>>> >>>>>>                rb.entity(entity instanceof Response
>>> >>>>>>                          ? ((Response)entity).getEntity() :
>>> entity);
>>> >>>>>>
>>> >>>>>>                Response r = rb.build();
>>> >>>>>>                getState().setResponse(r);
>>> >>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
>>> >>>>>>                return r;
>>> >>>>>>            } catch (Throwable ex) {
>>> >>>>>>                throw (ex instanceof ProcessingException) ?
>>> >>>>>> (ProcessingException)ex
>>> >>>>>>                                                      : new
>>> >>>>>> ProcessingException(ex);
>>> >>>>>>            } finally {
>>> >>>>>>
>>> >>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>>
>>> >>>
>>> >>>>>
>>> >>>>>>            }
>>> >>>>>>        }
>>> >>>>>>
>>> >>>>>>
>>> >>>>>>      public static ResponseBuilder fromResponse(Response
>>> response) {
>>> >>>>>>            ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>>
>>> >>>
>>> >>>>>> *        rb.entity(response.getEntity());
>>> >>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>> >>>>>> response.getMetadata().entrySet()) {
>>> >>>>>>                List values = entry.getValue();
>>> >>>>>>                for (Object value : values) {
>>> >>>>>>                    rb.header(entry.getKey(), value);
>>> >>>>>>                }
>>> >>>>>>            }
>>> >>>>>>            return rb;
>>> >>>>>>        }
>>> >>>>>>
>>> >>>>>> * rb.entity(response.getEntity());
>>> >>>>>> * seems like , entity is null in ResponseBuilder rb from the
>>> >>>>> fromResponse
>>> >>>>>> method.
>>> >>>>>>
>>> >>>>>> Please let me know, what could be the solution to fix this issue?
>>> >>>>>>
>>> >>>>>>
>>> >>>>>>
>>> >>>>>> --
>>> >>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>> >>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>>
>>> >>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>> >>>>>>
>>> >>>>>
>>> >>>>>
>>> >>>>> --
>>> >>>>> Sergey Beryozkin
>>> >>>>>
>>> >>>>> Talend Community Coders
>>> >>>>> http://coders.talend.com/
>>> >>>>>
>>> >>>>>
>>> >>>>> ------------------------------
>>> >>>>> If you reply to this email, your message will be added to the
>>> >>> discussion
>>> >>>>> below:
>>> >>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>> >>> ponse-objects-
>>> >>>>> tp5748134p5782725.html
>>> >>>>> To unsubscribe from Closing of WebClient and Response objects,
>>> click
>>> >>> here
>>> >>>>> <
>>> >>>>> .
>>> >>>>> NAML
>>> >>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>>> >>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>>> >>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
>>> >>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
>>> >>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
>>> >>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
>>> >>> email%21nabble%3Aemail.naml>
>>> >>>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>>
>>> >>>> --
>>> >>>> View this message in context: http://cxf.547215.n5.nabble.co
>>> >>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>>> >>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>> >>>>
>>> >>>
>>> >>>
>>> >>> ------------------------------
>>> >>> If you reply to this email, your message will be added to the
>>> discussion
>>> >>> below:
>>> >>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>> >>> ponse-objects-tp5748134p5782757.html
>>> >>> To unsubscribe from Closing of WebClient and Response objects, click
>>> here
>>> >>> <
>>> >>> .
>>> >>> NAML
>>> >>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.templa
>>> te.NabbleNamespace-nabble.view.web.template.NodeNamespac
>>> e&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-
>>> instant_emails%21nabble%3Aemail.naml-send_instant_email%
>>> 21nabble%3Aemail.naml>
>>> >>>
>>> >>
>>> >>
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > View this message in context: http://cxf.547215.n5.nabble.co
>>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
>>> > Sent from the cxf-user mailing list archive at Nabble.com.
>>> >
>>>
>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Talend Community Coders
>>> http://coders.talend.com/
>>>
>>>
>>> ------------------------------
>>> If you reply to this email, your message will be added to the discussion
>>> below:
>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>> ponse-objects-tp5748134p5782761.html
>>> To unsubscribe from Closing of WebClient and Response objects, click
>>> here
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>>> .
>>> NAML
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>
>>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782764.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Please find the attachement. In WebClient handle handleResponse () method
there is method call readBody (), in that method readEntity method is
called. After that there is another method call  JAXRSUtils.fromRespons
which is calling getEntity method



On Wed, Aug 16, 2017 at 2:29 PM, Sergey Beryozkin [via CXF] <
ml+s547215n5782761h25@n5.nabble.com> wrote:

> So where is readEntity is called from ?
> On 16/08/17 22:26, sbalustar wrote:
>
> > In CXF 3.1.8
> >
> > There is a call in readEntity menthod autoClose(), but in cxf 2.7.7
>  there
> > is no such method call.
> >
> >     protected void autoClose(Class<?> cls, boolean exception) {
> >
> >          if (!entityBufferred && cls != InputStream.class
> >
> >              && (exception || MessageUtils.isTrue(outMessage
> > .getContextualProperty("response.stream.auto.close")))) {
> >
> >              close();
> >
> >          }
> >
> >      }
> >
> >
> > If the auto close is set to true , then it is calling close method , and
> > changing the entityClosed value to true.
> >
> >
> >
> > On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782761&i=0>>
> wrote:
> >
> >> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
> below
> >>
> >>
> >>      public Object getEntity() {
> >>          return InjectionUtils.getEntity(getActualEntity());
> >>      }
> >>
> >>
> >>    public Object getActualEntity() {
> >>          checkEntityIsClosed();
> >>          return lastEntity != null ? lastEntity : entity;
> >>      }
> >>
> >>    private void checkEntityIsClosed() {
> >>
> >>          if (entityClosed) {
> >>
> >>              throw new IllegalStateException("Entity is not
> available");
> >>
> >>          }
> >>
> >>      }
> >>
> >>
> >>   public void close() throws ProcessingException {
> >>
> >>          if (!entityClosed) {
> >>
> >>              if (!entityBufferred && entity instanceof InputStream) {
> >>
> >>                  try {
> >>
> >>                      ((InputStream)entity).close();
> >>
> >>                  } catch (IOException ex) {
> >>
> >>                      throw new ResponseProcessingException(this, ex);
> >>
> >>                  }
> >>
> >>              }
> >>
> >>              entity = null;
> >>
> >>              entityClosed = true;
> >>
> >>          }
> >>
> >>
> >>
> >>      }
> >> In the readEntity method, there is a call to close() method which the
> >> entityClosed variable value is set to true. When calling the
> getEntity()
> >> method , there is a another method call checkEntityIsClosed is throwing
> the
> >> exception because the entityClosed is set to true in readEntity.
> >>
> >>
> >> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
> >> simply it returns the entity
> >>
> >> public Object getEntity() {
> >>          return lastEntity != null ? lastEntity : entity;
> >>      }
> >>
> >>
> >> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
> >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782761&i=1>>
> wrote:
> >>
> >>> Hi, that will need to be measured for a concrete flow.
> >>> I'm still not sure why you are seeing the failure with the auto close
> >>> being on - it only takes effect after the entity has been consumed...
> >>>
> >>> Sergey
> >>> On 16/08/17 19:03, sbalustar wrote:
> >>>
> >>>> Hi Sergey,
> >>>>
> >>>>      At runtime,  in Debug mode Changed the
> >>> response.stream.auto.close=false.
> >>>> Later on , i am not facing the Entity Not available Exception.
> >>>>
> >>>>     Is there any impact on the performance when we disabled the flag?
> >>>>
> >>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
> >>>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>
> >>> wrote:
> >>>>
> >>>>> Hi
> >>>>>
> >>>>> I don't quite understand what the issue is, does it happen when you
> >>>>> enable "response.stream.auto.close" ? If yes - what happens if you
> do
> >>>>> not enable this property ?
> >>>>>
> >>>>> CXF does not auto-close the input stream by default given of the few
> >>>>> well-known side-effects.
> >>>>>
> >>>>> Given you have already tried to debug - it is better to set a
> >>> breakpoint
> >>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
> >>> why
> >>>>> InputStream is not available in your case
> >>>>>
> >>>>> Cheers, Sergey
> >>>>>
> >>>>> On 15/08/17 23:20, sbalustar wrote:
> >>>>>
> >>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
> the
> >>>>> below
> >>>>>> issue.
> >>>>>>
> >>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
> >>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
> >>>>> Entity is
> >>>>>> not available
> >>>>>>        at
> >>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>
> >>>
> >>>>>
> >>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>
> >>>
> >>>>>
> >>>>>>        at
> >>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>
> >>>
> >>>>>
> >>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>
> >>>
> >>>>>
> >>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>
> >>>
> >>>>>
> >>>>>>        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>
> >>>
> >>>>>
> >>>>>>        at
> >>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>
> >>>
> >>>>>>     ... 78 more
> >>>>>>
> >>>>>> I have gone through this ticket
> >>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
> >>> that
> >>>>> Set
> >>>>>> this property: "response.stream.auto.close" to true. This is done
> >>> even
> >>>>>> though we are getting the same issue.
> >>>>>>
> >>>>>> When i debug the code, in WebClient.invoke method this exception is
> >>>>> occured.
> >>>>>>
> >>>>>>      protected Response handleResponse(Message outMessage, Class<?>
> >>>>>> responseClass, Type genericType) {
> >>>>>>            try {
> >>>>>>                ResponseBuilder rb = setResponseBuilder(outMessage,
> >>>>>> outMessage.getExchange());
> >>>>>>                Response currentResponse = rb.clone().build();
> >>>>>>                ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>
> >>>
> >>>>>>
> >>>>>>                Object entity = readBody(currentResponse,
> outMessage,
> >>>>>> responseClass, genericType,
> >>>>>>                                         new Annotation[]{});
> >>>>>>
> >>>>>>                if (entity == null) {
> >>>>>>                    int status = currentResponse.getStatus();
> >>>>>>                    if (status >= 400) {
> >>>>>>                        entity = currentResponse.getEntity();
> >>>>>>                    }
> >>>>>>                }
> >>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
> >>>>>>
> >>>>>>                rb.entity(entity instanceof Response
> >>>>>>                          ? ((Response)entity).getEntity() :
> entity);
> >>>>>>
> >>>>>>                Response r = rb.build();
> >>>>>>                getState().setResponse(r);
> >>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
> >>>>>>                return r;
> >>>>>>            } catch (Throwable ex) {
> >>>>>>                throw (ex instanceof ProcessingException) ?
> >>>>>> (ProcessingException)ex
> >>>>>>                                                      : new
> >>>>>> ProcessingException(ex);
> >>>>>>            } finally {
> >>>>>>
> >>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>
> >>>
> >>>>>
> >>>>>>            }
> >>>>>>        }
> >>>>>>
> >>>>>>
> >>>>>>      public static ResponseBuilder fromResponse(Response response)
> {
> >>>>>>            ResponseBuilder rb = toResponseBuilder(response.getStatus());
>
> >>>
> >>>>>> *        rb.entity(response.getEntity());
> >>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
> >>>>>> response.getMetadata().entrySet()) {
> >>>>>>                List values = entry.getValue();
> >>>>>>                for (Object value : values) {
> >>>>>>                    rb.header(entry.getKey(), value);
> >>>>>>                }
> >>>>>>            }
> >>>>>>            return rb;
> >>>>>>        }
> >>>>>>
> >>>>>> * rb.entity(response.getEntity());
> >>>>>> * seems like , entity is null in ResponseBuilder rb from the
> >>>>> fromResponse
> >>>>>> method.
> >>>>>>
> >>>>>> Please let me know, what could be the solution to fix this issue?
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> View this message in context: http://cxf.547215.n5.nabble.
> >>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>
> >>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Sergey Beryozkin
> >>>>>
> >>>>> Talend Community Coders
> >>>>> http://coders.talend.com/
> >>>>>
> >>>>>
> >>>>> ------------------------------
> >>>>> If you reply to this email, your message will be added to the
> >>> discussion
> >>>>> below:
> >>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
> >>> ponse-objects-
> >>>>> tp5748134p5782725.html
> >>>>> To unsubscribe from Closing of WebClient and Response objects, click
> >>> here
> >>>>> <
> >>>>> .
> >>>>> NAML
> >>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
> >>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
> >>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
> >>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
> >>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
> >>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
> >>> email%21nabble%3Aemail.naml>
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> View this message in context: http://cxf.547215.n5.nabble.co
> >>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
> >>>> Sent from the cxf-user mailing list archive at Nabble.com.
> >>>>
> >>>
> >>>
> >>> ------------------------------
> >>> If you reply to this email, your message will be added to the
> discussion
> >>> below:
> >>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
> >>> ponse-objects-tp5748134p5782757.html
> >>> To unsubscribe from Closing of WebClient and Response objects, click
> here
> >>> <
> >>> .
> >>> NAML
> >>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?
> macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&
> base=nabble.naml.namespaces.BasicNamespace-nabble.view.
> web.template.NabbleNamespace-nabble.view.web.template.
> NodeNamespace&breadcrumbs=notify_subscribers%21nabble%
> 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_
> instant_email%21nabble%3Aemail.naml>
> >>>
> >>
> >>
> >
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.
> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
> tp5748134p5782761.html
> To unsubscribe from Closing of WebClient and Response objects, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>


Screen Shot 2017-08-16 at 2.44.18 PM.png (292K) <http://cxf.547215.n5.nabble.com/attachment/5782762/0/Screen%20Shot%202017-08-16%20at%202.44.18%20PM.png>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782762.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
readBody method code ()

    protected <T> T readBody(Response r, Message outMessage, Class<T> cls,

                             Type type, Annotation[] anns) {



        if (cls == Response.class) {

            return cls.cast(r);

        }



        int status = r.getStatus();

        if ((status < 200 || status == 204) && r.getLength() <= 0 || status
>= 300) {

            return null;

        }

        return ((ResponseImpl)r).doReadEntity(cls, type, anns);


    }

On Wed, Aug 16, 2017 at 2:48 PM, Balakrishna Sudabathula <
bsudabathula@gmail.com> wrote:

> Please find the attachement. In WebClient handle handleResponse () method
> there is method call readBody (), in that method readEntity method is
> called. After that there is another method call  JAXRSUtils.fromRespons
> which is calling getEntity method
>
>
>
> On Wed, Aug 16, 2017 at 2:29 PM, Sergey Beryozkin [via CXF] <
> ml+s547215n5782761h25@n5.nabble.com> wrote:
>
>> So where is readEntity is called from ?
>> On 16/08/17 22:26, sbalustar wrote:
>>
>> > In CXF 3.1.8
>> >
>> > There is a call in readEntity menthod autoClose(), but in cxf 2.7.7
>>  there
>> > is no such method call.
>> >
>> >     protected void autoClose(Class<?> cls, boolean exception) {
>> >
>> >          if (!entityBufferred && cls != InputStream.class
>> >
>> >              && (exception || MessageUtils.isTrue(outMessage
>> > .getContextualProperty("response.stream.auto.close")))) {
>> >
>> >              close();
>> >
>> >          }
>> >
>> >      }
>> >
>> >
>> > If the auto close is set to true , then it is calling close method ,
>> and
>> > changing the entityClosed value to true.
>> >
>> >
>> >
>> > On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782761&i=0>>
>> wrote:
>> >
>> >> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like
>> below
>> >>
>> >>
>> >>      public Object getEntity() {
>> >>          return InjectionUtils.getEntity(getActualEntity());
>> >>      }
>> >>
>> >>
>> >>    public Object getActualEntity() {
>> >>          checkEntityIsClosed();
>> >>          return lastEntity != null ? lastEntity : entity;
>> >>      }
>> >>
>> >>    private void checkEntityIsClosed() {
>> >>
>> >>          if (entityClosed) {
>> >>
>> >>              throw new IllegalStateException("Entity is not
>> available");
>> >>
>> >>          }
>> >>
>> >>      }
>> >>
>> >>
>> >>   public void close() throws ProcessingException {
>> >>
>> >>          if (!entityClosed) {
>> >>
>> >>              if (!entityBufferred && entity instanceof InputStream) {
>> >>
>> >>                  try {
>> >>
>> >>                      ((InputStream)entity).close();
>> >>
>> >>                  } catch (IOException ex) {
>> >>
>> >>                      throw new ResponseProcessingException(this, ex);
>> >>
>> >>                  }
>> >>
>> >>              }
>> >>
>> >>              entity = null;
>> >>
>> >>              entityClosed = true;
>> >>
>> >>          }
>> >>
>> >>
>> >>
>> >>      }
>> >> In the readEntity method, there is a call to close() method which the
>> >> entityClosed variable value is set to true. When calling the
>> getEntity()
>> >> method , there is a another method call checkEntityIsClosed is
>> throwing the
>> >> exception because the entityClosed is set to true in readEntity.
>> >>
>> >>
>> >> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
>> >> simply it returns the entity
>> >>
>> >> public Object getEntity() {
>> >>          return lastEntity != null ? lastEntity : entity;
>> >>      }
>> >>
>> >>
>> >> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>> >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782761&i=1>>
>> wrote:
>> >>
>> >>> Hi, that will need to be measured for a concrete flow.
>> >>> I'm still not sure why you are seeing the failure with the auto close
>> >>> being on - it only takes effect after the entity has been consumed...
>> >>>
>> >>> Sergey
>> >>> On 16/08/17 19:03, sbalustar wrote:
>> >>>
>> >>>> Hi Sergey,
>> >>>>
>> >>>>      At runtime,  in Debug mode Changed the
>> >>> response.stream.auto.close=false.
>> >>>> Later on , i am not facing the Entity Not available Exception.
>> >>>>
>> >>>>     Is there any impact on the performance when we disabled the
>> flag?
>> >>>>
>> >>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>> >>>> [hidden email] <http:///user/SendEmail.jtp?ty
>> pe=node&node=5782757&i=0>>
>> >>> wrote:
>> >>>>
>> >>>>> Hi
>> >>>>>
>> >>>>> I don't quite understand what the issue is, does it happen when you
>> >>>>> enable "response.stream.auto.close" ? If yes - what happens if you
>> do
>> >>>>> not enable this property ?
>> >>>>>
>> >>>>> CXF does not auto-close the input stream by default given of the
>> few
>> >>>>> well-known side-effects.
>> >>>>>
>> >>>>> Given you have already tried to debug - it is better to set a
>> >>> breakpoint
>> >>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
>> >>> why
>> >>>>> InputStream is not available in your case
>> >>>>>
>> >>>>> Cheers, Sergey
>> >>>>>
>> >>>>> On 15/08/17 23:20, sbalustar wrote:
>> >>>>>
>> >>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing
>> the
>> >>>>> below
>> >>>>>> issue.
>> >>>>>>
>> >>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>> >>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>> >>>>> Entity is
>> >>>>>> not available
>> >>>>>>        at
>> >>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>
>> >>>
>> >>>>>
>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>> bClient.doResponse(WebClient.java:1110)
>> >>>
>> >>>>>
>> >>>>>>        at
>> >>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>
>> >>>
>> >>>>>
>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>> bClient.doInvoke(WebClient.java:892)
>> >>>
>> >>>>>
>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>> bClient.doInvoke(WebClient.java:863)
>> >>>
>> >>>>>
>> >>>>>>        at org.apache.cxf.jaxrs.client.We
>> bClient.invoke(WebClient.java:413)
>> >>>
>> >>>>>
>> >>>>>>        at
>> >>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>
>> >>>
>> >>>>>>     ... 78 more
>> >>>>>>
>> >>>>>> I have gone through this ticket
>> >>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you
>> mentioned
>> >>> that
>> >>>>> Set
>> >>>>>> this property: "response.stream.auto.close" to true. This is done
>> >>> even
>> >>>>>> though we are getting the same issue.
>> >>>>>>
>> >>>>>> When i debug the code, in WebClient.invoke method this exception
>> is
>> >>>>> occured.
>> >>>>>>
>> >>>>>>      protected Response handleResponse(Message outMessage,
>> Class<?>
>> >>>>>> responseClass, Type genericType) {
>> >>>>>>            try {
>> >>>>>>                ResponseBuilder rb = setResponseBuilder(outMessage,
>> >>>>>> outMessage.getExchange());
>> >>>>>>                Response currentResponse = rb.clone().build();
>> >>>>>>                ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>
>> >>>
>> >>>>>>
>> >>>>>>                Object entity = readBody(currentResponse,
>> outMessage,
>> >>>>>> responseClass, genericType,
>> >>>>>>                                         new Annotation[]{});
>> >>>>>>
>> >>>>>>                if (entity == null) {
>> >>>>>>                    int status = currentResponse.getStatus();
>> >>>>>>                    if (status >= 400) {
>> >>>>>>                        entity = currentResponse.getEntity();
>> >>>>>>                    }
>> >>>>>>                }
>> >>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
>> >>>>>>
>> >>>>>>                rb.entity(entity instanceof Response
>> >>>>>>                          ? ((Response)entity).getEntity() :
>> entity);
>> >>>>>>
>> >>>>>>                Response r = rb.build();
>> >>>>>>                getState().setResponse(r);
>> >>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
>> >>>>>>                return r;
>> >>>>>>            } catch (Throwable ex) {
>> >>>>>>                throw (ex instanceof ProcessingException) ?
>> >>>>>> (ProcessingException)ex
>> >>>>>>                                                      : new
>> >>>>>> ProcessingException(ex);
>> >>>>>>            } finally {
>> >>>>>>
>> >>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>
>> >>>
>> >>>>>
>> >>>>>>            }
>> >>>>>>        }
>> >>>>>>
>> >>>>>>
>> >>>>>>      public static ResponseBuilder fromResponse(Response response)
>> {
>> >>>>>>            ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>
>> >>>
>> >>>>>> *        rb.entity(response.getEntity());
>> >>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>> >>>>>> response.getMetadata().entrySet()) {
>> >>>>>>                List values = entry.getValue();
>> >>>>>>                for (Object value : values) {
>> >>>>>>                    rb.header(entry.getKey(), value);
>> >>>>>>                }
>> >>>>>>            }
>> >>>>>>            return rb;
>> >>>>>>        }
>> >>>>>>
>> >>>>>> * rb.entity(response.getEntity());
>> >>>>>> * seems like , entity is null in ResponseBuilder rb from the
>> >>>>> fromResponse
>> >>>>>> method.
>> >>>>>>
>> >>>>>> Please let me know, what could be the solution to fix this issue?
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>> --
>> >>>>>> View this message in context: http://cxf.547215.n5.nabble.
>> >>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>
>> >>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>> >>>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Sergey Beryozkin
>> >>>>>
>> >>>>> Talend Community Coders
>> >>>>> http://coders.talend.com/
>> >>>>>
>> >>>>>
>> >>>>> ------------------------------
>> >>>>> If you reply to this email, your message will be added to the
>> >>> discussion
>> >>>>> below:
>> >>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>> >>> ponse-objects-
>> >>>>> tp5748134p5782725.html
>> >>>>> To unsubscribe from Closing of WebClient and Response objects,
>> click
>> >>> here
>> >>>>> <
>> >>>>> .
>> >>>>> NAML
>> >>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>> >>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>> >>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
>> >>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
>> >>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
>> >>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
>> >>> email%21nabble%3Aemail.naml>
>> >>>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> View this message in context: http://cxf.547215.n5.nabble.co
>> >>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>> >>>> Sent from the cxf-user mailing list archive at Nabble.com.
>> >>>>
>> >>>
>> >>>
>> >>> ------------------------------
>> >>> If you reply to this email, your message will be added to the
>> discussion
>> >>> below:
>> >>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>> >>> ponse-objects-tp5748134p5782757.html
>> >>> To unsubscribe from Closing of WebClient and Response objects, click
>> here
>> >>> <
>> >>> .
>> >>> NAML
>> >>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
>> email%21nabble%3Aemail.naml>
>> >>>
>> >>
>> >>
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context: http://cxf.547215.n5.nabble.co
>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
>> > Sent from the cxf-user mailing list archive at Nabble.com.
>> >
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>> ponse-objects-tp5748134p5782761.html
>> To unsubscribe from Closing of WebClient and Response objects, click here
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>> .
>> NAML
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782763.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
So where is readEntity is called from ?
On 16/08/17 22:26, sbalustar wrote:
> In CXF 3.1.8
> 
> There is a call in readEntity menthod autoClose(), but in cxf 2.7.7  there
> is no such method call.
> 
>     protected void autoClose(Class<?> cls, boolean exception) {
> 
>          if (!entityBufferred && cls != InputStream.class
> 
>              && (exception || MessageUtils.isTrue(outMessage
> .getContextualProperty("response.stream.auto.close")))) {
> 
>              close();
> 
>          }
> 
>      }
> 
> 
> If the auto close is set to true , then it is calling close method , and
> changing the entityClosed value to true.
> 
> 
> 
> On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
> bsudabathula@gmail.com> wrote:
> 
>> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like below
>>
>>
>>      public Object getEntity() {
>>          return InjectionUtils.getEntity(getActualEntity());
>>      }
>>
>>
>>    public Object getActualEntity() {
>>          checkEntityIsClosed();
>>          return lastEntity != null ? lastEntity : entity;
>>      }
>>
>>    private void checkEntityIsClosed() {
>>
>>          if (entityClosed) {
>>
>>              throw new IllegalStateException("Entity is not available");
>>
>>          }
>>
>>      }
>>
>>
>>   public void close() throws ProcessingException {
>>
>>          if (!entityClosed) {
>>
>>              if (!entityBufferred && entity instanceof InputStream) {
>>
>>                  try {
>>
>>                      ((InputStream)entity).close();
>>
>>                  } catch (IOException ex) {
>>
>>                      throw new ResponseProcessingException(this, ex);
>>
>>                  }
>>
>>              }
>>
>>              entity = null;
>>
>>              entityClosed = true;
>>
>>          }
>>
>>
>>
>>      }
>> In the readEntity method, there is a call to close() method which the
>> entityClosed variable value is set to true. When calling the getEntity()
>> method , there is a another method call checkEntityIsClosed is throwing the
>> exception because the entityClosed is set to true in readEntity.
>>
>>
>> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
>> simply it returns the entity
>>
>> public Object getEntity() {
>>          return lastEntity != null ? lastEntity : entity;
>>      }
>>
>>
>> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
>> ml+s547215n5782757h1@n5.nabble.com> wrote:
>>
>>> Hi, that will need to be measured for a concrete flow.
>>> I'm still not sure why you are seeing the failure with the auto close
>>> being on - it only takes effect after the entity has been consumed...
>>>
>>> Sergey
>>> On 16/08/17 19:03, sbalustar wrote:
>>>
>>>> Hi Sergey,
>>>>
>>>>      At runtime,  in Debug mode Changed the
>>> response.stream.auto.close=false.
>>>> Later on , i am not facing the Entity Not available Exception.
>>>>
>>>>     Is there any impact on the performance when we disabled the flag?
>>>>
>>>> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>>>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>>> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> I don't quite understand what the issue is, does it happen when you
>>>>> enable "response.stream.auto.close" ? If yes - what happens if you do
>>>>> not enable this property ?
>>>>>
>>>>> CXF does not auto-close the input stream by default given of the few
>>>>> well-known side-effects.
>>>>>
>>>>> Given you have already tried to debug - it is better to set a
>>> breakpoint
>>>>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
>>> why
>>>>> InputStream is not available in your case
>>>>>
>>>>> Cheers, Sergey
>>>>>
>>>>> On 15/08/17 23:20, sbalustar wrote:
>>>>>
>>>>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
>>>>> below
>>>>>> issue.
>>>>>>
>>>>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>>>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>>>>> Entity is
>>>>>> not available
>>>>>>        at
>>>>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>>
>>>>>
>>>>>>        at
>>>>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>>
>>>>>
>>>>>>        at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>>
>>>>>
>>>>>>        at
>>>>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>>
>>>>>>     ... 78 more
>>>>>>
>>>>>> I have gone through this ticket
>>>>>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
>>> that
>>>>> Set
>>>>>> this property: "response.stream.auto.close" to true. This is done
>>> even
>>>>>> though we are getting the same issue.
>>>>>>
>>>>>> When i debug the code, in WebClient.invoke method this exception is
>>>>> occured.
>>>>>>
>>>>>>      protected Response handleResponse(Message outMessage, Class<?>
>>>>>> responseClass, Type genericType) {
>>>>>>            try {
>>>>>>                ResponseBuilder rb = setResponseBuilder(outMessage,
>>>>>> outMessage.getExchange());
>>>>>>                Response currentResponse = rb.clone().build();
>>>>>>                ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>>
>>>>>>
>>>>>>                Object entity = readBody(currentResponse, outMessage,
>>>>>> responseClass, genericType,
>>>>>>                                         new Annotation[]{});
>>>>>>
>>>>>>                if (entity == null) {
>>>>>>                    int status = currentResponse.getStatus();
>>>>>>                    if (status >= 400) {
>>>>>>                        entity = currentResponse.getEntity();
>>>>>>                    }
>>>>>>                }
>>>>>>                rb = JAXRSUtils.fromResponse(currentResponse);
>>>>>>
>>>>>>                rb.entity(entity instanceof Response
>>>>>>                          ? ((Response)entity).getEntity() : entity);
>>>>>>
>>>>>>                Response r = rb.build();
>>>>>>                getState().setResponse(r);
>>>>>>                ((ResponseImpl)r).setOutMessage(outMessage);
>>>>>>                return r;
>>>>>>            } catch (Throwable ex) {
>>>>>>                throw (ex instanceof ProcessingException) ?
>>>>>> (ProcessingException)ex
>>>>>>                                                      : new
>>>>>> ProcessingException(ex);
>>>>>>            } finally {
>>>>>>
>>>>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>>
>>>>>
>>>>>>            }
>>>>>>        }
>>>>>>
>>>>>>
>>>>>>      public static ResponseBuilder fromResponse(Response response) {
>>>>>>            ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>>
>>>>>> *        rb.entity(response.getEntity());
>>>>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>>>>> response.getMetadata().entrySet()) {
>>>>>>                List values = entry.getValue();
>>>>>>                for (Object value : values) {
>>>>>>                    rb.header(entry.getKey(), value);
>>>>>>                }
>>>>>>            }
>>>>>>            return rb;
>>>>>>        }
>>>>>>
>>>>>> * rb.entity(response.getEntity());
>>>>>> * seems like , entity is null in ResponseBuilder rb from the
>>>>> fromResponse
>>>>>> method.
>>>>>>
>>>>>> Please let me know, what could be the solution to fix this issue?
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> View this message in context: http://cxf.547215.n5.nabble.
>>>>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Sergey Beryozkin
>>>>>
>>>>> Talend Community Coders
>>>>> http://coders.talend.com/
>>>>>
>>>>>
>>>>> ------------------------------
>>>>> If you reply to this email, your message will be added to the
>>> discussion
>>>>> below:
>>>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>> ponse-objects-
>>>>> tp5748134p5782725.html
>>>>> To unsubscribe from Closing of WebClient and Response objects, click
>>> here
>>>>> <
>>>>> .
>>>>> NAML
>>>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
>>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
>>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
>>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
>>> email%21nabble%3Aemail.naml>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://cxf.547215.n5.nabble.co
>>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>>
>>>
>>>
>>> ------------------------------
>>> If you reply to this email, your message will be added to the discussion
>>> below:
>>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>>> ponse-objects-tp5748134p5782757.html
>>> To unsubscribe from Closing of WebClient and Response objects, click here
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>>> .
>>> NAML
>>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>>
>>
>>
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
In CXF 3.1.8

There is a call in readEntity menthod autoClose(), but in cxf 2.7.7  there
is no such method call.

   protected void autoClose(Class<?> cls, boolean exception) {

        if (!entityBufferred && cls != InputStream.class

            && (exception || MessageUtils.isTrue(outMessage
.getContextualProperty("response.stream.auto.close")))) {

            close();

        }

    }


If the auto close is set to true , then it is calling close method , and
changing the entityClosed value to true.



On Wed, Aug 16, 2017 at 2:18 PM, Balakrishna Sudabathula <
bsudabathula@gmail.com> wrote:

> Why because IN CXF 3.1.8 , The Code in the ResponseImpl class is like below
>
>
>     public Object getEntity() {
>         return InjectionUtils.getEntity(getActualEntity());
>     }
>
>
>   public Object getActualEntity() {
>         checkEntityIsClosed();
>         return lastEntity != null ? lastEntity : entity;
>     }
>
>   private void checkEntityIsClosed() {
>
>         if (entityClosed) {
>
>             throw new IllegalStateException("Entity is not available");
>
>         }
>
>     }
>
>
>  public void close() throws ProcessingException {
>
>         if (!entityClosed) {
>
>             if (!entityBufferred && entity instanceof InputStream) {
>
>                 try {
>
>                     ((InputStream)entity).close();
>
>                 } catch (IOException ex) {
>
>                     throw new ResponseProcessingException(this, ex);
>
>                 }
>
>             }
>
>             entity = null;
>
>             entityClosed = true;
>
>         }
>
>
>
>     }
> In the readEntity method, there is a call to close() method which the
> entityClosed variable value is set to true. When calling the getEntity()
> method , there is a another method call checkEntityIsClosed is throwing the
> exception because the entityClosed is set to true in readEntity.
>
>
> But In CXF 2.7.7,  there is no method call in the getEntity() method ,
> simply it returns the entity
>
> public Object getEntity() {
>         return lastEntity != null ? lastEntity : entity;
>     }
>
>
> On Wed, Aug 16, 2017 at 1:58 PM, Sergey Beryozkin [via CXF] <
> ml+s547215n5782757h1@n5.nabble.com> wrote:
>
>> Hi, that will need to be measured for a concrete flow.
>> I'm still not sure why you are seeing the failure with the auto close
>> being on - it only takes effect after the entity has been consumed...
>>
>> Sergey
>> On 16/08/17 19:03, sbalustar wrote:
>>
>> > Hi Sergey,
>> >
>> >     At runtime,  in Debug mode Changed the
>> response.stream.auto.close=false.
>> > Later on , i am not facing the Entity Not available Exception.
>> >
>> >    Is there any impact on the performance when we disabled the flag?
>> >
>> > On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5782757&i=0>>
>> wrote:
>> >
>> >> Hi
>> >>
>> >> I don't quite understand what the issue is, does it happen when you
>> >> enable "response.stream.auto.close" ? If yes - what happens if you do
>> >> not enable this property ?
>> >>
>> >> CXF does not auto-close the input stream by default given of the few
>> >> well-known side-effects.
>> >>
>> >> Given you have already tried to debug - it is better to set a
>> breakpoint
>> >> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see
>> why
>> >> InputStream is not available in your case
>> >>
>> >> Cheers, Sergey
>> >>
>> >> On 15/08/17 23:20, sbalustar wrote:
>> >>
>> >>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
>> >> below
>> >>> issue.
>> >>>
>> >>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>> >>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>> >> Entity is
>> >>> not available
>> >>>       at
>> >>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>
>> >>
>> >>>       at
>> >>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>
>> >>
>> >>>       at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>
>> >>
>> >>>       at
>> >>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>
>> >>>    ... 78 more
>> >>>
>> >>> I have gone through this ticket
>> >>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned
>> that
>> >> Set
>> >>> this property: "response.stream.auto.close" to true. This is done
>> even
>> >>> though we are getting the same issue.
>> >>>
>> >>> When i debug the code, in WebClient.invoke method this exception is
>> >> occured.
>> >>>
>> >>>     protected Response handleResponse(Message outMessage, Class<?>
>> >>> responseClass, Type genericType) {
>> >>>           try {
>> >>>               ResponseBuilder rb = setResponseBuilder(outMessage,
>> >>> outMessage.getExchange());
>> >>>               Response currentResponse = rb.clone().build();
>> >>>               ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>
>> >>>
>> >>>               Object entity = readBody(currentResponse, outMessage,
>> >>> responseClass, genericType,
>> >>>                                        new Annotation[]{});
>> >>>
>> >>>               if (entity == null) {
>> >>>                   int status = currentResponse.getStatus();
>> >>>                   if (status >= 400) {
>> >>>                       entity = currentResponse.getEntity();
>> >>>                   }
>> >>>               }
>> >>>               rb = JAXRSUtils.fromResponse(currentResponse);
>> >>>
>> >>>               rb.entity(entity instanceof Response
>> >>>                         ? ((Response)entity).getEntity() : entity);
>> >>>
>> >>>               Response r = rb.build();
>> >>>               getState().setResponse(r);
>> >>>               ((ResponseImpl)r).setOutMessage(outMessage);
>> >>>               return r;
>> >>>           } catch (Throwable ex) {
>> >>>               throw (ex instanceof ProcessingException) ?
>> >>> (ProcessingException)ex
>> >>>                                                     : new
>> >>> ProcessingException(ex);
>> >>>           } finally {
>> >>>
>> >>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>
>> >>
>> >>>           }
>> >>>       }
>> >>>
>> >>>
>> >>>     public static ResponseBuilder fromResponse(Response response) {
>> >>>           ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>
>> >>> *        rb.entity(response.getEntity());
>> >>> *        for (Map.Entry<String, List&lt;Object>> entry :
>> >>> response.getMetadata().entrySet()) {
>> >>>               List values = entry.getValue();
>> >>>               for (Object value : values) {
>> >>>                   rb.header(entry.getKey(), value);
>> >>>               }
>> >>>           }
>> >>>           return rb;
>> >>>       }
>> >>>
>> >>> * rb.entity(response.getEntity());
>> >>> * seems like , entity is null in ResponseBuilder rb from the
>> >> fromResponse
>> >>> method.
>> >>>
>> >>> Please let me know, what could be the solution to fix this issue?
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> View this message in context: http://cxf.547215.n5.nabble.
>> >> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>> >>> Sent from the cxf-user mailing list archive at Nabble.com.
>> >>>
>> >>
>> >>
>> >> --
>> >> Sergey Beryozkin
>> >>
>> >> Talend Community Coders
>> >> http://coders.talend.com/
>> >>
>> >>
>> >> ------------------------------
>> >> If you reply to this email, your message will be added to the
>> discussion
>> >> below:
>> >> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>> ponse-objects-
>> >> tp5748134p5782725.html
>> >> To unsubscribe from Closing of WebClient and Response objects, click
>> here
>> >> <
>> >> .
>> >> NAML
>> >> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?ma
>> cro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=
>> nabble.naml.namespaces.BasicNamespace-nabble.view.web.
>> template.NabbleNamespace-nabble.view.web.template.NodeNamesp
>> ace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
>> naml-instant_emails%21nabble%3Aemail.naml-send_instant_
>> email%21nabble%3Aemail.naml>
>> >>
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context: http://cxf.547215.n5.nabble.co
>> m/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
>> > Sent from the cxf-user mailing list archive at Nabble.com.
>> >
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Res
>> ponse-objects-tp5748134p5782757.html
>> To unsubscribe from Closing of WebClient and Response objects, click here
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>> .
>> NAML
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782759.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi, that will need to be measured for a concrete flow.
I'm still not sure why you are seeing the failure with the auto close 
being on - it only takes effect after the entity has been consumed...

Sergey
On 16/08/17 19:03, sbalustar wrote:
> Hi Sergey,
> 
>     At runtime,  in Debug mode Changed the response.stream.auto.close=false.
> Later on , i am not facing the Entity Not available Exception.
> 
>    Is there any impact on the performance when we disabled the flag?
> 
> On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
> ml+s547215n5782725h9@n5.nabble.com> wrote:
> 
>> Hi
>>
>> I don't quite understand what the issue is, does it happen when you
>> enable "response.stream.auto.close" ? If yes - what happens if you do
>> not enable this property ?
>>
>> CXF does not auto-close the input stream by default given of the few
>> well-known side-effects.
>>
>> Given you have already tried to debug - it is better to set a breakpoint
>> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why
>> InputStream is not available in your case
>>
>> Cheers, Sergey
>>
>> On 15/08/17 23:20, sbalustar wrote:
>>
>>> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
>> below
>>> issue.
>>>
>>> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
>>> javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
>> Entity is
>>> not available
>>>       at
>>> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>>
>>>       at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>>
>>>       at
>>> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>>
>>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>>
>>>       at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>>
>>>       at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>>
>>>       at
>>> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>>>    ... 78 more
>>>
>>> I have gone through this ticket
>>> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned that
>> Set
>>> this property: "response.stream.auto.close" to true. This is done even
>>> though we are getting the same issue.
>>>
>>> When i debug the code, in WebClient.invoke method this exception is
>> occured.
>>>
>>>     protected Response handleResponse(Message outMessage, Class<?>
>>> responseClass, Type genericType) {
>>>           try {
>>>               ResponseBuilder rb = setResponseBuilder(outMessage,
>>> outMessage.getExchange());
>>>               Response currentResponse = rb.clone().build();
>>>               ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>>>
>>>               Object entity = readBody(currentResponse, outMessage,
>>> responseClass, genericType,
>>>                                        new Annotation[]{});
>>>
>>>               if (entity == null) {
>>>                   int status = currentResponse.getStatus();
>>>                   if (status >= 400) {
>>>                       entity = currentResponse.getEntity();
>>>                   }
>>>               }
>>>               rb = JAXRSUtils.fromResponse(currentResponse);
>>>
>>>               rb.entity(entity instanceof Response
>>>                         ? ((Response)entity).getEntity() : entity);
>>>
>>>               Response r = rb.build();
>>>               getState().setResponse(r);
>>>               ((ResponseImpl)r).setOutMessage(outMessage);
>>>               return r;
>>>           } catch (Throwable ex) {
>>>               throw (ex instanceof ProcessingException) ?
>>> (ProcessingException)ex
>>>                                                     : new
>>> ProcessingException(ex);
>>>           } finally {
>>>
>>> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>>
>>>           }
>>>       }
>>>
>>>
>>>     public static ResponseBuilder fromResponse(Response response) {
>>>           ResponseBuilder rb = toResponseBuilder(response.getStatus());
>>> *        rb.entity(response.getEntity());
>>> *        for (Map.Entry<String, List&lt;Object>> entry :
>>> response.getMetadata().entrySet()) {
>>>               List values = entry.getValue();
>>>               for (Object value : values) {
>>>                   rb.header(entry.getKey(), value);
>>>               }
>>>           }
>>>           return rb;
>>>       }
>>>
>>> * rb.entity(response.getEntity());
>>> * seems like , entity is null in ResponseBuilder rb from the
>> fromResponse
>>> method.
>>>
>>> Please let me know, what could be the solution to fix this issue?
>>>
>>>
>>>
>>> --
>>> View this message in context: http://cxf.547215.n5.nabble.
>> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
>> tp5748134p5782725.html
>> To unsubscribe from Closing of WebClient and Response objects, click here
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
>> .
>> NAML
>> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
> 
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 

Re: Closing of WebClient and Response objects

Posted by sbalustar <bs...@gmail.com>.
Hi Sergey,

   At runtime,  in Debug mode Changed the response.stream.auto.close=false.
Later on , i am not facing the Entity Not available Exception.

  Is there any impact on the performance when we disabled the flag?

On Wed, Aug 16, 2017 at 3:32 AM, Sergey Beryozkin [via CXF] <
ml+s547215n5782725h9@n5.nabble.com> wrote:

> Hi
>
> I don't quite understand what the issue is, does it happen when you
> enable "response.stream.auto.close" ? If yes - what happens if you do
> not enable this property ?
>
> CXF does not auto-close the input stream by default given of the few
> well-known side-effects.
>
> Given you have already tried to debug - it is better to set a breakpoint
> inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why
> InputStream is not available in your case
>
> Cheers, Sergey
>
> On 15/08/17 23:20, sbalustar wrote:
>
> > HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the
> below
> > issue.
> >
> > AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
> > javax.ws.rs.ProcessingException: java.lang.IllegalStateException:
> Entity is
> > not available
> >      at
> > org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>
> >      at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>
> >      at
> > org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>
> >      at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>
> >      at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>
> >      at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>
> >      at
> > com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
> >   ... 78 more
> >
> > I have gone through this ticket
> > https://issues.apache.org/jira/browse/CXF-5144 which you mentioned that
> Set
> > this property: "response.stream.auto.close" to true. This is done even
> > though we are getting the same issue.
> >
> > When i debug the code, in WebClient.invoke method this exception is
> occured.
> >
> >    protected Response handleResponse(Message outMessage, Class<?>
> > responseClass, Type genericType) {
> >          try {
> >              ResponseBuilder rb = setResponseBuilder(outMessage,
> > outMessage.getExchange());
> >              Response currentResponse = rb.clone().build();
> >              ((ResponseImpl)currentResponse).setOutMessage(outMessage);
> >
> >              Object entity = readBody(currentResponse, outMessage,
> > responseClass, genericType,
> >                                       new Annotation[]{});
> >
> >              if (entity == null) {
> >                  int status = currentResponse.getStatus();
> >                  if (status >= 400) {
> >                      entity = currentResponse.getEntity();
> >                  }
> >              }
> >              rb = JAXRSUtils.fromResponse(currentResponse);
> >
> >              rb.entity(entity instanceof Response
> >                        ? ((Response)entity).getEntity() : entity);
> >
> >              Response r = rb.build();
> >              getState().setResponse(r);
> >              ((ResponseImpl)r).setOutMessage(outMessage);
> >              return r;
> >          } catch (Throwable ex) {
> >              throw (ex instanceof ProcessingException) ?
> > (ProcessingException)ex
> >                                                    : new
> > ProcessingException(ex);
> >          } finally {
> >
> > ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>
> >          }
> >      }
> >
> >
> >    public static ResponseBuilder fromResponse(Response response) {
> >          ResponseBuilder rb = toResponseBuilder(response.getStatus());
> > *        rb.entity(response.getEntity());
> > *        for (Map.Entry<String, List&lt;Object>> entry :
> > response.getMetadata().entrySet()) {
> >              List values = entry.getValue();
> >              for (Object value : values) {
> >                  rb.header(entry.getKey(), value);
> >              }
> >          }
> >          return rb;
> >      }
> >
> > * rb.entity(response.getEntity());
> > * seems like , entity is null in ResponseBuilder rb from the
> fromResponse
> > method.
> >
> > Please let me know, what could be the solution to fix this issue?
> >
> >
> >
> > --
> > View this message in context: http://cxf.547215.n5.nabble.
> com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-
> tp5748134p5782725.html
> To unsubscribe from Closing of WebClient and Response objects, click here
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5748134&code=YnN1ZGFiYXRodWxhQGdtYWlsLmNvbXw1NzQ4MTM0fDEyODI4MTYwNTM=>
> .
> NAML
> <http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782748.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Closing of WebClient and Response objects

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I don't quite understand what the issue is, does it happen when you 
enable "response.stream.auto.close" ? If yes - what happens if you do 
not enable this property ?

CXF does not auto-close the input stream by default given of the few 
well-known side-effects.

Given you have already tried to debug - it is better to set a breakpoint 
inside org.apache.cxf.jaxrs.impl.ResponseImpl - there you will see why 
InputStream is not available in your case

Cheers, Sergey

On 15/08/17 23:20, sbalustar wrote:
> HI sergey, We are upgrading CXF version 2.7.7 to 3.1.8 and facing the below
> issue.
> 
> AUDIT:2017-08-15 11:31:11.047:localhost-startStop-1:"Caused by
> javax.ws.rs.ProcessingException: java.lang.IllegalStateException: Entity is
> not available
>      at
> org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1141)
>      at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1110)
>      at
> org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1035)
>      at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:892)
>      at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
>      at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:413)
>      at
> com.walmart.platform.soa.client.RestClient.invoke(RestClient.java:261)
>   ... 78 more
> 
> I have gone through this ticket
> https://issues.apache.org/jira/browse/CXF-5144 which you mentioned that Set
> this property: "response.stream.auto.close" to true. This is done even
> though we are getting the same issue.
> 
> When i debug the code, in WebClient.invoke method this exception is occured.
> 
>    protected Response handleResponse(Message outMessage, Class<?>
> responseClass, Type genericType) {
>          try {
>              ResponseBuilder rb = setResponseBuilder(outMessage,
> outMessage.getExchange());
>              Response currentResponse = rb.clone().build();
>              ((ResponseImpl)currentResponse).setOutMessage(outMessage);
>              
>              Object entity = readBody(currentResponse, outMessage,
> responseClass, genericType,
>                                       new Annotation[]{});
>              
>              if (entity == null) {
>                  int status = currentResponse.getStatus();
>                  if (status >= 400) {
>                      entity = currentResponse.getEntity();
>                  }
>              }
>              rb = JAXRSUtils.fromResponse(currentResponse);
>              
>              rb.entity(entity instanceof Response
>                        ? ((Response)entity).getEntity() : entity);
>              
>              Response r = rb.build();
>              getState().setResponse(r);
>              ((ResponseImpl)r).setOutMessage(outMessage);
>              return r;
>          } catch (Throwable ex) {
>              throw (ex instanceof ProcessingException) ?
> (ProcessingException)ex
>                                                    : new
> ProcessingException(ex);
>          } finally {
>             
> ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies();
>          }
>      }
> 
> 
>    public static ResponseBuilder fromResponse(Response response) {
>          ResponseBuilder rb = toResponseBuilder(response.getStatus());
> *        rb.entity(response.getEntity());
> *        for (Map.Entry<String, List&lt;Object>> entry :
> response.getMetadata().entrySet()) {
>              List values = entry.getValue();
>              for (Object value : values) {
>                  rb.header(entry.getKey(), value);
>              }
>          }
>          return rb;
>      }
> 
> * rb.entity(response.getEntity());
> * seems like , entity is null in ResponseBuilder rb from the fromResponse
> method.
> 
> Please let me know, what could be the solution to fix this issue?
> 
> 
> 
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Closing-of-WebClient-and-Response-objects-tp5748134p5782716.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/