/** * Override superclass to ensure that MultiMap instances are * correctly handled. * <p> * If you call this method with a normal map, each entry is * added using <code>put(Object,Object)</code>. * If you call this method with a multi map, each entry is * added using <code>putAll(Object,Collection)</code>. * * @param map the map to copy (either a normal or multi map) */ @Override @SuppressWarnings("unchecked") public void putAll(final Map<? extends K, ?> map) { if (map instanceof MultiMap) { for (final Map.Entry<? extends K, Object> entry : ((MultiMap<? extends K, V>) map).entrySet()) { putAll(entry.getKey(), (Collection<V>) entry.getValue()); } } else { for (final Map.Entry<? extends K, ?> entry : map.entrySet()) { put(entry.getKey(), entry.getValue()); } } }
/** * In the parameters variable, adds the value to the collection associated with the specified key. * <p> * Unlike a normal <code>Map</code> the previous value is not replaced. * Instead the new value is added to the collection stored against the key. * * @param key the key to store against * @param value the value to add to the collection at the key */ public void addParameter(String key, Object value) { parameters.put(key, value); }
/** * In the parameters variable, adds the value to the collection associated with the specified key. * <p> * Unlike {@link #addParameter(String, Object)} the previous value is overridden. * First, any existing values are removed, then the new value is added to the collection at the specified key * * @param key the key to store against * @param value the value to add to the collection at the key */ protected void addSingletonParameter(String key, Object value) { parameters.remove(key); parameters.put(key, value); }
public void insert(String key, int nn, Object value) { this.map.put(key, nn); this.valuesMap.put(nn, new AttributeDescriptor(key, value)); //System.err.printf("Inserted: %s, %d, %s\n", key, nn, value); }
@Test public void testServesUnzippedContentAndRemovesGzipHeadersIfClientDoesNotAcceptGZipEncoding() throws Exception { final String dummyContent = "hello i'm a page that was cached"; final MultiValueMap headers = new MultiValueMap(); headers.put("Content-Encoding", "gzip"); headers.put("Vary", "Accept-Encoding"); headers.put("Dummy", "Some Value"); final InMemoryCachedEntry cachedPage = new InMemoryCachedEntry(dummyContent.getBytes(), "text/plain", "ASCII", 123, headers, System.currentTimeMillis(), originalURL, -1); when(cachePolicy.shouldCache(cache, aggregationState, flushPolicy)).thenReturn(new CachePolicyResult(CachePolicyResult.useCache, "/test-page", cachedPage)); when(request.getDateHeader("If-Modified-Since")).thenReturn(-1l); when(request.getHeader("User-Agent")).thenReturn("Mozilla/4.0 (MSIE 7.0; Windows NT 5.1)"); when(request.getHeaders("Accept-Encoding")).thenReturn(enumeration()); final ByteArrayOutputStream fakedOut = new ByteArrayOutputStream(); response.setStatus(123); when(response.containsHeader("Dummy")).thenReturn(false); response.addHeader("Dummy", "Some Value"); response.setContentType("text/plain"); response.setCharacterEncoding("ASCII"); response.setContentLength(dummyContent.length()); when(response.getOutputStream()).thenReturn(new SimpleServletOutputStream(fakedOut)); response.flushBuffer(); when(webContext.getResponse()).thenReturn(response); executeNoCacheFilterAndVerify(); assertEquals(dummyContent, fakedOut.toString()); }
@Ignore @Test public void testIgnoreEncodingAndServeContentFlatWhenUserAgentIsIE6() throws Exception { final String dummyContent = "hello i'm a page that was cached"; final MultiValueMap headers = new MultiValueMap(); headers.put("Last-Modified", 2000l); headers.put("Dummy", "dummy"); headers.put("Dummy", "dummy2"); final InMemoryCachedEntry cachedPage = new InMemoryCachedEntry(dummyContent.getBytes(), "text/plain", "ASCII", 123, headers, System.currentTimeMillis(), originalURL, -1); when(cachePolicy.shouldCache(cache, aggregationState, flushPolicy)).thenReturn(new CachePolicyResult(CachePolicyResult.useCache, "/test-page", cachedPage)); when(request.getDateHeader("If-Modified-Since")).thenReturn(-1l); when(request.getHeader("User-Agent")).thenReturn("Mozilla/4.0 (MSIE 6.0; Windows NT 5.1)"); final ByteArrayOutputStream fakedOut = new ByteArrayOutputStream(); response.setStatus(123); when(response.containsHeader("Last-Modified")).thenReturn(false); response.addDateHeader("Last-Modified", 2000l); when(response.containsHeader("Dummy")).thenReturn(false); response.addHeader("Dummy", "dummy"); response.addHeader("Dummy", "dummy2"); response.setContentType("text/plain"); response.setCharacterEncoding("ASCII"); response.setContentLength(32); when(response.getOutputStream()).thenReturn(new SimpleServletOutputStream(fakedOut)); response.flushBuffer(); when(webContext.getResponse()).thenReturn(response); when(request.getHeaders("Accept-Encoding")).thenReturn(enumeration("foo", "gzip", "bar")); when(response.containsHeader("Content-Encoding")).thenReturn(true); executeNoCacheFilterAndVerify(); assertTrue(Arrays.equals(dummyContent.getBytes(), fakedOut.toByteArray())); }
@Test public void testUnGZipIfContentIsGZipped() throws IOException { final String s = "hello"; final byte[] gzipped = GZipUtil.gzip(s.getBytes()); final MultiValueMap responseHeaders = new MultiValueMap(); responseHeaders.put("Content-Encoding", "gzip"); final InMemoryCachedEntry p = new InMemoryCachedEntry(gzipped, "text/plain", "cha", 1, responseHeaders, System.currentTimeMillis(), "originalUrl", -1); assertEquals(gzipped, p.getGzippedContent()); assertEquals("hello", new String(p.getPlainContent())); }