[Jersey] ChunkedOutput not producing Chunked output on browser

From: gschandok <>
Date: Wed, 3 Dec 2014 20:28:41 -0700 (MST)


I am using org.glassfish.jersey.server.ChunkedOutput to get the chunked
response to my request. When I hit the URL through browser, instead of
getting output as separate chunks, I am getting all the chunks at once.
But when I use a Test Client to hit the resource, I get the output as
separate chunks.

Server Used: Glassfish 4.0
Jersey version 2.13

Resource method is as follows:

public ChunkedOutput<String> getChunkedResponse(@Context HttpServletRequest
request) {

    final ChunkedOutput<String> output = new ChunkedOutput<String>(

    new Thread() {
        public void run() {
            try {
                String chunk;
                String arr[] = { "America\r\n", "London\r\n", "Delhi\r\n",
"null" };
                int i = 0;
                while (!(chunk = arr[i]).equals("null")) {
            } catch (IOException e) {
                logger.error("IOException : ", e);
            } catch (InterruptedException e) {
                logger.error("InterruptedException : ", e);
            } finally {
                try {
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    logger.error("IOException IN finally : ", e);

    // the output will be probably returned even before
    // a first chunk is written by the new thread
    return output;

Test Client method is as follows:

  private static void testChunkedResponse(WebTarget target){
      final Response response = target.path("restRes").path("chunk")
        final ChunkedInput<String> chunkedInput =
GenericType<ChunkedInput&lt;String>>() {});
        String chunk;
        while ((chunk = != null) {
  "Next chunk received: " + chunk);

Can someone please help me understand why response is not getting chunked on
browser and what can be done about it?

View this message in context:
Sent from the Jersey mailing list archive at