@Test public void testBindCookies() throws Exception { final SoyMapData soyMapData = new SoyMapData(); final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final Enumeration e = mock(Enumeration.class); when(e.hasMoreElements()).thenReturn(false); when(request.getParameterNames()).thenReturn(e); when(request.getHeaderNames()).thenReturn(e); when(request.getCookies()).thenReturn(new Cookie[]{new Cookie("name1", "value1"), new Cookie("name2", "value2")}); cookieResolver.resolveData(request, response, null, soyMapData); Assert.assertEquals("should not be value1", "value1", soyMapData.get("_request.cookie.name1.value").stringValue()); Assert.assertEquals("should not be value2", "value2", soyMapData.get("_request.cookie.name2.value").stringValue()); Assert.assertEquals("should not be name1", "name1", soyMapData.get("_request.cookie.name1.name").stringValue()); Assert.assertEquals("should not be name2", "name2", soyMapData.get("_request.cookie.name2.name").stringValue()); }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (final Cookie cookie : request.getCookies()) { if (StringUtils.hasLength(cookie.getName())) { final String keyPrefix = prefix + cookie.getName(); root.put(keyPrefix + ".name", cookie.getName()); if (StringUtils.hasLength(cookie.getValue())) { root.put(keyPrefix + ".value", cookie.getValue()); } if (StringUtils.hasLength(cookie.getComment())) { root.put(keyPrefix + ".comment", cookie.getComment()); } if (StringUtils.hasLength(cookie.getDomain())) { root.put(keyPrefix + ".domain", cookie.getDomain()); } root.put(keyPrefix + ".maxAge", cookie.getMaxAge()); if (StringUtils.hasLength(cookie.getPath())) { root.put(keyPrefix + ".path", cookie.getPath()); } root.put(keyPrefix + ".version", cookie.getVersion()); root.put(keyPrefix + ".secure", cookie.getSecure()); } } }
CookieDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (final Cookie cookie : request.getCookies()) { if (StringUtils.hasLength(cookie.getName())) { final String keyPrefix = prefix + cookie.getName(); root.put(keyPrefix + ".name", cookie.getName()); if (StringUtils.hasLength(cookie.getValue())) { root.put(keyPrefix + ".value", cookie.getValue()); } if (StringUtils.hasLength(cookie.getComment())) { root.put(keyPrefix + ".comment", cookie.getComment()); } if (StringUtils.hasLength(cookie.getDomain())) { root.put(keyPrefix + ".domain", cookie.getDomain()); } root.put(keyPrefix + ".maxAge", cookie.getMaxAge()); if (StringUtils.hasLength(cookie.getPath())) { root.put(keyPrefix + ".path", cookie.getPath()); } root.put(keyPrefix + ".version", cookie.getVersion()); root.put(keyPrefix + ".secure", cookie.getSecure()); } } } }
CookieDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (final Cookie cookie : request.getCookies()) { if (StringUtils.hasLength(cookie.getName())) { final String keyPrefix = prefix + cookie.getName(); root.put(keyPrefix + ".name", cookie.getName()); if (StringUtils.hasLength(cookie.getValue())) { root.put(keyPrefix + ".value", cookie.getValue()); } if (StringUtils.hasLength(cookie.getComment())) { root.put(keyPrefix + ".comment", cookie.getComment()); } if (StringUtils.hasLength(cookie.getDomain())) { root.put(keyPrefix + ".domain", cookie.getDomain()); } root.put(keyPrefix + ".maxAge", cookie.getMaxAge()); if (StringUtils.hasLength(cookie.getPath())) { root.put(keyPrefix + ".path", cookie.getPath()); } root.put(keyPrefix + ".version", cookie.getVersion()); root.put(keyPrefix + ".secure", cookie.getSecure()); } } }  }
CookieDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (final Cookie cookie : request.getCookies()) { if (StringUtils.hasLength(cookie.getName())) { final String keyPrefix = prefix + cookie.getName(); root.put(keyPrefix + ".name", cookie.getName()); if (StringUtils.hasLength(cookie.getValue())) { root.put(keyPrefix + ".value", cookie.getValue()); } if (StringUtils.hasLength(cookie.getComment())) { root.put(keyPrefix + ".comment", cookie.getComment()); } if (StringUtils.hasLength(cookie.getDomain())) { root.put(keyPrefix + ".domain", cookie.getDomain()); } root.put(keyPrefix + ".maxAge", cookie.getMaxAge()); if (StringUtils.hasLength(cookie.getPath())) { root.put(keyPrefix + ".path", cookie.getPath()); } root.put(keyPrefix + ".version", cookie.getVersion()); root.put(keyPrefix + ".secure", cookie.getSecure()); } } }  @Override void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root); String getPrefix(); void setPrefix(String prefix); }
CookieDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (final Cookie cookie : request.getCookies()) { if (StringUtils.hasLength(cookie.getName())) { final String keyPrefix = prefix + cookie.getName(); root.put(keyPrefix + ".name", cookie.getName()); if (StringUtils.hasLength(cookie.getValue())) { root.put(keyPrefix + ".value", cookie.getValue()); } if (StringUtils.hasLength(cookie.getComment())) { root.put(keyPrefix + ".comment", cookie.getComment()); } if (StringUtils.hasLength(cookie.getDomain())) { root.put(keyPrefix + ".domain", cookie.getDomain()); } root.put(keyPrefix + ".maxAge", cookie.getMaxAge()); if (StringUtils.hasLength(cookie.getPath())) { root.put(keyPrefix + ".path", cookie.getPath()); } root.put(keyPrefix + ".version", cookie.getVersion()); root.put(keyPrefix + ".secure", cookie.getSecure()); } } }  @Override void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root); String getPrefix(); void setPrefix(String prefix);  }