@Test public void testResolverHeaders() throws Exception { final SoyMapData soyMapData = new SoyMapData(); final Vector<String> names = new Vector<String>(); names.add("name1"); names.add("name2"); final Vector<String> values = new Vector<String>(); values.add("value1"); values.add("value2"); 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(names.elements()); when(request.getHeader("name1")).thenReturn(values.get(0)); when(request.getHeader("name2")).thenReturn(values.get(1)); when(request.getCookies()).thenReturn(new Cookie[]{}); requestHeadersResolver.resolveData(request, response, Maps.<String, Object>newHashMap(), soyMapData); Assert.assertEquals("should not be value1", "value1", soyMapData.get("_request.header.name1").stringValue()); Assert.assertEquals("should not be value2", "value2", soyMapData.get("_request.header.name2").stringValue()); }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = (String) e.nextElement(); final String requestHeader = request.getHeader(headerName); if (requestHeader != null) { root.put(prefix + headerName, requestHeader); } } }
RequestHeadersDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = (String) e.nextElement(); final String requestHeader = request.getHeader(headerName); if (requestHeader != null) { root.put(prefix + headerName, requestHeader); } } } }
RequestHeadersDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = (String) e.nextElement(); final String requestHeader = request.getHeader(headerName); if (requestHeader != null) { root.put(prefix + headerName, requestHeader); } } }  }
RequestHeadersDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = (String) e.nextElement(); final String requestHeader = request.getHeader(headerName); if (requestHeader != null) { root.put(prefix + headerName, requestHeader); } } }  @Override void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root); void setPrefix(String prefix); String getPrefix(); }
RequestHeadersDataResolver implements RuntimeDataResolver { @Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = (String) e.nextElement(); final String requestHeader = request.getHeader(headerName); if (requestHeader != null) { root.put(prefix + headerName, requestHeader); } } }  @Override void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root); void setPrefix(String prefix); String getPrefix();  }