public String retrieveUserId(HttpServletRequest req) { HttpSession session = req.getSession(); String userKey = "userId"; String userId = (String) session.getAttribute(userKey); if (userId == null) { String a = this.requestUserId(); userId = Helpers.jsonFromString(a).getString("id"); session.setAttribute(userKey, userId); } return userId; }