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

        String action = request.getParameter("action");
        String callback = request.getParameter("callback");

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

        if (action.equals("discoFeed")) {
            response.setContentType("application/javascript");
            JSONArray json;
            json = getMetadataJson();
            String sourceUrl = request.getParameter("source");
            if (sourceUrl != null) {
                json = getDiscoFeed(sourceUrl);
            }
            String jsonStr = "";
            try {
                jsonStr = getExtendedFeed(json, request).toString(2);
            } catch (JSONException ex) {
                LOG.log(Level.INFO, null, ex);
            }
            String jsonp = callback + "(" + jsonStr + ")";
            response.getWriter().write(jsonp);
        }

        if (action.equals("setCookie")) {
            response.setContentType("application/javascript");
            String value = request.getParameter("entityID");
            String maxAgeStr = request.getParameter("maxAge");
            int maxAge;
            try {
                maxAge = Integer.decode(maxAgeStr) * (60 * 60 * 24);
            } catch (Exception ex) {
                maxAge = -1;
            }
            Cookie cookie = getCookie(request.getCookies(), "lastIdp", response);
            cookie.setValue(value);
            cookie.setPath("/");
            cookie.setMaxAge(maxAge);
            response.addCookie(cookie);
            String jsonp = callback + "({\"entityID\": \"" + value + "\"})";
            response.getWriter().write(jsonp);
        }

    }