private void doHandle(final HttpServletResponse response, final StubResponse stubResponse)
      throws IOException {
    setResponseMainHeaders(response);
    setStubResponseHeaders(stubResponse, response);
    response.setStatus(Integer.parseInt(stubResponse.getStatus()));

    if (stubResponse.getLatency() != null) {
      try {
        final long latency = Long.parseLong(stubResponse.getLatency());
        TimeUnit.MILLISECONDS.sleep(latency);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
    response.getWriter().println(stubResponse.getBody());
  }
 private void setStubResponseHeaders(
     final StubResponse stubResponse, final HttpServletResponse response) {
   response.setCharacterEncoding("UTF-8");
   for (Map.Entry<String, String> entry : stubResponse.getHeaders().entrySet()) {
     response.setHeader(entry.getKey(), entry.getValue());
   }
 }