public String get(final Request request, final String key) { String result = null; String prefString = cookieUtils.load(PREFMAN_KEY); if (prefString != null) { final Map<String, String> prefs = getPrefs(new String(Base64.decodeBase64(prefString.getBytes()))); result = prefs.get(key); } return result; }
public void set( final Request request, final Response response, final String key, final String value) { String prefString = cookieUtils.load(PREFMAN_KEY); final Map<String, String> current = new HashMap<>(); if (prefString != null) { current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes())))); } // after retrieved previous setting in order to overwrite the key ... current.put(key, value); try { cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes()))); } catch (IOException e) { LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e); } }
public void set( final Request request, final Response response, final Map<String, List<String>> prefs) { Map<String, String> current = new HashMap<>(); String prefString = cookieUtils.load(PREFMAN_KEY); if (prefString != null) { current.putAll(getPrefs(new String(Base64.decodeBase64(prefString.getBytes())))); } // after retrieved previous setting in order to overwrite the key ... for (Map.Entry<String, List<String>> entry : prefs.entrySet()) { current.put(entry.getKey(), StringUtils.join(entry.getValue(), ";")); } try { cookieUtils.save(PREFMAN_KEY, new String(Base64.encodeBase64(setPrefs(current).getBytes()))); } catch (IOException e) { LOG.error("Could not save {} info: {}", getClass().getSimpleName(), current, e); } }