title: Json response in netty and java
body: <p>I want to send a json response using a netty http server. I use Gson for the json creation. My code looks like that</p>
  
  <pre><code>HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
              HttpResponseStatus.OK);
  response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0);
  response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/json");
  JsonObject jsonResponseMessage = new JsonObject();
  jsonResponseMessage.addProperty("result", success);
  ctx.write(jsonResponseMessage);
  response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, jsonResponseMessage.toString().length());
  ctx.write(response);
  </code></pre>
  
  <p>inside channelRead0 method, and </p>
  
  <pre><code>ctx.flush()
  </code></pre>
  
  <p>inside channelReadComplete method. The problem is that the I never get the response, back, it seems that the request gets stuck and never return a response. I believe it has to do with the content length. Do I need to do something more?</p>