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 <
[email protected]> 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] <
> [email protected]> 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<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.