@Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/html");
    resp.getWriter().println("<html><body>");

    String keyname = req.getParameter("keyname");
    String value = req.getParameter("value");

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    // Using the synchronous cache.
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));

    // display every element of kind TaskData for /datastore
    if (req.getParameterMap().isEmpty()) {
      // querying from datastore
      resp.getWriter().println("<h3>Datastore results:</h3>");
      List<String> listOfKeys = new ArrayList<String>();
      Query q = new Query("TaskData");
      PreparedQuery pq = datastore.prepare(q);
      for (Entity result : pq.asIterable()) {
        String datastore_key = result.getKey().getName();
        String taskData_value = (String) result.getProperty("value");
        Date taskData_date = (Date) result.getProperty("date");
        resp.getWriter()
            .println(
                "<p>keyname = "
                    + datastore_key
                    + "  value = "
                    + taskData_value
                    + " date = "
                    + taskData_date.toString()
                    + "</p>");
        listOfKeys.add(datastore_key);
      }
      // check which of the keys exist in memcache
      String memcache_value;
      resp.getWriter().println("<h3>Memcache results:</h3>");
      for (String datastore_key : listOfKeys) {
        memcache_value = (String) syncCache.get(datastore_key);
        if (memcache_value != null) {
          // String decoded = new String(memcache_value, "UTF-8");
          resp.getWriter()
              .println("<p>keyname = " + datastore_key + " value = " + memcache_value + "</p>");
        }
      }
    }

    // display element of kind TaskData with key=keyname
    else if (keyname != null && value == null) {

      // first check in the cache
      String memcache_value = (String) syncCache.get(keyname); // Read from cache.
      // Get value from datastore
      Key task_key = KeyFactory.createKey("TaskData", keyname);
      try {
        Entity tne = datastore.get(task_key);
        if (memcache_value == null) {
          resp.getWriter().println("<h2>Datastore</h2>");
        } else {
          resp.getWriter().println("<h2>Both</h2>");
        }

      } catch (EntityNotFoundException e) {
        resp.getWriter().println("<h2>Neither</h2>");
      }
    }

    // store element of kind TaskData with key=keyname and value=value
    else if (keyname != null && value != null) {
      Entity tne = new Entity("TaskData", keyname);
      tne.setProperty("value", value);
      tne.setProperty("date", new Date());
      datastore.put(tne);
      syncCache.put(keyname, value); // Populate cache.
      resp.getWriter()
          .println("<h2>Stored " + keyname + " and " + value + " in Datastore and Memcache</h2>");
    } else {

      resp.getWriter().println("<h2>You entered wrong query parameters</h2>");
    }

    /*
       Entity tne = new Entity("TaskData", "Person");
    alice.setProperty("gender", "female");
    alice.setProperty("age", 20);
    */

    resp.getWriter().println("</body></html>");
  }
  public List getIterationList(String projectId) {
    List<Map> list = new ArrayList<Map>();

    try {

      String apiUrl =
          rallyApiHost
              + "/iteration?"
              + "project="
              + rallyApiHost
              + "/project/"
              + projectId
              + "&fetch=true&order=Name%20desc&start=1&pagesize=100";

      String checkProjectRef = rallyApiHost + "/project/" + projectId;

      log.info("rallyApiUrl:" + apiUrl);
      log.info("checkProjectRef:" + checkProjectRef);

      String responseXML = getRallyXML(apiUrl);

      SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
      Date currentDate = new Date();

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String state = item.getChildText("State");

        String startDateStr = item.getChildText("StartDate");
        String endDateStr = item.getChildText("EndDate");

        Date startDate = ISO8601FORMAT.parse(startDateStr);
        Date endDate = ISO8601FORMAT.parse(endDateStr);

        boolean isCurrent = false;

        int startCheck = startDate.compareTo(currentDate);
        int endCheck = endDate.compareTo(currentDate);

        if (startCheck < 0 && endCheck > 0) {
          isCurrent = true;
        }

        log.info("name=" + name + " isCurrent=" + isCurrent);

        String releaseRef = item.getAttribute("ref").getValue();

        // In child project, parent object have to be filiered
        Element projectElement = item.getChild("Project");
        String projectRef = projectElement.getAttributeValue("ref");

        if (projectRef.equals(checkProjectRef)) {

          map.put("objId", objId);
          map.put("rallyRef", releaseRef);
          map.put("name", name);
          map.put("state", state);
          map.put("isCurrent", "" + isCurrent);

          list.add(map);
        }
      }

      log.info("-----------");

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }