import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; public class InputUtils { public static String getCognitoIDFromBody(Map inputMap) { System.out.println(inputMap.keySet()); System.out.println(inputMap.entrySet()); Map contextMap; if ((inputMap.get("context") != null) && (inputMap.get("context") instanceof Map)) { contextMap = ((Map) inputMap.get("context")); } else { throw new IllegalArgumentException("The key \"context\" must exist and be a map"); } System.out.println(inputMap.get("context")); System.out.println(contextMap.get("sub")); return contextMap.get("sub").toString(); } public static Map getBody(Map inputMap) { return getMap(inputMap, "body"); } private static String getQueryString(Map inputMap) { return (String) (getMap(inputMap, "params").get("querystring")); } public static HashMap getQueryParams(Map inputMap) { return (HashMap) (getMap(inputMap, "params").get("querystring")); // String queryString = getQueryString(inputMap); // List queryparams = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8); // HashMap mappedParams = new HashMap<>(); // for (NameValuePair param : queryparams) { // mappedParams.put(param.getName(), param.getValue()); // } // return mappedParams; } public static Map getMap(Map parentMap, String childKey) { if ((parentMap.get(childKey) != null) && (parentMap.get(childKey) instanceof Map)) { return ((Map) parentMap.get(childKey)); } throw new IllegalArgumentException("The key \"" + childKey + "\" must exist and be a map"); } }