public void writeResponse(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // Note: This is needed only for development
    String referer = request.getHeader("referer");
    URI refererUri = null;
    try {
      refererUri = new URI(referer);
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    if (refererUri != null && refererUri.getHost().equals("localhost")) {
      String url = "http://" + refererUri.getHost() + ":" + refererUri.getPort();
      response.addHeader("Access-Control-Allow-Origin", url);
      response.addHeader("Access-Control-Allow-Credentials", "true");
      response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
      response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    }
    result.writeResponse(response, callback);
  }