Cookie cookie = new Cookie(host, headerelement.getName(), headerelement.getValue(),
Cookie cookie = null; try { cookie = new Cookie(host, headerelement.getName(), headerelement.getValue(),
org.apache.commons.httpclient.Cookie cookie = new org.apache.commons.httpclient.Cookie(); cookie.setDomain("localhost"); cookie.setPath("/"); cookie.setName("Tim"); cookie.setValue("Tim");
/** * add cookie to state * @param state * @param cookie */ private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) { int index = cookie.indexOf('='); state.addCookie(new Cookie(host, cookie.substring(0, index), cookie.substring(index + 1), path, null, secure)); }
/** * add cookie to state * @param state * @param cookie */ private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) { int index = cookie.indexOf('='); state.addCookie(new Cookie(host, cookie.substring(0, index), cookie.substring(index + 1), path, null, secure)); }
/** * add cookie to state * @param state * @param cookie */ private void addCookie(HttpState state, String cookie,String host, String path, boolean secure) { int index = cookie.indexOf('='); state.addCookie(new Cookie(host, cookie.substring(0, index), cookie.substring(index + 1), path, null, secure)); }
/** * Creates a cookie with the given name and value. * * @param name the cookie name * @param value the cookie value * @return CrawlerPack */ public CrawlerPack addCookie(String name, String value){ if( null == name ) { log.warn("addCookie: Cookie name null."); return this; } cookies.add( new Cookie("", name, value) ); return this; }
@Override @SuppressWarnings("unchecked") public Cookie[] asArrayOfCookies(Object cookiesObject) { Map<String, String> cookieMap = (Map<String, String>) cookiesObject; Cookie[] arrayOfCookies = new Cookie[cookieMap.size()]; int i = 0; for (Entry<String, String> cookieEntry : cookieMap.entrySet()) { Cookie cookie = new Cookie(); cookie.setName(cookieEntry.getKey()); cookie.setValue(cookieEntry.getValue()); arrayOfCookies[i++] = cookie; } return arrayOfCookies; }
/** * Manually add cookies */ public AbderaClient addCookie(String domain, String name, String value) { Cookie cookie = new Cookie(domain, name, value); client.getState().addCookie(cookie); return this; }
/** * Manually add cookies */ public AbderaClient addCookie(String domain, String name, String value, String path, Date expires, boolean secure) { Cookie cookie = new Cookie(domain, name, value, path, expires, secure); client.getState().addCookie(cookie); return this; }
/** * Manually add cookies */ public AbderaClient addCookie(String domain, String name, String value, String path, int maxAge, boolean secure) { Cookie cookie = new Cookie(domain, name, value, path, maxAge, secure); client.getState().addCookie(cookie); return this; }
@Override public Object putAndMergeCookie(Object preExistentCookies, String cookieName, String cookieValue) { final Cookie[] preExistentCookiesArray = (Cookie[]) preExistentCookies; final int sessionIndex = getCookieIndexFromCookiesArray(cookieName, preExistentCookiesArray); // domain, path, secure (https) and expiry are handled in method // CookieHelper.addCookiesToClient() final Cookie newSessionCookie = new Cookie(null, cookieName, cookieValue); final Cookie[] mergedCookiesArray; if (sessionIndex >= 0) { preExistentCookiesArray[sessionIndex] = newSessionCookie; mergedCookiesArray = preExistentCookiesArray; } else { Cookie[] newSessionCookieArray = new Cookie[]{newSessionCookie}; mergedCookiesArray = concatenateCookies(preExistentCookiesArray, newSessionCookieArray); } return mergedCookiesArray; }
@Override public Object putAndMergeCookie(Object preExistentCookies, Map<String, String> newCookiesMap) { if (newCookiesMap == null) { return putAndMergeCookie(preExistentCookies, (Cookie[]) null); } else { Cookie[] cookiesArray = new Cookie[newCookiesMap.size()]; int i = 0; for (Entry<String, String> cookieEntry : newCookiesMap.entrySet()) { Cookie cookie = new Cookie(); cookie.setName(cookieEntry.getKey()); cookie.setValue(cookieEntry.getValue()); cookiesArray[i++] = cookie; } return putAndMergeCookie(preExistentCookies, cookiesArray); } }
private org.apache.commons.httpclient.Cookie toHttpClientCookie(Cookie cookie) { org.apache.commons.httpclient.Cookie internal = new org.apache.commons.httpclient.Cookie(); internal.setName(cookie.getName()); internal.setValue(cookie.getValue()); internal.setComment(cookie.getComment()); internal.setDomain(cookie.getDomain()); // internal.setExpiryDate(toExpiry(cookie.getMaxAge())); internal.setPath(cookie.getPath()); internal.setVersion(cookie.getVersion()); return internal; }
/** @deprecated (0.14.0) Use {@link #getZestCookies()} instead. */ @Deprecated public List<Cookie> getCookies() { List<Cookie> cookies = new ArrayList<>(); for (ZestCookie cookie : this.cookies) { cookies.add( new Cookie( cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiryDate(), cookie.isSecure())); } return cookies; }
public MockBrowser(HttpClient httpClient) { _httpClient = httpClient; HttpConnectionManager connectionManager = httpClient.getHttpConnectionManager(); if (connectionManager instanceof MultiThreadedHttpConnectionManager) { _threadPool = Executors.newFixedThreadPool(10); } else { LOG.warn("The configured HttpClient does not use a MultiThreadedHttpConnectionManager, will only use 1 thread (instead of 10) for downloading CSS files and checking image URLs ..."); _threadPool = Executors.newFixedThreadPool(1); } HttpState httpState = new HttpState(); WebDriver driver = _webPage.getDriver(); for (org.openqa.selenium.Cookie cookie : driver.manage().getCookies()) { httpState.addCookie(new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure())); } _httpClient.setState(httpState); }
/** * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state * * @param seleniumCookieSet * @return */ private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) { HttpState mimicWebDriverCookieState = new HttpState(); for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) { Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(), seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(), seleniumCookie.isSecure()); mimicWebDriverCookieState.addCookie(httpClientCookie); } return mimicWebDriverCookieState; }
private Cookie convertCookie(HttpCookie cookie) { Cookie c = new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), (int) cookie.getMaxAge(), cookie.getSecure()); c.setVersion(cookie.getVersion()); c.setComment(cookie.getComment()); return c; }
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())); }
/** * Transforms a {@link ServerCookie} (from Apache Tomcat) into a {@link Cookie} * (from commons httpclient). Both types of Cookie hold the same data but the * {@link ServerCookie} is the type that you get when parsing cookies as a * Server. */ protected static Cookie transformServerCookieToClientCookie(ServerCookie serverCookie) { Cookie clientCookie = new Cookie(serverCookie.getDomain().toString(), serverCookie.getName() .toString(), serverCookie.getValue().toString(), serverCookie.getPath().toString(), serverCookie.getMaxAge(), serverCookie.getSecure()); clientCookie.setComment(serverCookie.getComment().toString()); clientCookie.setVersion(serverCookie.getVersion()); return clientCookie; }