private static com.gargoylesoftware.htmlunit.util.Cookie createCookie(javax.servlet.http.Cookie cookie) { Date expires = null; if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); }
cookie.setDomain(tokens[0]); cookie.setExpiryDate(expirationDate); cookie.setSecure(Boolean.valueOf(tokens[3]).booleanValue()); cookie.setPath(tokens[2]);
private BasicClientCookie duplicateCookie(Cookie seleniumCookie) { BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue()); duplicateCookie.setDomain(seleniumCookie.getDomain()); duplicateCookie.setAttribute(BasicClientCookie.DOMAIN_ATTR, seleniumCookie.getDomain()); duplicateCookie.setSecure(seleniumCookie.isSecure()); duplicateCookie.setExpiryDate(seleniumCookie.getExpiry()); duplicateCookie.setPath(seleniumCookie.getPath()); return duplicateCookie; } }
cookie.setSecure(true); } else { if (rawCookieParamNameAndValue.length != 2) {
BasicClientCookie cookie = new BasicClientCookie(name,value); // cookie.setVersion(1); cookie.setDomain(host); cookie.setPath("/"); cookie.setSecure(true); cookieJar.addCookie(cookie);
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String)in.readObject(); String value = (String)in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String)in.readObject()); clientCookie.setDomain((String)in.readObject()); clientCookie.setExpiryDate((Date)in.readObject()); clientCookie.setPath((String)in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); } }
CookieSyncManager.getInstance().sync(); String cookie = CookieManager.getInstance().getCookie(DOMAIN_NAME+COOKIE_PATH); BasicCookieStore cookieJar = new BasicCookieStore(); if (!cookie.equals("")) { String[] cookies = cookie.split(";"); for (int i = 0; i < cookies.length; i++) { String[] nvp = cookies[i].split("="); BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]); c.setDomain(DOMAIN_NAME); c.setPath(COOKIE_PATH); c.setSecure(true); cookieJar.addCookie(c); } }
/** * Creates a new cookie with the specified name and value which applies to the specified domain, * the specified path, and expires after the specified amount of time. * @param domain the domain to which this cookie applies * @param name the cookie name * @param value the cookie name * @param path the path to which this cookie applies * @param maxAge the number of seconds for which this cookie is valid; <tt>-1</tt> indicates that the * cookie should never expire; other negative numbers are not allowed * @param secure whether or not this cookie is secure (i.e. HTTPS vs HTTP) */ public Cookie(final String domain, final String name, final String value, final String path, final int maxAge, final boolean secure) { final BasicClientCookie cookie = new BasicClientCookie(name, value != null ? value : ""); cookie.setDomain(domain); cookie.setPath(path); cookie.setSecure(secure); if (maxAge < -1) { throw new IllegalArgumentException("invalid max age: " + maxAge); } if (maxAge >= 0) { cookie.setExpiryDate(new Date(System.currentTimeMillis() + (maxAge * 1000))); } httpClientCookie_ = cookie; }
/** * Creates a new cookie with the specified name and value which applies to the specified domain, * the specified path, and expires after the specified amount of time. * @param domain the domain to which this cookie applies * @param name the cookie name * @param value the cookie name * @param path the path to which this cookie applies * @param maxAge the number of seconds for which this cookie is valid; <tt>-1</tt> indicates that the * cookie should never expire; other negative numbers are not allowed * @param secure whether or not this cookie is secure (i.e. HTTPS vs HTTP) */ public Cookie(final String domain, final String name, final String value, final String path, final int maxAge, final boolean secure) { final BasicClientCookie cookie = new BasicClientCookie(name, value != null ? value : ""); cookie.setDomain(domain); cookie.setPath(path); cookie.setSecure(secure); if (maxAge < -1) { throw new IllegalArgumentException("invalid max age: " + maxAge); } if (maxAge >= 0) { cookie.setExpiryDate(new Date(System.currentTimeMillis() + (maxAge * 1000))); } httpClientCookie_ = cookie; }
static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) { Date expires = null; if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); } }
private static com.gargoylesoftware.htmlunit.util.Cookie createCookie(javax.servlet.http.Cookie cookie) { Date expires = null; if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); }
org.apache.http.cookie.Cookie toApacheCookie() { BasicClientCookie cookie = new BasicClientCookie(name, value); cookie.setExpiryDate(expires); cookie.setPath(path); cookie.setDomain(domain); cookie.setSecure(secure); return cookie; }
private org.apache.http.cookie.Cookie convert(Cookie in) { BasicClientCookie out = new BasicClientCookie(in.getName(), in.getValue()); String domainStr = null; if (StringUtils.isEmpty(in.getDomain())) { String urlStr = context.item().engine.get().getLocation(); try { URL url = new URL(urlStr); domainStr = url.getHost(); } catch (MalformedURLException e) { Matcher matcher = domain.matcher(urlStr); if (matcher.matches()) { domainStr = matcher.group(1); } } } out.setDomain(domainStr == null ? in.getDomain() : domainStr); if (in.getExpiry() != null) { out.setExpiryDate(in.getExpiry()); } out.setPath(in.getPath()); out.setSecure(in.isSecure()); out.setValue(in.getValue()); out.setVersion(1); return out; }
private void addCookiesToStore(List<Cookie> cookies, CookieStore cookieStore, String domain) { for (Cookie cookie : cookies) { BasicClientCookie apacheCookie = new BasicClientCookie(cookie.name, cookie.value); apacheCookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true"); if (cookie.domain != null) { apacheCookie.setDomain(cookie.domain); } else { apacheCookie.setDomain(domain); } if (cookie.expiry != null) { apacheCookie.setExpiryDate(cookie.expiry); } if (cookie.path != null) { apacheCookie.setPath(cookie.path); } apacheCookie.setSecure(cookie.secure); cookieStore.addCookie(apacheCookie); } } }
/** * Builds a new Apache cookie from given cookie values * * @param cookie * @return apache http cookie * @throws NullArgumentException if argument cookie is null; */ public static org.apache.http.cookie.Cookie asApacheCookie(Cookie cookie) { if (cookie == null) { throw new NullArgumentException("cookie"); } BasicClientCookie apacheCookie = new BasicClientCookie(cookie.getName(), cookie.getValue()); apacheCookie.setDomain(cookie.getDomain()); apacheCookie.setExpiryDate(new Date(cookie.getExpiresAt())); apacheCookie.setPath(cookie.getPath()); apacheCookie.setSecure(cookie.isSecure()); return apacheCookie; }
/** * Add Cookie * * @param name cookie name * @param value cookie value * @param domain cookie domain * @param isSecure whether the cookie is secure or not * @param expirationDate cookie expiration date * @param path cookie path */ @PublicAtsApi public void addCookie( String name, String value, String domain, String path, Date expirationDate, boolean isSecure ) { BasicCookieStore cookieStore = (BasicCookieStore) httpContext.getAttribute(HttpClientContext.COOKIE_STORE); if (cookieStore == null) { cookieStore = new BasicCookieStore(); httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); } BasicClientCookie cookie = new BasicClientCookie(name, value); cookie.setDomain(domain); cookie.setPath(path); cookie.setExpiryDate(expirationDate); cookie.setSecure(isSecure); cookieStore.addCookie(cookie); }
/** * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state * * @param seleniumCookieSet Set<Cookie> */ private BasicCookieStore mimicCookieState(Set<Cookie> seleniumCookieSet) { BasicCookieStore copyOfWebDriverCookieStore = new BasicCookieStore(); for (Cookie seleniumCookie : seleniumCookieSet) { BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(), seleniumCookie.getValue()); duplicateCookie.setDomain(seleniumCookie.getDomain()); duplicateCookie.setSecure(seleniumCookie.isSecure()); duplicateCookie.setExpiryDate(seleniumCookie.getExpiry()); duplicateCookie.setPath(seleniumCookie.getPath()); copyOfWebDriverCookieStore.addCookie(duplicateCookie); } return copyOfWebDriverCookieStore; }
/** * Create an HttpClient cookie from a JMeter cookie */ private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) { long exp = jmc.getExpiresMillis(); BasicClientCookie ret = new BasicClientCookie(jmc.getName(), jmc.getValue()); ret.setDomain(jmc.getDomain()); ret.setPath(jmc.getPath()); ret.setExpiryDate(exp > 0 ? new Date(exp) : null); // use null for no expiry ret.setSecure(jmc.getSecure()); ret.setVersion(jmc.getVersion()); if(jmc.isDomainSpecified()) { ret.setAttribute(ClientCookie.DOMAIN_ATTR, jmc.getDomain()); } if(jmc.isPathSpecified()) { ret.setAttribute(ClientCookie.PATH_ATTR, jmc.getPath()); } return ret; }