List of usage examples for org.apache.http.cookie ClientCookie PATH_ATTR
String PATH_ATTR
To view the source code for org.apache.http.cookie ClientCookie PATH_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); }//from w w w.j a va 2 s. com }
From source file:org.apache.jmeter.protocol.http.control.HC4CookieHandler.java
@Override public void addCookieFromHeader(CookieManager cookieManager, boolean checkCookies, String cookieHeader, URL url) {//from ww w. j a v a 2 s .c o 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.esxx.js.protocol.CookieJar.java
private Scriptable cookieToScriptable(Context cx, Cookie cookie) { Scriptable js = cx.newObject(jsuri); Scriptable raw = cx.newObject(js);/*from w ww .j a v a 2 s .c o 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.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 . j a v a 2s . c o m*/ 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 ww w. j a v a 2s .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; }
From source file:org.apache.jmeter.protocol.http.control.TestHC4CookieManager.java
@Test public void testCookieOrdering2() throws Exception { URL url = new URL("http://order.now/sub1/moo.html"); man.addCookieFromHeader("test1=moo1;", url); man.addCookieFromHeader("test2=moo2;path=/sub1", url); man.addCookieFromHeader("test2=moo3;path=/", url); assertEquals(3, man.getCookieCount()); assertEquals("/sub1", man.get(0).getPath()); // Defaults to caller URL assertEquals("/sub1", man.get(1).getPath()); assertEquals("/", man.get(2).getPath()); String s = man.getCookieHeaderForURL(url); assertNotNull(s);/*from w w w . ja v a 2 s .c o m*/ HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler(); List<org.apache.http.cookie.Cookie> c = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES); assertEquals("/sub1", c.get(0).getPath()); assertFalse(((BasicClientCookie) c.get(0)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("/sub1", c.get(1).getPath()); assertTrue(((BasicClientCookie) c.get(1)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("/", c.get(2).getPath()); assertEquals("test1=moo1; test2=moo2; test2=moo3", s); }
From source file:org.apache.jmeter.protocol.http.control.TestHC4CookieManager.java
@Test public void testCookiePolicy2109() throws Exception { man.setCookiePolicy(org.apache.http.client.params.CookiePolicy.RFC_2109); man.testStarted(); // ensure policy is picked up URL url = new URL("http://order.now/sub1/moo.html"); man.addCookieFromHeader("test1=moo1;", url); man.addCookieFromHeader("test2=moo2;path=/sub1", url); man.addCookieFromHeader("test2=moo3;path=/", url); assertEquals(3, man.getCookieCount()); assertEquals("/sub1", man.get(0).getPath()); assertEquals("/sub1", man.get(1).getPath()); assertEquals("/", man.get(2).getPath()); String s = man.getCookieHeaderForURL(url); assertNotNull(s);//from w w w. jav a 2 s . c o m HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler(); List<org.apache.http.cookie.Cookie> c = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES); assertEquals("/sub1", c.get(0).getPath()); assertFalse(((BasicClientCookie) c.get(0)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("/sub1", c.get(1).getPath()); assertTrue(((BasicClientCookie) c.get(1)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("/", c.get(2).getPath()); assertTrue(((BasicClientCookie) c.get(2)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("$Version=0; test1=moo1; test2=moo2; $Path=/sub1; test2=moo3; $Path=/", s); }
From source file:org.apache.jmeter.protocol.http.control.TestHC4CookieManager.java
@Test public void testCookiePolicyNetscape() throws Exception { man.setCookiePolicy(CookieSpecs.NETSCAPE); man.testStarted(); // ensure policy is picked up URL url = new URL("http://www.order.now/sub1/moo.html"); man.addCookieFromHeader("test1=moo1;", url); man.addCookieFromHeader("test2=moo2;path=/sub1", url); man.addCookieFromHeader("test2=moo3;path=/", url); assertEquals(3, man.getCookieCount()); assertEquals("/sub1", man.get(0).getPath()); assertEquals("/sub1", man.get(1).getPath()); assertEquals("/", man.get(2).getPath()); String s = man.getCookieHeaderForURL(url); assertNotNull(s);//from ww w . j av a 2 s . c o m HC4CookieHandler cookieHandler = (HC4CookieHandler) man.getCookieHandler(); List<org.apache.http.cookie.Cookie> c = cookieHandler.getCookiesForUrl(man.getCookies(), url, CookieManager.ALLOW_VARIABLE_COOKIES); assertEquals("/sub1", c.get(0).getPath()); assertFalse(((BasicClientCookie) c.get(0)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("/sub1", c.get(1).getPath()); assertTrue(((BasicClientCookie) c.get(1)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("/", c.get(2).getPath()); assertTrue(((BasicClientCookie) c.get(2)).containsAttribute(ClientCookie.PATH_ATTR)); assertEquals("test1=moo1; test2=moo2; test2=moo3", s); }