GZip encoding in JerseyWhat exactly is the ResourceConfig class in Jersey 2?GZIP encoding in Jersey 2 / GrizzlyJersey/JAX-RS : Return Content-Length in response header instead of chunked transfer encodingjersey 2.0 jaxrs RI - return json string on exceptionHow to make Jersey use GZip compression for the response message bodyHow do I set Content-Length when returning large objects in Jersey JAX-RS serverJersey Server Sent Events not working with Accept-Encoding gzipGetting the response's true wire size from a jersey clientof a HTTP jersey response that is chunked and gzipped by a filterStream large responses with jersey, asynchronouslyHow to consume a service with chunked-encoding transfer in java using Jersey FrameworkGZIP with httpclient 4.5.3Jersey framework resource response issue Chunked-Encoded data

My manager quit. Should I agree to defer wage increase to accommodate budget concerns?

Comma Code - Automate the Boring Stuff with Python

Does "as soon as" imply simultaneity?

Why was LOGO created?

Why does this image of Jupiter look so strange?

How can I indicate the first and the last reference number written in a page of the bibliography in the header of the page?

What is the difference between an astronaut in the ISS and a freediver in perfect neutral buoyancy?

Why is 6. Nge2 better, and 7. d5 a necessary push in this game?

Past participle ending in -t versus -en

Is it impolite to ask for an in-flight catalogue with no intention of buying?

What does it mean by "my days-of-the-week underwear only go to Thursday" in this context?

How to deal with a Homophobic PC

Passiflora Snow Queen is drying out

Why is STARTTLS still used?

Why did the Soviet Union not "grant" Inner Mongolia to Mongolia after World War Two?

How can this Stack Exchange site have an animated favicon?

Should the average user with no special access rights be worried about SMS-based 2FA being theoretically interceptable?

What should I consider when deciding whether to delay an exam?

What secular civic space would pioneers build for small frontier towns?

I transpose the source code, you transpose the input!

Why did UK NHS pay for homeopathic treatments?

Would you write key signatures for non-conventional scales?

Is the mass of paint relevant in rocket design?

Rounding the corners of tcolorbox



GZip encoding in Jersey


What exactly is the ResourceConfig class in Jersey 2?GZIP encoding in Jersey 2 / GrizzlyJersey/JAX-RS : Return Content-Length in response header instead of chunked transfer encodingjersey 2.0 jaxrs RI - return json string on exceptionHow to make Jersey use GZip compression for the response message bodyHow do I set Content-Length when returning large objects in Jersey JAX-RS serverJersey Server Sent Events not working with Accept-Encoding gzipGetting the response's true wire size from a jersey clientof a HTTP jersey response that is chunked and gzipped by a filterStream large responses with jersey, asynchronouslyHow to consume a service with chunked-encoding transfer in java using Jersey FrameworkGZIP with httpclient 4.5.3Jersey framework resource response issue Chunked-Encoded data






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm writing a RESTful web service in Jersey 2. I want to support the Gzip encoding for the responses. Following this answer, I enabled the org.glassfish.jersey.server.filter.EncodingFilter in my ResourceConfig class.



public class MyWebService extends ResourceConfig 
public MyWebService()
register(EncodingFilter.class);
register(GZipEncoder.class);
register(DeflateEncoder.class);




On my resource class, I'm returning a javax.ws.rs.core.Response object.



@GET
@Path("api/configs")
public Response listConfigs() throws Exception
List<UserConfig> configs = configService.getAll();
return Response.ok().entity(configs).build();



Now when I hit this api, I get a response but the response headers do not contain a Content-Encoding header, rather it contains Transfer-Encoding: chunked.



Request:



> GET /api/configs HTTP/1.1
> Accept-Encoding: gzip


Response:



> HTTP/1.1 200 
> Transfer-Encoding: chunked
* Received 14.8 KB chunk
* Received 504 B chunk
* Received 15.2 KB chunk
* Received 506 B chunk
* Received 15.1 KB chunk
* Received 514 B chunk


There is no Content-Encoding: gzip header in the response, nor there is any Content-Length header.



I'm using Jersey 2.27 on Tomcat 9.



Is there any other configuration I'm missing? How do I get these two headers and get the response as gzip compressed rather than receiving chunked response?



Edit: I have noticed that when I send large files ( > 1000 KB) I get both the Content-Encoding: gzip and Transfer-Encoding: chunked headers.










share|improve this question


























  • I don't think MyWebService is being picked up by the container. Are you loading it from web.xml like shown in this answer? --- Try putting a breakpoint on the first register(...) call to see if it's being executed. If it is, then put a breakpoint at the beginning of filter(...) in the class EncodingFilter, and step through to see any it's not applying the gzip encoding.

    – Andreas
    Mar 29 at 20:22

















3















I'm writing a RESTful web service in Jersey 2. I want to support the Gzip encoding for the responses. Following this answer, I enabled the org.glassfish.jersey.server.filter.EncodingFilter in my ResourceConfig class.



