List of usage examples for org.apache.http.cookie ClientCookie DOMAIN_ATTR
String DOMAIN_ATTR
To view the source code for org.apache.http.cookie ClientCookie DOMAIN_ATTR.
Click Source Link
From source file:com.github.tmyroadctfig.icloud4j.json.SerializableClientCookie.java
public SerializableClientCookie(Cookie cookie) { this.name = cookie.getName(); this.value = cookie.getValue(); this.cookieComment = cookie.getComment(); this.cookieDomain = cookie.getDomain(); this.cookieExpiryDate = cookie.getExpiryDate() != null ? cookie.getExpiryDate().getTime() : null; this.cookiePath = cookie.getPath(); this.isSecure = cookie.isSecure(); this.cookieVersion = cookie.getVersion(); if (cookie instanceof ClientCookie) { ClientCookie c = (ClientCookie) cookie; copyAttribute(ClientCookie.COMMENT_ATTR, c); copyAttribute(ClientCookie.COMMENTURL_ATTR, c); copyAttribute(ClientCookie.DISCARD_ATTR, c); copyAttribute(ClientCookie.DOMAIN_ATTR, c); copyAttribute(ClientCookie.EXPIRES_ATTR, c); copyAttribute(ClientCookie.MAX_AGE_ATTR, c); copyAttribute(ClientCookie.PATH_ATTR, c); copyAttribute(ClientCookie.PORT_ATTR, c); copyAttribute(ClientCookie.SECURE_ATTR, c); copyAttribute(ClientCookie.DOMAIN_ATTR, c); }/* w w w .j av a 2s . c o m*/ }
From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.SiteMinderAuthenticator.java
/** * @return the list of SiteMinder cookies that have to be added to the HTTP request in order to authenticate it. *//*from w w w. java 2 s .com*/ private List<Cookie> getSiteMinderCookies() { javax.servlet.http.Cookie[] receivedCookies = ((ServletRequest) container.getRequest()) .getHttpServletRequest().getCookies(); List<Cookie> cookies = new ArrayList<Cookie>(); // Look for the SMSESSION cookie. for (int i = 0; i < receivedCookies.length; i++) { javax.servlet.http.Cookie receivedCookie = receivedCookies[i]; if (SITE_MINDER_COOKIES.contains(receivedCookie.getName())) { BasicClientCookie cookie = new BasicClientCookie(receivedCookie.getName(), receivedCookie.getValue()); cookie.setVersion(receivedCookie.getVersion()); cookie.setDomain(receivedCookie.getDomain()); cookie.setPath(receivedCookie.getPath()); cookie.setSecure(receivedCookie.getSecure()); // Set attributes EXACTLY as sent by the browser. cookie.setAttribute(ClientCookie.VERSION_ATTR, String.valueOf(receivedCookie.getVersion())); cookie.setAttribute(ClientCookie.DOMAIN_ATTR, receivedCookie.getDomain()); cookies.add(cookie); } } return cookies; }
From source file:com.jaeksoft.searchlib.crawler.web.database.CookieItem.java
public BasicClientCookie getCookie() throws MalformedURLException, URISyntaxException { if (basicClientCookie != null) return basicClientCookie; basicClientCookie = new BasicClientCookie(name, value); basicClientCookie.setVersion(1);/*from w ww. j a v a 2 s . c o m*/ String domain_attr = StringUtils.fastConcat(".", InternetDomainName.from(extractUrl().getHost()).name()); basicClientCookie.setDomain(domain_attr); basicClientCookie.setPath("/"); basicClientCookie.setSecure(true); basicClientCookie.setAttribute(ClientCookie.VERSION_ATTR, "1"); basicClientCookie.setAttribute(ClientCookie.DOMAIN_ATTR, domain_attr); return basicClientCookie; }
From source file:org.apache.jmeter.protocol.http.control.TestHC4CookieManager.java
/** * @throws Exception//from w ww . j a v a 2 s.co m */ @Test public void testAddCookieFromHeaderWithWildcard() throws Exception { URL url = new URL("https://subdomain.bt.com/page"); String headerLine = "SMTRYNO=1; path=/; domain=.bt.com"; man.addCookieFromHeader(headerLine, url); Assert.assertEquals(1, man.getCookieCount()); HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler(); List<org.apache.http.cookie.Cookie> cookies = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES); for (org.apache.http.cookie.Cookie cookie : cookies) { // See http://tools.ietf.org/html/rfc6265#section-5.2.3 Assert.assertEquals("bt.com", cookie.getDomain()); Assert.assertTrue(((BasicClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)); } // we check that CookieManager returns the cookies for the main domain URL urlMainDomain = new URL("https://www.bt.com/page"); cookies = cookieHandler.getCookiesForUrl(man.getCookies(), urlMainDomain, CookieManager.ALLOW_VARIABLE_COOKIES); Assert.assertEquals(1, cookies.size()); for (org.apache.http.cookie.Cookie cookie : cookies) { // See http://tools.ietf.org/html/rfc6265#section-5.2.3 Assert.assertEquals("bt.com", cookie.getDomain()); Assert.assertTrue(((BasicClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)); } }
From source file:org.apache.jmeter.protocol.http.control.HC4CookieHandler.java
@Override public void addCookieFromHeader(CookieManager cookieManager, boolean checkCookies, String cookieHeader, URL url) {/*from www .j a va 2 s .co m*/ boolean debugEnabled = log.isDebugEnabled(); if (debugEnabled) { log.debug("Received Cookie: " + cookieHeader + " From: " + url.toExternalForm()); } String protocol = url.getProtocol(); String host = url.getHost(); int port = HTTPSamplerBase.getDefaultPort(protocol, url.getPort()); String path = url.getPath(); boolean isSecure = HTTPSamplerBase.isSecure(protocol); List<org.apache.http.cookie.Cookie> cookies = null; CookieOrigin cookieOrigin = new CookieOrigin(host, port, path, isSecure); BasicHeader basicHeader = new BasicHeader(HTTPConstants.HEADER_SET_COOKIE, cookieHeader); try { cookies = cookieSpec.parse(basicHeader, cookieOrigin); } catch (MalformedCookieException e) { log.error("Unable to add the cookie", e); } if (cookies == null) { return; } for (org.apache.http.cookie.Cookie cookie : cookies) { try { if (checkCookies) { cookieSpec.validate(cookie, cookieOrigin); } Date expiryDate = cookie.getExpiryDate(); long exp = 0; if (expiryDate != null) { exp = expiryDate.getTime(); } Cookie newCookie = new Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.isSecure(), exp / 1000, ((BasicClientCookie) cookie).containsAttribute(ClientCookie.PATH_ATTR), ((BasicClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR), cookie.getVersion()); // Store session cookies as well as unexpired ones if (exp == 0 || exp >= System.currentTimeMillis()) { cookieManager.add(newCookie); // Has its own debug log; removes matching cookies } else { cookieManager.removeMatchingCookies(newCookie); if (debugEnabled) { log.info("Dropping expired Cookie: " + newCookie.toString()); } } } catch (MalformedCookieException e) { // This means the cookie was wrong for the URL log.warn("Not storing invalid cookie: <" + cookieHeader + "> for URL " + url + " (" + e.getLocalizedMessage() + ")"); } catch (IllegalArgumentException e) { log.warn(cookieHeader + e.getLocalizedMessage()); } } }
From source file:org.apache.jmeter.protocol.http.control.TestHC4CookieManager.java
/** * @throws Exception/*from w w w . j a v a 2s . c o m*/ */ @Test public void testAddCookieFromHeaderWithNoWildcard() throws Exception { URL url = new URL("https://subdomain.bt.com/page"); String headerLine = "SMTRYNO=1; path=/"; man.addCookieFromHeader(headerLine, url); Assert.assertEquals(1, man.getCookieCount()); HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler(); List<org.apache.http.cookie.Cookie> cookies = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES); Assert.assertEquals(1, cookies.size()); for (org.apache.http.cookie.Cookie cookie : cookies) { // See http://tools.ietf.org/html/rfc6265#section-5.2.3 Assert.assertEquals("subdomain.bt.com", cookie.getDomain()); Assert.assertFalse(((BasicClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)); } // we check that CookieManager returns the cookies for the main domain URL urlMainDomain = new URL("https://www.bt.com/page"); cookies = cookieHandler.getCookiesForUrl(man.getCookies(), urlMainDomain, CookieManager.ALLOW_VARIABLE_COOKIES); Assert.assertEquals(0, cookies.size()); }
From source file:org.esxx.js.protocol.CookieJar.java
private Scriptable cookieToScriptable(Context cx, Cookie cookie) { Scriptable js = cx.newObject(jsuri); Scriptable raw = cx.newObject(js);/*from ww w. jav a2s . co m*/ js.put("raw", js, raw); setValue(cx, cookie, js, raw, "name", cookie.getName()); setValue(cx, cookie, js, raw, "value", cookie.getValue()); setValue(cx, cookie, js, raw, ClientCookie.COMMENT_ATTR, cookie.getComment()); setValue(cx, cookie, js, raw, ClientCookie.COMMENTURL_ATTR, cookie.getCommentURL()); setValue(cx, cookie, js, raw, ClientCookie.DISCARD_ATTR, null); setValue(cx, cookie, js, raw, ClientCookie.DOMAIN_ATTR, cookie.getDomain()); setValue(cx, cookie, js, raw, ClientCookie.EXPIRES_ATTR, cookie.getExpiryDate()); setValue(cx, cookie, js, raw, ClientCookie.MAX_AGE_ATTR, null); setValue(cx, cookie, js, raw, ClientCookie.PATH_ATTR, cookie.getPath()); setValue(cx, cookie, js, raw, ClientCookie.PORT_ATTR, cookie.getPorts()); setValue(cx, cookie, js, raw, ClientCookie.SECURE_ATTR, cookie.isSecure()); setValue(cx, cookie, js, raw, ClientCookie.VERSION_ATTR, cookie.getVersion()); return js; }
From source file:org.apache.jmeter.protocol.http.control.TestHC4CookieManager.java
/** * @throws Exception//from w w w .java2 s . c o m */ @Test public void testAddCookieFromHeaderWithWildcard2() throws Exception { URL url = new URL("https://www.bt.com/page"); String headerLine = "SMTRYNO=1; path=/; domain=.bt.com"; man.addCookieFromHeader(headerLine, url); Assert.assertEquals(1, man.getCookieCount()); HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler(); URL urlSubDomain = new URL("https://subdomain.bt.com/page"); List<org.apache.http.cookie.Cookie> cookies = cookieHandler.getCookiesForUrl(man.getCookies(), urlSubDomain, CookieManager.ALLOW_VARIABLE_COOKIES); Assert.assertEquals(1, cookies.size()); for (org.apache.http.cookie.Cookie cookie : cookies) { // See http://tools.ietf.org/html/rfc6265#section-5.2.3 Assert.assertEquals("bt.com", cookie.getDomain()); Assert.assertTrue(((BasicClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)); } }
From source file:org.esxx.js.protocol.CookieJar.java
private Cookie scriptableToCookie(Context cx, Scriptable js) { String name = Context.toString(js.get("name", js)); String value = Context.toString(js.get("value", js)); Object raw = js.get("raw", js); BasicClientCookie cookie;//from w w w . ja v a 2 s. c om if (js.has(ClientCookie.COMMENTURL_ATTR, js) || js.has(ClientCookie.DISCARD_ATTR, js) || js.has(ClientCookie.PORT_ATTR, js)) { BasicClientCookie2 cookie2 = new BasicClientCookie2(name, value); cookie2.setCommentURL(stringValue(cx, js, raw, cookie2, ClientCookie.COMMENTURL_ATTR)); cookie2.setDiscard(booleanValue(cx, js, raw, cookie2, ClientCookie.DISCARD_ATTR)); cookie2.setPorts(intArrayValue(cx, js, raw, cookie2, ClientCookie.PORT_ATTR)); cookie = cookie2; } else { cookie = new BasicClientCookie(name, value); } cookie.setComment(stringValue(cx, js, raw, cookie, ClientCookie.COMMENT_ATTR)); cookie.setDomain(stringValue(cx, js, raw, cookie, ClientCookie.DOMAIN_ATTR)); cookie.setExpiryDate(dateValue(cx, js, raw, cookie, ClientCookie.EXPIRES_ATTR)); cookie.setPath(stringValue(cx, js, raw, cookie, ClientCookie.PATH_ATTR)); cookie.setSecure(booleanValue(cx, js, raw, cookie, ClientCookie.SECURE_ATTR)); cookie.setVersion(intValue(cx, js, raw, cookie, ClientCookie.VERSION_ATTR)); setRawValue(raw, cookie, ClientCookie.MAX_AGE_ATTR); return cookie; }
From source file:org.apache.jmeter.protocol.http.control.HC4CookieHandler.java
/** * Create an HttpClient cookie from a JMeter cookie *//*from w w w. j a va2s .co m*/ 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; }