protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String callback = request.getParameter("callback");
        List<String> entityIDs = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            String val = request.getParameter(getId(i));
            if (val != null) {
                entityIDs.add(val);
            }
        }
        String maxAgeStr = request.getParameter("maxAge");
        String last = request.getParameter("last");

        if (callback == null) {
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
            response.getWriter().write("");
            return;
        }

        // If no entity ID parameters - return current cookie values
        response.setContentType("application/javascript");
        if (entityIDs.isEmpty() && last == null) {
            String cookieResponse;
            try {
                cookieResponse = getResponseFromCookie(request).toString(2);
            } catch (JSONException ex) {
                LOG.log(Level.INFO, null, ex);
                cookieResponse = "";
            }
            String jsonp = callback + "(" + cookieResponse + ")";
            response.getWriter().write(jsonp);
            return;
        }

        // Else, set cookie
        int maxAge;
        try {
            maxAge = Integer.decode(maxAgeStr) * (60 * 60 * 24);
        } catch (Exception ex) {
            maxAge = -1;
        }
        String cookieResponse;
        try {
            cookieResponse = setCookie(request.getCookies(), response, last, entityIDs, maxAge).toString(2);
        } catch (JSONException ex) {
            LOG.log(Level.INFO, null, ex);
            cookieResponse = "";
        }
        String jsonp = callback + "(" + cookieResponse + ")";
        response.getWriter().write(jsonp);
    }