You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Francesco Chicchiriccò <il...@apache.org> on 2014/07/09 10:45:36 UTC

[CXF 3.0.0.] Response with closed entity after client.invoke: could it be?

HI all,
this snippet

WebClient client = ...;
Response response = client.invoke(method, inputStream);
response.getEntity();

fails with

java.lang.IllegalStateException: Entity is not available
         at 
org.apache.cxf.jaxrs.impl.ResponseImpl.checkEntityIsClosed(ResponseImpl.java:475)
         at 
org.apache.cxf.jaxrs.impl.ResponseImpl.getActualEntity(ResponseImpl.java:137)
         at 
org.apache.cxf.jaxrs.impl.ResponseImpl.getEntity(ResponseImpl.java:142)

I am using CXF 3.0.0 (the same code works fine with CXF 2.7.11): any idea?

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC, Olingo PMC
http://people.apache.org/~ilgrosso/


Re: [CXF 3.0.0.] Response with closed entity after client.invoke: could it be?

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 09/07/2014 13:09, Sergey Beryozkin wrote:
> Hi Francesco, I reverted a WebClient.close() -> Response.close() code 
> sequence for now anyway, see [1]. It is unlikely JAX-RS 2.0 
> Client.close() would be requested to track all of the Responses to 
> make sure it auto closes them too and I'd like WebClient.close be 
> consistent with the standard approach.

Thanks Sergey.
Regards.

> [1] https://issues.apache.org/jira/browse/CXF-5865
> On 09/07/14 10:32, Sergey Beryozkin wrote:
>> Hi Francesco
>>
>> On 09/07/14 10:16, Francesco Chicchiriccò wrote:
>>> On 09/07/2014 10:45, Francesco Chicchiriccò wrote:
>>>> iI all,
>>>> this snippet
>>>>
>>>> WebClient client = ...;
>>>> Response response = client.invoke(method, inputStream);
>>>> response.getEntity();
>>>>
>>>> fails with
>>>>
>>>> java.lang.IllegalStateException: Entity is not available
>>>>         at
>>>> org.apache.cxf.jaxrs.impl.ResponseImpl.checkEntityIsClosed(ResponseImpl.java:475) 
>>>>
>>>>
>>>>
>>>>         at
>>>> org.apache.cxf.jaxrs.impl.ResponseImpl.getActualEntity(ResponseImpl.java:137) 
>>>>
>>>>
>>>>
>>>>         at
>>>> org.apache.cxf.jaxrs.impl.ResponseImpl.getEntity(ResponseImpl.java:142) 
>>>>
>>>>
>>>> I am using CXF 3.0.0 (the same code works fine with CXF 2.7.11): any
>>>> idea?
>>>
>>> It seems I've over-simplified the snippet above: it should have been,
>>> actually
>>>
>>> WebClient client = ...;
>>> Response response = client.invoke(method, inputStream);
>>> client.close();
>>> response.getEntity();
>>>
>>> It seems that with CXF 3.0.0 closing a client implies also closing the
>>> response object, thus causing the exception above: correct?
>>>
>> Yes. I did it for the code to stay in sync  with
>> https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/client/Client.html#close() 
>>
>>
>>
>> "Close client instance and all it's associated resources" implied to me
>> that a Response Input Stream also needs to be closed due to it being a
>> 'production' of the client activity.
>>
>> However now I'm not exactly sure a Response needs to be closed if the
>> client is closed. There's no any guidance right now in JAX-RS 2.0 docs
>> so I'll ask and get back
>>
>> Thanks, Sergey
>>
>>
>>> Regards.

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC, Olingo PMC
http://people.apache.org/~ilgrosso/


Re: [CXF 3.0.0.] Response with closed entity after client.invoke: could it be?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Francesco, I reverted a WebClient.close() -> Response.close() code 
sequence for now anyway, see [1]. It is unlikely JAX-RS 2.0 
Client.close() would be requested to track all of the Responses to make 
sure it auto closes them too and I'd like WebClient.close be consistent 
with the standard approach.

Thanks, Sergey

