You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Dmitri T <ta...@gmail.com> on 2023/01/17 12:01:53 UTC

Empty stream for gzipped response

Hello.
After upgrading from Camel 3.7.x to the recent version, gzipped
response (Content-Encoding: gzip) from a route comes empty. I have
found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
(line 602 doWriteGZIPResponse method): Object body =
exchange.getIn().getBody();
I debugged and found. that stream was not empty, if that line was
replaced by Object body = message.getBody(InputStream.class);, like it
was done for plain non-gzipped response in doWriteDirectResponse
method.
I have tested this change with ServletStreamingGzipChunkedTest successfully.
Is this an issue and could be fixed in the next Camel release?

Re: Empty stream for gzipped response

Posted by Claus Ibsen <cl...@gmail.com>.
Can you put together a reproducer example and either put that on github
with readme how to run, or create a JIRA and attach it as .zip.
This makes it easier for us to investigate

On Fri, Jan 20, 2023 at 10:38 AM Dmitri T <ta...@gmail.com> wrote:

> BTW, it seems that behavior comes from "The type converter from
> InputStream to byte[] will now close the input stream after the
> conversion" (
> https://camel.apache.org/manual/camel-3x-upgrade-guide-3_18.html)
>
> чт, 19 янв. 2023 г. в 17:42, Dmitri T <ta...@gmail.com>:
> >
> > Hi.
> >
> > This fix does not work. Reset method just sets pos = mark, but it is
> > already 0 (stream is empty).
> >
> > чт, 19 янв. 2023 г. в 15:57, Claus Ibsen <cl...@gmail.com>:
> > >
> > > Hi
> > >
> > > Okay can you try with adding reset to stream cache such as and give
> that a
> > > test locally.
> > >
> > > Object body = exchange.getIn().getBody();
> > > // reset the stream cache if the body is the instance of StreamCache
> > > if (body instanceof StreamCache) {
> > >     ((StreamCache) body).reset();
> > > }
> > > if (body instanceof InputStream) {
> > >     InputStream is = (InputStream) body;
> > >     if (LOG.isDebugEnabled()) {
> > >         LOG.debug("Streaming GZIP response in chunked mode with buffer
> > > size {}", response.getBufferSize());
> > >     }
> > >
> > >
> > >
> > > On Wed, Jan 18, 2023 at 10:22 AM Claus Ibsen <cl...@gmail.com>
> wrote:
> > >
> > > >
> > > >
> > > > On Tue, Jan 17, 2023 at 3:16 PM Dmitri T <ta...@gmail.com>
> wrote:
> > > >
> > > >> Sure.
> > > >> The Server is jetty from camel-jetty.
> > > >> Message body is:
> > > >> org.apache.camel.converter.stream.InputStreamCache for
> > > >> exchange.getIn().getBody() (empty)
> > > >> org.apache.camel.converter.stream.ByteArrayInputStreamCache for
> > > >> message.getBody() (not empty)
> > > >>
> > > >>
> > > > Thanks for reporting this. You are welcome to create a JIRA so we
> can work
> > > > on a fix.
> > > > I think we need to check for StreamCache in that part of the code.
> > > >
> > > >
> > > >
> > > >> вт, 17 янв. 2023 г. в 16:59, Claus Ibsen <cl...@gmail.com>:
> > > >> >
> > > >>
> > > >
> > > >
> > > >
> > > >
> > > >> > Hi
> > > >> >
> > > >> > Thanks for reporting. Can you tell a bit more about what HTTP
> server you
> > > >> > are using? And what class type the message body is at that moment
> in
> > > >> > doWriteGZIPResponse?
> > > >> > If the body is not an instance of InputStream then what type is
> that
> > > >> body
> > > >> > of yours?
> > > >> >
> > > >> >
> > > >> > On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com>
> wrote:
> > > >> >
> > > >> > > Hello.
> > > >> > > After upgrading from Camel 3.7.x to the recent version, gzipped
> > > >> > > response (Content-Encoding: gzip) from a route comes empty. I
> have
> > > >> > > found an issue CAMEL-13092 (fixed in Camel 3.10) which caused
> that in
> > > >> > >
> > > >> > >
> > > >>
> camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
> > > >> > > (line 602 doWriteGZIPResponse method): Object body =
> > > >> > > exchange.getIn().getBody();
> > > >> > > I debugged and found. that stream was not empty, if that line
> was
> > > >> > > replaced by Object body = message.getBody(InputStream.class);,
> like it
> > > >> > > was done for plain non-gzipped response in doWriteDirectResponse
> > > >> > > method.
> > > >> > > I have tested this change with ServletStreamingGzipChunkedTest
> > > >> > > successfully.
> > > >> > > Is this an issue and could be fixed in the next Camel release?
> > > >> > >
> > > >> >
> > > >> >
> > > >> > --
> > > >> > Claus Ibsen
> > > >> > -----------------
> > > >> > @davsclaus
> > > >> > Camel in Action 2: https://www.manning.com/ibsen2
> > > >>
> > > >>
> > > >>
> > > >> --
> > > >> Best regards,
> > > >> Dmitri
> > > >>
> > > >
> > > >
> > > > --
> > > > Claus Ibsen
> > > > -----------------
> > > > @davsclaus
> > > > Camel in Action 2: https://www.manning.com/ibsen2
> > > >
> > >
> > >
> > > --
> > > Claus Ibsen
> > > -----------------
> > > @davsclaus
> > > Camel in Action 2: https://www.manning.com/ibsen2
> >
> >
> >
> > --
> > Best regards,
> > Dmitri
>
>
>
> --
> Best regards,
> Dmitri
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Empty stream for gzipped response

Posted by Dmitri T <ta...@gmail.com>.
BTW, it seems that behavior comes from "The type converter from
InputStream to byte[] will now close the input stream after the
conversion" (https://camel.apache.org/manual/camel-3x-upgrade-guide-3_18.html)

чт, 19 янв. 2023 г. в 17:42, Dmitri T <ta...@gmail.com>:
>
> Hi.
>
> This fix does not work. Reset method just sets pos = mark, but it is
> already 0 (stream is empty).
>
> чт, 19 янв. 2023 г. в 15:57, Claus Ibsen <cl...@gmail.com>:
> >
> > Hi
> >
> > Okay can you try with adding reset to stream cache such as and give that a
> > test locally.
> >
> > Object body = exchange.getIn().getBody();
> > // reset the stream cache if the body is the instance of StreamCache
> > if (body instanceof StreamCache) {
> >     ((StreamCache) body).reset();
> > }
> > if (body instanceof InputStream) {
> >     InputStream is = (InputStream) body;
> >     if (LOG.isDebugEnabled()) {
> >         LOG.debug("Streaming GZIP response in chunked mode with buffer
> > size {}", response.getBufferSize());
> >     }
> >
> >
> >
> > On Wed, Jan 18, 2023 at 10:22 AM Claus Ibsen <cl...@gmail.com> wrote:
> >
> > >
> > >
> > > On Tue, Jan 17, 2023 at 3:16 PM Dmitri T <ta...@gmail.com> wrote:
> > >
> > >> Sure.
> > >> The Server is jetty from camel-jetty.
> > >> Message body is:
> > >> org.apache.camel.converter.stream.InputStreamCache for
> > >> exchange.getIn().getBody() (empty)
> > >> org.apache.camel.converter.stream.ByteArrayInputStreamCache for
> > >> message.getBody() (not empty)
> > >>
> > >>
> > > Thanks for reporting this. You are welcome to create a JIRA so we can work
> > > on a fix.
> > > I think we need to check for StreamCache in that part of the code.
> > >
> > >
> > >
> > >> вт, 17 янв. 2023 г. в 16:59, Claus Ibsen <cl...@gmail.com>:
> > >> >
> > >>
> > >
> > >
> > >
> > >
> > >> > Hi
> > >> >
> > >> > Thanks for reporting. Can you tell a bit more about what HTTP server you
> > >> > are using? And what class type the message body is at that moment in
> > >> > doWriteGZIPResponse?
> > >> > If the body is not an instance of InputStream then what type is that
> > >> body
> > >> > of yours?
> > >> >
> > >> >
> > >> > On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com> wrote:
> > >> >
> > >> > > Hello.
> > >> > > After upgrading from Camel 3.7.x to the recent version, gzipped
> > >> > > response (Content-Encoding: gzip) from a route comes empty. I have
> > >> > > found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
> > >> > >
> > >> > >
> > >> camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
> > >> > > (line 602 doWriteGZIPResponse method): Object body =
> > >> > > exchange.getIn().getBody();
> > >> > > I debugged and found. that stream was not empty, if that line was
> > >> > > replaced by Object body = message.getBody(InputStream.class);, like it
> > >> > > was done for plain non-gzipped response in doWriteDirectResponse
> > >> > > method.
> > >> > > I have tested this change with ServletStreamingGzipChunkedTest
> > >> > > successfully.
> > >> > > Is this an issue and could be fixed in the next Camel release?
> > >> > >
> > >> >
> > >> >
> > >> > --
> > >> > Claus Ibsen
> > >> > -----------------
> > >> > @davsclaus
> > >> > Camel in Action 2: https://www.manning.com/ibsen2
> > >>
> > >>
> > >>
> > >> --
> > >> Best regards,
> > >> Dmitri
> > >>
> > >
> > >
> > > --
> > > Claus Ibsen
> > > -----------------
> > > @davsclaus
> > > Camel in Action 2: https://www.manning.com/ibsen2
> > >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Best regards,
> Dmitri



-- 
Best regards,
Dmitri

Re: Empty stream for gzipped response

Posted by Dmitri T <ta...@gmail.com>.
Hi.

This fix does not work. Reset method just sets pos = mark, but it is
already 0 (stream is empty).

чт, 19 янв. 2023 г. в 15:57, Claus Ibsen <cl...@gmail.com>:
>
> Hi
>
> Okay can you try with adding reset to stream cache such as and give that a
> test locally.
>
> Object body = exchange.getIn().getBody();
> // reset the stream cache if the body is the instance of StreamCache
> if (body instanceof StreamCache) {
>     ((StreamCache) body).reset();
> }
> if (body instanceof InputStream) {
>     InputStream is = (InputStream) body;
>     if (LOG.isDebugEnabled()) {
>         LOG.debug("Streaming GZIP response in chunked mode with buffer
> size {}", response.getBufferSize());
>     }
>
>
>
> On Wed, Jan 18, 2023 at 10:22 AM Claus Ibsen <cl...@gmail.com> wrote:
>
> >
> >
> > On Tue, Jan 17, 2023 at 3:16 PM Dmitri T <ta...@gmail.com> wrote:
> >
> >> Sure.
> >> The Server is jetty from camel-jetty.
> >> Message body is:
> >> org.apache.camel.converter.stream.InputStreamCache for
> >> exchange.getIn().getBody() (empty)
> >> org.apache.camel.converter.stream.ByteArrayInputStreamCache for
> >> message.getBody() (not empty)
> >>
> >>
> > Thanks for reporting this. You are welcome to create a JIRA so we can work
> > on a fix.
> > I think we need to check for StreamCache in that part of the code.
> >
> >
> >
> >> вт, 17 янв. 2023 г. в 16:59, Claus Ibsen <cl...@gmail.com>:
> >> >
> >>
> >
> >
> >
> >
> >> > Hi
> >> >
> >> > Thanks for reporting. Can you tell a bit more about what HTTP server you
> >> > are using? And what class type the message body is at that moment in
> >> > doWriteGZIPResponse?
> >> > If the body is not an instance of InputStream then what type is that
> >> body
> >> > of yours?
> >> >
> >> >
> >> > On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com> wrote:
> >> >
> >> > > Hello.
> >> > > After upgrading from Camel 3.7.x to the recent version, gzipped
> >> > > response (Content-Encoding: gzip) from a route comes empty. I have
> >> > > found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
> >> > >
> >> > >
> >> camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
> >> > > (line 602 doWriteGZIPResponse method): Object body =
> >> > > exchange.getIn().getBody();
> >> > > I debugged and found. that stream was not empty, if that line was
> >> > > replaced by Object body = message.getBody(InputStream.class);, like it
> >> > > was done for plain non-gzipped response in doWriteDirectResponse
> >> > > method.
> >> > > I have tested this change with ServletStreamingGzipChunkedTest
> >> > > successfully.
> >> > > Is this an issue and could be fixed in the next Camel release?
> >> > >
> >> >
> >> >
> >> > --
> >> > Claus Ibsen
> >> > -----------------
> >> > @davsclaus
> >> > Camel in Action 2: https://www.manning.com/ibsen2
> >>
> >>
> >>
> >> --
> >> Best regards,
> >> Dmitri
> >>
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Best regards,
Dmitri

Re: Empty stream for gzipped response

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Okay can you try with adding reset to stream cache such as and give that a
test locally.

Object body = exchange.getIn().getBody();
// reset the stream cache if the body is the instance of StreamCache
if (body instanceof StreamCache) {
    ((StreamCache) body).reset();
}
if (body instanceof InputStream) {
    InputStream is = (InputStream) body;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Streaming GZIP response in chunked mode with buffer
size {}", response.getBufferSize());
    }



On Wed, Jan 18, 2023 at 10:22 AM Claus Ibsen <cl...@gmail.com> wrote:

>
>
> On Tue, Jan 17, 2023 at 3:16 PM Dmitri T <ta...@gmail.com> wrote:
>
>> Sure.
>> The Server is jetty from camel-jetty.
>> Message body is:
>> org.apache.camel.converter.stream.InputStreamCache for
>> exchange.getIn().getBody() (empty)
>> org.apache.camel.converter.stream.ByteArrayInputStreamCache for
>> message.getBody() (not empty)
>>
>>
> Thanks for reporting this. You are welcome to create a JIRA so we can work
> on a fix.
> I think we need to check for StreamCache in that part of the code.
>
>
>
>> вт, 17 янв. 2023 г. в 16:59, Claus Ibsen <cl...@gmail.com>:
>> >
>>
>
>
>
>
>> > Hi
>> >
>> > Thanks for reporting. Can you tell a bit more about what HTTP server you
>> > are using? And what class type the message body is at that moment in
>> > doWriteGZIPResponse?
>> > If the body is not an instance of InputStream then what type is that
>> body
>> > of yours?
>> >
>> >
>> > On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com> wrote:
>> >
>> > > Hello.
>> > > After upgrading from Camel 3.7.x to the recent version, gzipped
>> > > response (Content-Encoding: gzip) from a route comes empty. I have
>> > > found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
>> > >
>> > >
>> camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
>> > > (line 602 doWriteGZIPResponse method): Object body =
>> > > exchange.getIn().getBody();
>> > > I debugged and found. that stream was not empty, if that line was
>> > > replaced by Object body = message.getBody(InputStream.class);, like it
>> > > was done for plain non-gzipped response in doWriteDirectResponse
>> > > method.
>> > > I have tested this change with ServletStreamingGzipChunkedTest
>> > > successfully.
>> > > Is this an issue and could be fixed in the next Camel release?
>> > >
>> >
>> >
>> > --
>> > Claus Ibsen
>> > -----------------
>> > @davsclaus
>> > Camel in Action 2: https://www.manning.com/ibsen2
>>
>>
>>
>> --
>> Best regards,
>> Dmitri
>>
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Empty stream for gzipped response

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jan 17, 2023 at 3:16 PM Dmitri T <ta...@gmail.com> wrote:

> Sure.
> The Server is jetty from camel-jetty.
> Message body is:
> org.apache.camel.converter.stream.InputStreamCache for
> exchange.getIn().getBody() (empty)
> org.apache.camel.converter.stream.ByteArrayInputStreamCache for
> message.getBody() (not empty)
>
>
Thanks for reporting this. You are welcome to create a JIRA so we can work
on a fix.
I think we need to check for StreamCache in that part of the code.



> вт, 17 янв. 2023 г. в 16:59, Claus Ibsen <cl...@gmail.com>:
> >
>




> > Hi
> >
> > Thanks for reporting. Can you tell a bit more about what HTTP server you
> > are using? And what class type the message body is at that moment in
> > doWriteGZIPResponse?
> > If the body is not an instance of InputStream then what type is that body
> > of yours?
> >
> >
> > On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com> wrote:
> >
> > > Hello.
> > > After upgrading from Camel 3.7.x to the recent version, gzipped
> > > response (Content-Encoding: gzip) from a route comes empty. I have
> > > found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
> > >
> > >
> camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
> > > (line 602 doWriteGZIPResponse method): Object body =
> > > exchange.getIn().getBody();
> > > I debugged and found. that stream was not empty, if that line was
> > > replaced by Object body = message.getBody(InputStream.class);, like it
> > > was done for plain non-gzipped response in doWriteDirectResponse
> > > method.
> > > I have tested this change with ServletStreamingGzipChunkedTest
> > > successfully.
> > > Is this an issue and could be fixed in the next Camel release?
> > >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
> --
> Best regards,
> Dmitri
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Empty stream for gzipped response

Posted by Dmitri T <ta...@gmail.com>.
Sure.
The Server is jetty from camel-jetty.
Message body is:
org.apache.camel.converter.stream.InputStreamCache for
exchange.getIn().getBody() (empty)
org.apache.camel.converter.stream.ByteArrayInputStreamCache for
message.getBody() (not empty)

вт, 17 янв. 2023 г. в 16:59, Claus Ibsen <cl...@gmail.com>:
>
> Hi
>
> Thanks for reporting. Can you tell a bit more about what HTTP server you
> are using? And what class type the message body is at that moment in
> doWriteGZIPResponse?
> If the body is not an instance of InputStream then what type is that body
> of yours?
>
>
> On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com> wrote:
>
> > Hello.
> > After upgrading from Camel 3.7.x to the recent version, gzipped
> > response (Content-Encoding: gzip) from a route comes empty. I have
> > found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
> >
> > camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
> > (line 602 doWriteGZIPResponse method): Object body =
> > exchange.getIn().getBody();
> > I debugged and found. that stream was not empty, if that line was
> > replaced by Object body = message.getBody(InputStream.class);, like it
> > was done for plain non-gzipped response in doWriteDirectResponse
> > method.
> > I have tested this change with ServletStreamingGzipChunkedTest
> > successfully.
> > Is this an issue and could be fixed in the next Camel release?
> >
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Best regards,
Dmitri

Re: Empty stream for gzipped response

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Thanks for reporting. Can you tell a bit more about what HTTP server you
are using? And what class type the message body is at that moment in
doWriteGZIPResponse?
If the body is not an instance of InputStream then what type is that body
of yours?


On Tue, Jan 17, 2023 at 1:03 PM Dmitri T <ta...@gmail.com> wrote:

> Hello.
> After upgrading from Camel 3.7.x to the recent version, gzipped
> response (Content-Encoding: gzip) from a route comes empty. I have
> found an issue CAMEL-13092 (fixed in Camel 3.10) which caused that in
>
> camel-http-common/src/main/java/org/apache/camel/http/common/DefaultHttpBinding.java
> (line 602 doWriteGZIPResponse method): Object body =
> exchange.getIn().getBody();
> I debugged and found. that stream was not empty, if that line was
> replaced by Object body = message.getBody(InputStream.class);, like it
> was done for plain non-gzipped response in doWriteDirectResponse
> method.
> I have tested this change with ServletStreamingGzipChunkedTest
> successfully.
> Is this an issue and could be fixed in the next Camel release?
>


-- 
Claus Ibsen
-----------------
@davsclaus
Camel in Action 2: https://www.manning.com/ibsen2