private static RequestScoper continueRequest(Map<Key<?>, Object> seedMap) { Preconditions.checkArgument( null != seedMap, "Seed map cannot be null, try passing in Collections.emptyMap() instead."); // Snapshot the seed map and add all the instances to our continuing HTTP request. final ContinuingHttpServletRequest continuingRequest = new ContinuingHttpServletRequest(GuiceFilter.getRequest(Key.get(HttpServletRequest.class))); for (Map.Entry<Key<?>, Object> entry : seedMap.entrySet()) { Object value = validateAndCanonicalizeValue(entry.getKey(), entry.getValue()); continuingRequest.setAttribute(entry.getKey().toString(), value); } return new RequestScoper() { @Override public CloseableScope open() { checkScopingState( null == GuiceFilter.localContext.get(), "Cannot continue request in the same thread as a HTTP request!"); return new GuiceFilter.Context(continuingRequest, continuingRequest, null).open(); } }; }
public void testReturnNullCookiesIfDelegateHasNoNull() { HttpServletRequest delegate = createMock(HttpServletRequest.class); expect(delegate.getCookies()).andStubReturn(null); replay(delegate); assertNull(new ContinuingHttpServletRequest(delegate).getCookies()); verify(delegate); }
private static RequestScoper continueRequest(Map<Key<?>, Object> seedMap) { Preconditions.checkArgument( null != seedMap, "Seed map cannot be null, try passing in Collections.emptyMap() instead."); // Snapshot the seed map and add all the instances to our continuing HTTP request. final ContinuingHttpServletRequest continuingRequest = new ContinuingHttpServletRequest(GuiceFilter.getRequest(Key.get(HttpServletRequest.class))); for (Map.Entry<Key<?>, Object> entry : seedMap.entrySet()) { Object value = validateAndCanonicalizeValue(entry.getKey(), entry.getValue()); continuingRequest.setAttribute(entry.getKey().toString(), value); } return new RequestScoper() { @Override public CloseableScope open() { checkScopingState( null == GuiceFilter.localContext.get(), "Cannot continue request in the same thread as a HTTP request!"); return new GuiceFilter.Context(continuingRequest, continuingRequest, null).open(); } }; }
public void testReturnDelegateCookies() { Cookie[] cookies = new Cookie[] {new Cookie("testName1", TEST_VALUE_1), new Cookie("testName2", "testValue2")}; HttpServletRequest delegate = createMock(HttpServletRequest.class); expect(delegate.getCookies()).andStubReturn(cookies); replay(delegate); ContinuingHttpServletRequest continuingRequest = new ContinuingHttpServletRequest(delegate); assertCookieArraysEqual(cookies, continuingRequest.getCookies()); // Now mutate the original cookies, this shouldnt be reflected in the continued request. cookies[0].setValue("INVALID"); cookies[1].setValue("INVALID"); cookies[1].setMaxAge(123); try { assertCookieArraysEqual(cookies, continuingRequest.getCookies()); throw new Error(); } catch (AssertionFailedError e) { // Expected. } // Verify that they remain equal to the original values. assertEquals(TEST_VALUE_1, continuingRequest.getCookies()[0].getValue()); assertEquals(TEST_VALUE_2, continuingRequest.getCookies()[1].getValue()); assertEquals(DEFAULT_MAX_AGE, continuingRequest.getCookies()[1].getMaxAge()); // Perform a snapshot of the snapshot. ContinuingHttpServletRequest furtherContinuingRequest = new ContinuingHttpServletRequest(continuingRequest); // The cookies should be fixed. assertCookieArraysEqual(continuingRequest.getCookies(), furtherContinuingRequest.getCookies()); verify(delegate); }
private static RequestScoper continueRequest(Map<Key<?>, Object> seedMap) { Preconditions.checkArgument( null != seedMap, "Seed map cannot be null, try passing in Collections.emptyMap() instead."); // Snapshot the seed map and add all the instances to our continuing HTTP request. final ContinuingHttpServletRequest continuingRequest = new ContinuingHttpServletRequest(GuiceFilter.getRequest(Key.get(HttpServletRequest.class))); for (Map.Entry<Key<?>, Object> entry : seedMap.entrySet()) { Object value = validateAndCanonicalizeValue(entry.getKey(), entry.getValue()); continuingRequest.setAttribute(entry.getKey().toString(), value); } return new RequestScoper() { @Override public CloseableScope open() { checkScopingState( null == GuiceFilter.localContext.get(), "Cannot continue request in the same thread as a HTTP request!"); return new GuiceFilter.Context(continuingRequest, continuingRequest, null).open(); } }; }
new ContinuingHttpServletRequest(GuiceFilter.getRequest()); for (Map.Entry<Key<?>, Object> entry : seedMap.entrySet()) { Object value = validateAndCanonicalizeValue(entry.getKey(), entry.getValue()); continuingRequest.setAttribute(entry.getKey().toString(), value);
new ContinuingHttpServletRequest(GuiceFilter.getRequest()); for (Map.Entry<Key<?>, Object> entry : seedMap.entrySet()) { Object value = validateAndCanonicalizeValue(entry.getKey(), entry.getValue()); continuingRequest.setAttribute(entry.getKey().toString(), value);