public class MyWebService extends ResourceConfig 
public MyWebService()
register(EncodingFilter.class);
register(GZipEncoder.class);
register(DeflateEncoder.class);




On my resource class, I'm returning a javax.ws.rs.core.Response object.



@GET
@Path("api/configs")
public Response listConfigs() throws Exception
List<UserConfig> configs = configService.getAll();
return Response.ok().entity(configs).build();



Now when I hit this api, I get a response but the response headers do not contain a Content-Encoding header, rather it contains Transfer-Encoding: chunked.



Request:



> GET /api/configs HTTP/1.1
> Accept-Encoding: gzip


Response:



> HTTP/1.1 200 
> Transfer-Encoding: chunked
* Received 14.8 KB chunk
* Received 504 B chunk
* Received 15.2 KB chunk
* Received 506 B chunk
* Received 15.1 KB chunk
* Received 514 B chunk


There is no Content-Encoding: gzip header in the response, nor there is any Content-Length header.



I'm using Jersey 2.27 on Tomcat 9.



Is there any other configuration I'm missing? How do I get these two headers and get the response as gzip compressed rather than receiving chunked response?



Edit: I have noticed that when I send large files ( > 1000 KB) I get both the Content-Encoding: gzip and Transfer-Encoding: chunked headers.










share|improve this question


























  • I don't think MyWebService is being picked up by the container. Are you loading it from web.xml like shown in this answer? --- Try putting a breakpoint on the first register(...) call to see if it's being executed. If it is, then put a breakpoint at the beginning of filter(...) in the class EncodingFilter, and step through to see any it's not applying the gzip encoding.

    – Andreas
    Mar 29 at 20:22













3












3








3


1






I'm writing a RESTful web service in Jersey 2. I want to support the Gzip encoding for the responses. Following this answer, I enabled the org.glassfish.jersey.server.filter.EncodingFilter in my ResourceConfig class.



public class MyWebService extends ResourceConfig 
public MyWebService()
register(EncodingFilter.class);
register(GZipEncoder.class);
register(DeflateEncoder.class);




On my resource class, I'm returning a javax.ws.rs.core.Response object.



@GET
@Path("api/configs")
public Response listConfigs() throws Exception
List<UserConfig> configs = configService.getAll();
return Response.ok().entity(configs).build();



Now when I hit this api, I get a response but the response headers do not contain a Content-Encoding header, rather it contains Transfer-Encoding: chunked.



Request:



> GET /api/configs HTTP/1.1
> Accept-Encoding: gzip


Response:



> HTTP/1.1 200 
> Transfer-Encoding: chunked
* Received 14.8 KB chunk
* Received 504 B chunk
* Received 15.2 KB chunk
* Received 506 B chunk
* Received 15.1 KB chunk
* Received 514 B chunk


There is no Content-Encoding: gzip header in the response, nor there is any Content-Length header.



I'm using Jersey 2.27 on Tomcat 9.



Is there any other configuration I'm missing? How do I get these two headers and get the response as gzip compressed rather than receiving chunked response?



Edit: I have noticed that when I send large files ( > 1000 KB) I get both the Content-Encoding: gzip and Transfer-Encoding: chunked headers.










share|improve this question
















I'm writing a RESTful web service in Jersey 2. I want to support the Gzip encoding for the responses. Following this answer, I enabled the org.glassfish.jersey.server.filter.EncodingFilter in my ResourceConfig class.



public class MyWebService extends ResourceConfig 
public MyWebService()
register(EncodingFilter.class);
register(GZipEncoder.class);
register(DeflateEncoder.class);




On my resource class, I'm returning a javax.ws.rs.core.Response object.



@GET
@Path("api/configs")
public Response listConfigs() throws Exception
List<UserConfig> configs = configService.getAll();
return Response.ok().entity(configs).build();



Now when I hit this api, I get a response but the response headers do not contain a Content-Encoding header, rather it contains Transfer-Encoding: chunked.



Request:



> GET /api/configs HTTP/1.1
> Accept-Encoding: gzip


Response:



> HTTP/1.1 200 
> Transfer-Encoding: chunked
* Received 14.8 KB chunk
* Received 504 B chunk
* Received 15.2 KB chunk
* Received 506 B chunk
* Received 15.1 KB chunk
* Received 514 B chunk


There is no Content-Encoding: gzip header in the response, nor there is any Content-Length header.



I'm using Jersey 2.27 on Tomcat 9.



Is there any other configuration I'm missing? How do I get these two headers and get the response as gzip compressed rather than receiving chunked response?



Edit: I have noticed that when I send large files ( > 1000 KB) I get both the Content-Encoding: gzip and Transfer-Encoding: chunked headers.







java jersey jax-rs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 7 at 13:15







Termin4t0r

















asked Mar 28 at 17:44









Termin4t0r Termin4t0r

405 bronze badges




