@Test(expected = BeanValidationException.class) public void testReadCookie_Validation() { storage.readCookie(null); }
protected @NotNull Optional<Cookie> readCookie(@NotNull CookieName name) { try { RequestCycle requestCycle = RequestCycle.get(); if (requestCycle == null) { LOG.warn("RequestCycle is null - cannot read cookies"); return Optional.empty(); } WebRequest request = (WebRequest) requestCycle.getRequest(); List<Cookie> cookies = request.getCookies(); LOG.debug("Found cookies {} for {}", cookies, request); if (cookies == null || cookies.isEmpty()) { return Optional.empty(); } Optional<Cookie> result = cookies.stream().filter(cookie -> name.name().equals(cookie.getName())) .findFirst(); LOG.debug("Found cookie: {}", result); return result; } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", name, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }
CookieStorage { protected @NotNull Optional<Cookie> readCookie(@NotNull CookieName name) { try { RequestCycle requestCycle = RequestCycle.get(); if (requestCycle == null) { LOG.warn("RequestCycle is null - cannot read cookies"); return Optional.empty(); } WebRequest request = (WebRequest) requestCycle.getRequest(); List<Cookie> cookies = request.getCookies(); LOG.debug("Found cookies {} for {}", cookies, request); if (cookies == null || cookies.isEmpty()) { return Optional.empty(); } Optional<Cookie> result = cookies.stream().filter(cookie -> name.name().equals(cookie.getName())) .findFirst(); LOG.debug("Found cookie: {}", result); return result; } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", name, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } } }
CookieStorage { protected @NotNull Optional<Cookie> readCookie(@NotNull CookieName name) { try { RequestCycle requestCycle = RequestCycle.get(); if (requestCycle == null) { LOG.warn("RequestCycle is null - cannot read cookies"); return Optional.empty(); } WebRequest request = (WebRequest) requestCycle.getRequest(); List<Cookie> cookies = request.getCookies(); LOG.debug("Found cookies {} for {}", cookies, request); if (cookies == null || cookies.isEmpty()) { return Optional.empty(); } Optional<Cookie> result = cookies.stream().filter(cookie -> name.name().equals(cookie.getName())) .findFirst(); LOG.debug("Found cookie: {}", result); return result; } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", name, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }  }
CookieStorage { protected @NotNull Optional<Cookie> readCookie(@NotNull CookieName name) { try { RequestCycle requestCycle = RequestCycle.get(); if (requestCycle == null) { LOG.warn("RequestCycle is null - cannot read cookies"); return Optional.empty(); } WebRequest request = (WebRequest) requestCycle.getRequest(); List<Cookie> cookies = request.getCookies(); LOG.debug("Found cookies {} for {}", cookies, request); if (cookies == null || cookies.isEmpty()) { return Optional.empty(); } Optional<Cookie> result = cookies.stream().filter(cookie -> name.name().equals(cookie.getName())) .findFirst(); LOG.debug("Found cookie: {}", result); return result; } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", name, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }  void storeCookieAsJson(@NotNull CookieName cookieName, @NotNull Object obj); @Valid Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz); }
CookieStorage { protected @NotNull Optional<Cookie> readCookie(@NotNull CookieName name) { try { RequestCycle requestCycle = RequestCycle.get(); if (requestCycle == null) { LOG.warn("RequestCycle is null - cannot read cookies"); return Optional.empty(); } WebRequest request = (WebRequest) requestCycle.getRequest(); List<Cookie> cookies = request.getCookies(); LOG.debug("Found cookies {} for {}", cookies, request); if (cookies == null || cookies.isEmpty()) { return Optional.empty(); } Optional<Cookie> result = cookies.stream().filter(cookie -> name.name().equals(cookie.getName())) .findFirst(); LOG.debug("Found cookie: {}", result); return result; } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", name, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }  void storeCookieAsJson(@NotNull CookieName cookieName, @NotNull Object obj); @Valid Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz);  }