[1] https://issues.apache.org/jira/browse/CXF-5865
On 09/07/14 10:32, Sergey Beryozkin wrote:
> Hi Francesco
>
> On 09/07/14 10:16, Francesco Chicchiriccò wrote:
>> On 09/07/2014 10:45, Francesco Chicchiriccò wrote:
>>> iI all,
>>> this snippet
>>>
>>> WebClient client = ...;
>>> Response response = client.invoke(method, inputStream);
>>> response.getEntity();
>>>
>>> fails with
>>>
>>> java.lang.IllegalStateException: Entity is not available
>>>         at
>>> org.apache.cxf.jaxrs.impl.ResponseImpl.checkEntityIsClosed(ResponseImpl.java:475)
>>>
>>>
>>>         at
>>> org.apache.cxf.jaxrs.impl.ResponseImpl.getActualEntity(ResponseImpl.java:137)
>>>
>>>
>>>         at
>>> org.apache.cxf.jaxrs.impl.ResponseImpl.getEntity(ResponseImpl.java:142)
>>>
>>> I am using CXF 3.0.0 (the same code works fine with CXF 2.7.11): any
>>> idea?
>>
>> It seems I've over-simplified the snippet above: it should have been,
>> actually
>>
>> WebClient client = ...;
>> Response response = client.invoke(method, inputStream);
>> client.close();
>> response.getEntity();
>>
>> It seems that with CXF 3.0.0 closing a client implies also closing the
>> response object, thus causing the exception above: correct?
>>
> Yes. I did it for the code to stay in sync  with
> https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/client/Client.html#close()
>
>
> "Close client instance and all it's associated resources" implied to me
> that a Response Input Stream also needs to be closed due to it being a
> 'production' of the client activity.
>
> However now I'm not exactly sure a Response needs to be closed if the
> client is closed. There's no any guidance right now in JAX-RS 2.0 docs
> so I'll ask and get back
>
> Thanks, Sergey
>
>
>> Regards.
>>
>


-- 
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Re: [CXF 3.0.0.] Response with closed entity after client.invoke: could it be?

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

On 09/07/14 10:16, Francesco Chicchiriccò wrote:
> On 09/07/2014 10:45, Francesco Chicchiriccò wrote:
>> iI all,
>> this snippet
>>
>> WebClient client = ...;
>> Response response = client.invoke(method, inputStream);
>> response.getEntity();
>>
>> fails with
>>
>> java.lang.IllegalStateException: Entity is not available
>>         at
>> org.apache.cxf.jaxrs.impl.ResponseImpl.checkEntityIsClosed(ResponseImpl.java:475)
>>
>>         at
>> org.apache.cxf.jaxrs.impl.ResponseImpl.getActualEntity(ResponseImpl.java:137)
>>
>>         at
>> org.apache.cxf.jaxrs.impl.ResponseImpl.getEntity(ResponseImpl.java:142)
>>
>> I am using CXF 3.0.0 (the same code works fine with CXF 2.7.11): any
>> idea?
>
> It seems I've over-simplified the snippet above: it should have been,
> actually
>
> WebClient client = ...;
> Response response = client.invoke(method, inputStream);
> client.close();
> response.getEntity();
>
> It seems that with CXF 3.0.0 closing a client implies also closing the
> response object, thus causing the exception above: correct?
>
Yes. I did it for the code to stay in sync  with
https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/client/Client.html#close()

"Close client instance and all it's associated resources" implied to me 
that a Response Input Stream also needs to be closed due to it being a 
'production' of the client activity.

However now I'm not exactly sure a Response needs to be closed if the 
client is closed. There's no any guidance right now in JAX-RS 2.0 docs 
so I'll ask and get back

Thanks, Sergey


> Regards.
>


Re: [CXF 3.0.0.] Response with closed entity after client.invoke: could it be?

Posted by Daniel Kulp <dk...@apache.org>.
On Jul 9, 2014, at 5:16 AM, Francesco Chicchiriccò <il...@apache.org> wrote:

> On 09/07/2014 10:45, Francesco Chicchiriccò wrote:
> 
> It seems I've over-simplified the snippet above: it should have been, actually
> 
> WebClient client = ...;
> Response response = client.invoke(method, inputStream);
> client.close();
> response.getEntity();
> 
> It seems that with CXF 3.0.0 closing a client implies also closing the response object, thus causing the exception above: correct?

Even with Sergey’s change, I wouldn’t rely on this.   Closing the client SHOULD result in the transport being shut down.   For the default URLConnection  based transport, that doesn’t really do anything so the InputStream would still be valid.  For the async http clients, this could result in the thread pools and listeners and everything being shutdown and thus nothing would be listening for any more data to come in.   


-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: [CXF 3.0.0.] Response with closed entity after client.invoke: could it be?

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 09/07/2014 10:45, Francesco Chicchiriccò wrote:
> iI all,
> this snippet
>
> WebClient client = ...;
> Response response = client.invoke(method, inputStream);
> response.getEntity();
>
> fails with
>
> java.lang.IllegalStateException: Entity is not available
>         at 
> org.apache.cxf.jaxrs.impl.ResponseImpl.checkEntityIsClosed(ResponseImpl.java:475)
>         at 
> org.apache.cxf.jaxrs.impl.ResponseImpl.getActualEntity(ResponseImpl.java:137)
>         at 
> org.apache.cxf.jaxrs.impl.ResponseImpl.getEntity(ResponseImpl.java:142)
>
> I am using CXF 3.0.0 (the same code works fine with CXF 2.7.11): any 
> idea?

It seems I've over-simplified the snippet above: it should have been, 
actually

WebClient client = ...;
Response response = client.invoke(method, inputStream);
client.close();
response.getEntity();

It seems that with CXF 3.0.0 closing a client implies also closing the 
response object, thus causing the exception above: correct?

Regards.

-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC, Olingo PMC
http://people.apache.org/~ilgrosso/