405 bronze badges















  • I don't think MyWebService is being picked up by the container. Are you loading it from web.xml like shown in this answer? --- Try putting a breakpoint on the first register(...) call to see if it's being executed. If it is, then put a breakpoint at the beginning of filter(...) in the class EncodingFilter, and step through to see any it's not applying the gzip encoding.

    – Andreas
    Mar 29 at 20:22

















  • I don't think MyWebService is being picked up by the container. Are you loading it from web.xml like shown in this answer? --- Try putting a breakpoint on the first register(...) call to see if it's being executed. If it is, then put a breakpoint at the beginning of filter(...) in the class EncodingFilter, and step through to see any it's not applying the gzip encoding.

    – Andreas
    Mar 29 at 20:22
















I don't think MyWebService is being picked up by the container. Are you loading it from web.xml like shown in this answer? --- Try putting a breakpoint on the first register(...) call to see if it's being executed. If it is, then put a breakpoint at the beginning of filter(...) in the class EncodingFilter, and step through to see any it's not applying the gzip encoding.

– Andreas
Mar 29 at 20:22





I don't think MyWebService is being picked up by the container. Are you loading it from web.xml like shown in this answer? --- Try putting a breakpoint on the first register(...) call to see if it's being executed. If it is, then put a breakpoint at the beginning of filter(...) in the class EncodingFilter, and step through to see any it's not applying the gzip encoding.

– Andreas
Mar 29 at 20:22












1 Answer
1






active

oldest

votes


















1
















Whether to use Transfer-Encoding or Content-Length is entirely the container's discretion. It depends on the allowed buffer size.



If the container has to set the Content-Length header, it has to know the length of the compressed response beforehand, therefore, the container has to buffer the entire response in the memory.



In case of Jersey, the content length buffer size is defined by ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER. By default, this is 8192 bytes.



You can easily increase this from your MyWebService class:



public class MyWebService extends ResourceConfig 
public MyWebService()
register(EncodingFilter.class);
register(GZipEncoder.class);
register(DeflateEncoder.class);

...

property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 32768);





Hope this helps.






share|improve this answer



























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403910%2fgzip-encoding-in-jersey%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1
















    Whether to use Transfer-Encoding or Content-Length is entirely the container's discretion. It depends on the allowed buffer size.



    If the container has to set the Content-Length header, it has to know the length of the compressed response beforehand, therefore, the container has to buffer the entire response in the memory.



    In case of Jersey, the content length buffer size is defined by ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER. By default, this is 8192 bytes.



    You can easily increase this from your MyWebService class:



    public class MyWebService extends ResourceConfig 
    public MyWebService()
    register(EncodingFilter.class);
    register(GZipEncoder.class);
    register(DeflateEncoder.class);

    ...

    property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 32768);





    Hope this helps.






    share|improve this answer





























      1
















      Whether to use Transfer-Encoding or Content-Length is entirely the container's discretion. It depends on the allowed buffer size.



      If the container has to set the Content-Length header, it has to know the length of the compressed response beforehand, therefore, the container has to buffer the entire response in the memory.



      In case of Jersey, the content length buffer size is defined by ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER. By default, this is 8192 bytes.



      You can easily increase this from your MyWebService class:



      public class MyWebService extends ResourceConfig 
      public MyWebService()
      register(EncodingFilter.class);
      register(GZipEncoder.class);
      register(DeflateEncoder.class);

      ...

      property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 32768);





      Hope this helps.






      share|improve this answer



























        1














        1










        1









        Whether to use Transfer-Encoding or Content-Length is entirely the container's discretion. It depends on the allowed buffer size.



        If the container has to set the Content-Length header, it has to know the length of the compressed response beforehand, therefore, the container has to buffer the entire response in the memory.



        In case of Jersey, the content length buffer size is defined by ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER. By default, this is 8192 bytes.



        You can easily increase this from your MyWebService class:



        public class MyWebService extends ResourceConfig 
        public MyWebService()
        register(EncodingFilter.class);
        register(GZipEncoder.class);
        register(DeflateEncoder.class);

        ...

        property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 32768);





        Hope this helps.






        share|improve this answer













        Whether to use Transfer-Encoding or Content-Length is entirely the container's discretion. It depends on the allowed buffer size.



        If the container has to set the Content-Length header, it has to know the length of the compressed response beforehand, therefore, the container has to buffer the entire response in the memory.



        In case of Jersey, the content length buffer size is defined by ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER. By default, this is 8192 bytes.



        You can easily increase this from your MyWebService class:



        public class MyWebService extends ResourceConfig 
        public MyWebService()
        register(EncodingFilter.class);
        register(GZipEncoder.class);
        register(DeflateEncoder.class);

        ...

        property(ServerProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, 32768);





        Hope this helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 7 at 13:24









        bytesandcaffeinebytesandcaffeine

        1535 bronze badges




        1535 bronze badges

































            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403910%2fgzip-encoding-in-jersey%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해