title: Spring RestTemplate: Read chuncked response
body: <p>I'm using Spring RestTemplate to write a RESTful client.
  I need to intantiate the HTTP Chunk mode on client side, so I can read chuncked data sent by the server I'm calling.</p>
  
  <p>Can anyone help me how to do that? I've already searched on the internet for something that looks like what I need to do, but it didn't help.
  Can you, at least, put me on some direction? and I'll will try to do it on my own :)</p>
  
  <p>I need to do something like this:</p>
  
  <pre><code>ExecutorService executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 0L, //
          TimeUnit.SECONDS, new SynchronousQueue&lt;Runnable&gt;());
      executorService.execute(() -&gt; {
         ChunkedInput&lt;JsonNode&gt; chunkedInput = null;
         JsonNode chunk = null;
         while (true) {
          try {
             chunkedInput = getJsonNodeChunkedInput(privatePollingUrl);
          } catch (CtiAlcatelException e) {
             logger.error("Getting Json Node Chunked Input refused", e);
          }
  
          while ((chunk = chunkedInput.read()) != null) {
             logger.debug("-- Next chunk received: {}", chunk);
             try {
              processEvent(chunk);
             } catch (Exception e) {
              logger.error("Error occured while processing chunk {}", chunk, e);
             }
          }
  
          if (Thread.currentThread().isInterrupted()) {
             logger.info("Chunk thread interrupted");
             Thread.currentThread().interrupt();
             chunkedInput.close();
          }
  
          logger.debug("-- Restarting the chunk");
         }
  
      });
  
      private ChunkedInput&lt;JsonNode&gt; getJsonNodeChunkedInput(String privatePollingUrl) throws CtiAlcatelException {
          logger.trace("&gt;&gt; getJsonNodeChunkedInput() &gt; Got param: {}", privatePollingUrl);
  
          final Response response = restfulService.get(privatePollingUrl, alcAdminCredential.getCookie(), null);
          ChunkedInput&lt;JsonNode&gt; chunkedInput = response.readEntity(new GenericType&lt;ChunkedInput&lt;JsonNode&gt;&gt;() {
          });
  
          logger.trace("&lt;&lt; getJsonNodeChunkedInput() &lt; Returning: {}", chunkedInput);
          return chunkedInput;
         }
  </code></pre>
  
  <p>This is done using Jersey client.
  Thank you very much</p>