title: Java REST Chunked Encoding
body: <p>I'm trying to read some information with a REST-Service that uses chunk-encoding. </p>
  
  <pre><code>String encodedURL = URLEncoder.encode(url, "UTF-8");
  WebClient client = org.apache.cxf.jaxrs.client.WebClient.create(encodedURL).accept("text/html");
  Response response = client.get();
  </code></pre>
  
  <p>The response contains a status, metadata and the entity. The metadata contains the following information:</p>
  
  <blockquote>
    <p>{Date=[Thu, 13 Oct 2011 13:27:02 GMT], Vary=[Accept-Encoding,
    User-Agent], Transfer-Encoding=[chunked], Keep-Alive=[timeout=15,
    max=100], Content-Type=[text/html; charset=charset=UTF-8],
    Connection=[Keep-Alive], X-Pad=[avoid browser bug],
    Server=[Apache/2.2.3 (Linux/SUSE)]}</p>
  </blockquote>
  
  <p>and the entity contains an instance of the type sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.</p>
  
  <p>I the past, I've been using the following line of of code, to get the entire result string:</p>
  
  <pre><code>String resultString = client.get(String.class);
  </code></pre>
  
  <p>But somehow, this line throws an exception:</p>
  
  <blockquote>
    <p>.Problem with reading the response message, class : class
    java.lang.String, ContentType : text/html;charset=charset=UTF-8.
    org.apache.cxf.jaxrs.client.ClientWebApplicationException: .Problem
    with reading the response message, class : class java.lang.String,
    ContentType : text/html;charset=charset=UTF-8. </p>
    
    <p>... caused by:</p>
    
    <p>Caused by: java.io.UnsupportedEncodingException: charset=UTF-8    at
    sun.nio.cs.StreamDecoder.forInputStreamReader(Unknown Source)     at
    java.io.InputStreamReader.(Unknown Source)  at
    org.apache.cxf.helpers.IOUtils.toString(IOUtils.java:180)     at
    org.apache.cxf.helpers.IOUtils.toString(IOUtils.java:166)     at
    org.apache.cxf.jaxrs.provider.PrimitiveTextProvider.readFrom(PrimitiveTextProvider.java:51)
      at
    org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:435)
      ... 49 more</p>
  </blockquote>
  
  <p>Is there a straightforward solution to the get the entire content of the response?</p>
  
  <p>Thank you!</p>
  
  <p>kon</p>