private CookieManager getCookieManager() { return this.webClient.getCookieManager(); }
private void storeCookies(WebRequest webRequest, javax.servlet.http.Cookie[] cookies) { Date now = new Date(); CookieManager cookieManager = this.webClient.getCookieManager(); for (javax.servlet.http.Cookie cookie : cookies) { if (cookie.getDomain() == null) { cookie.setDomain(webRequest.getUrl().getHost()); } Cookie toManage = createCookie(cookie); Date expires = toManage.getExpires(); if (expires == null || expires.after(now)) { cookieManager.addCookie(toManage); } else { cookieManager.removeCookie(toManage); } } }
@After public void tearDown() { webClient.getCookieManager().clearCookies(); webClient.close(); }
private void assertSingleSessionCookie(String expected) { com.gargoylesoftware.htmlunit.util.Cookie jsessionidCookie = webClient.getCookieManager().getCookie("JSESSIONID"); if (expected == null || expected.contains("Expires=Thu, 01-Jan-1970 00:00:01 GMT")) { assertThat(jsessionidCookie, nullValue()); return; } String actual = jsessionidCookie.getValue(); assertThat("JSESSIONID=" + actual + "; Path=/test; Domain=example.com", equalTo(expected)); }
@Test // SPR-14066 public void cookieManagerShared() throws Exception { this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build(); WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build(); assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA")); client.getCookieManager().addCookie(new Cookie("localhost", "cookie", "cookieManagerShared")); assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("cookieManagerShared")); }
@Test // SPR-14066 public void cookieManagerShared() throws Exception { WebConnectionHtmlUnitDriver otherDriver = new WebConnectionHtmlUnitDriver(); this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build(); this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc) .withDelegate(otherDriver).build(); assertThat(get("http://localhost/"), equalTo("")); Cookie cookie = new Cookie("localhost", "cookie", "cookieManagerShared"); otherDriver.getWebClient().getCookieManager().addCookie(cookie); assertThat(get("http://localhost/"), equalTo("cookieManagerShared")); }
public void deleteCookieNamed(String name) { CookieManager cookieManager = webClient.getCookieManager(); Set<org.apache.commons.httpclient.Cookie> rawCookies = webClient.getCookieManager().getCookies(getHostName()); for (org.apache.commons.httpclient.Cookie cookie : rawCookies) { if (name.equals(cookie.getName())) { cookieManager.removeCookie(cookie); } } }
public void print(HtmlPage page) { System.out.println("\n\n\n RAW REQUEST BODY \n" + getRawRequestBody()); System.out.println("\n\n\n RAW RESPONSE \n" + getRawResponse()); System.out.println("Response Headers: " + page.getWebResponse().getResponseHeaders()); System.out.println("\n\n\n ********************************* \n" + page.asXml()); System.out.println("\n\n\n **************************** \n" + webClient.getCookieManager().getCookies()); System.out.println("\n\n\n *********************************"); }
@After public void tearDown() { webClient.getCookieManager().clearCookies(); webClient.close(); }
WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setUseInsecureSSL(true); webClient.getOptions().setThrowExceptionOnFailingStatusCode(false); webClient.getCookieManager().setCookiesEnabled(true); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getCookieManager().setCookiesEnabled(true);
@Override public void deleteCookieNamed(String name) { CookieManager cookieManager = getWebClient().getCookieManager(); URL url = getRawUrl(); Set<com.gargoylesoftware.htmlunit.util.Cookie> rawCookies = getWebClient().getCookies(url); for (com.gargoylesoftware.htmlunit.util.Cookie cookie : rawCookies) { if (name.equals(cookie.getName())) { cookieManager.removeCookie(cookie); } } }
@Override public void deleteAllCookies() { CookieManager cookieManager = getWebClient().getCookieManager(); URL url = getRawUrl(); Set<com.gargoylesoftware.htmlunit.util.Cookie> rawCookies = getWebClient().getCookies(url); for (com.gargoylesoftware.htmlunit.util.Cookie cookie : rawCookies) { cookieManager.removeCookie(cookie); } }
/** * Returns the property "cookieEnabled". * @return the property "cookieEnabled" */ public boolean jsxGet_cookieEnabled() { return getWindow().getWebWindow().getWebClient().getCookieManager().isCookiesEnabled(); }
/** * Returns the property "cookieEnabled". * @return the property "cookieEnabled" */ public boolean jsxGet_cookieEnabled() { return getWindow().getWebWindow().getWebClient().getCookieManager().isCookiesEnabled(); }
/** * Returns the property "cookieEnabled". * @return the property "cookieEnabled" */ public boolean jsxGet_cookieEnabled() { return getWindow().getWebWindow().getWebClient().getCookieManager().isCookiesEnabled(); }
/** * Returns the {@code cookieEnabled} property. * @return the {@code cookieEnabled} property */ @JsxGetter public boolean isCookieEnabled() { return getWindow().getWebWindow().getWebClient().getCookieManager().isCookiesEnabled(); }
/** * Returns the {@code cookieEnabled} property. * @return the {@code cookieEnabled} property */ @JsxGetter public boolean isCookieEnabled() { return getWindow().getWebWindow().getWebClient().getCookieManager().isCookiesEnabled(); }
public Set<Cookie> getCookies() { Set<org.apache.commons.httpclient.Cookie> rawCookies = webClient.getCookieManager().getCookies(getHostName()); Set<Cookie> retCookies = new HashSet<Cookie>(); for(org.apache.commons.httpclient.Cookie c : rawCookies) { if (c.getPath() != null && getPath().startsWith(c.getPath())) { retCookies.add(new ReturnedCookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.getExpiryDate(), c.getSecure())); } } return retCookies; }
@Override public String call() throws Exception { WebClient client = new WebClient(); client.setThrowExceptionOnFailingStatusCode(false); client.getCookieManager().addCookie(new Cookie(contextPath.getHost(), JSESSIONID, jsessionid)); Page page = client.getPage(contextPath + "introspect?mode=" + mode + "&cid=" + cid); if (!(page instanceof TextPage)) { return "" + page.getWebResponse().getStatusCode(); } TextPage textPage = (TextPage) page; return textPage.getContent(); }
public void addCookie(Cookie cookie) { Page page = lastPage(); if (!(page instanceof HtmlPage)) { throw new WebDriverException("You may not set cookies on a page that is not HTML"); } // Cookies only make sense if the page is String domain = getDomainForCookie(cookie); verifyDomain(cookie, domain); webClient.getCookieManager().addCookie(new org.apache.commons.httpclient.Cookie(domain, cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure())); }