while (iteratorCookie.hasNext()) { Cookie cookie = iteratorCookie.next(); cookieStr.append(cookie.getName() + "=" + cookie.getValue()); if (iteratorCookie.hasNext()) { cookieStr.append(";");
public static String getCookie(String name) { List<Cookie> cookies = cookieStore.getCookies(); for (Cookie cookie : cookies) { if (cookie.getName().equalsIgnoreCase(name)) { return cookie.getValue(); } } return null; }
public void addCookie(Cookie cookie) { if (isCookieCountMaxedForDomain(cookie.getDomain())) { logger.log( Level.FINEST, "Maximum number of cookies reached for domain " + cookie.getDomain() + ". Will not add new cookie " + cookie.getName() + " with value " + cookie.getValue()); return; } addCookieImpl(cookie); }
public List<Header> formatCookies(final List<Cookie> cookies) { if (cookies == null) { throw new IllegalArgumentException("List of cookies may not be null"); } if (cookies.isEmpty()) { throw new IllegalArgumentException("List of cookies may not be empty"); } CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } buffer.append(cookie.getName()); buffer.append("="); String s = cookie.getValue(); if (s != null) { buffer.append(s); } } List<Header> headers = new ArrayList<Header>(1); headers.add(new BufferedHeader(buffer)); return headers; }
public List<Header> formatCookies(final List<Cookie> cookies) { if (cookies == null) { throw new IllegalArgumentException("List of cookies may not be null"); } if (cookies.isEmpty()) { throw new IllegalArgumentException("List of cookies may not be empty"); } CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } buffer.append(cookie.getName()); String s = cookie.getValue(); if (s != null) { buffer.append("="); buffer.append(s); } } List<Header> headers = new ArrayList<Header>(1); headers.add(new BufferedHeader(buffer)); return headers; }
public static HttpHeaders getHeaders(CookieStore cookies) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML, MediaType.ALL)); for (org.apache.http.cookie.Cookie cookie : cookies.getCookies()) { headers.add("Cookie", cookie.getName() + "=" + cookie.getValue()); } return headers; }
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { final CookieOrigin cookieOrigin = cookieOriginFromUri(requestSpec.getURI()); for (Cookie cookie : cookieStore.getCookies()) { if (cookieSpec.match(cookie, cookieOrigin) && !requestSpec.getCookies().hasCookieWithName(cookie.getName())) { requestSpec.cookie(cookie.getName(), cookie.getValue()); } } final Response response = ctx.next(requestSpec, responseSpec); List<Cookie> responseCookies = extractResponseCookies(response, cookieOrigin); cookieStore.addCookies(responseCookies.toArray(new Cookie[0])); return response; }
/** * Return a string suitable for sending in a <tt>"Cookie"</tt> header * as defined in RFC 2109 for backward compatibility with cookie version 0 * @param buffer The char array buffer to use for output * @param cookie The {@link Cookie} to be formatted as string * @param version The version to use. */ protected void formatCookieAsVer(final CharArrayBuffer buffer, final Cookie cookie, int version) { formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version); if (cookie.getPath() != null) { if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.PATH_ATTR)) { buffer.append("; "); formatParamAsVer(buffer, "$Path", cookie.getPath(), version); } } if (cookie.getDomain() != null) { if (cookie instanceof ClientCookie && ((ClientCookie) cookie).containsAttribute(ClientCookie.DOMAIN_ATTR)) { buffer.append("; "); formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version); } } }
public TimelyEndpointConfig(Cookie sessionCookie) { if (null != sessionCookie) { this.sessionCookie = String.format(FORMAT, sessionCookie.getName(), sessionCookie.getValue()); } }
public static String getSessionIdValueFromState(CookieStore cookieStore) { String sessionID = null; for (Cookie cookie : cookieStore.getCookies()) { if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) { sessionID = cookie.getValue(); break; } } return sessionID; }
private static void setCookie(HttpRequest request, Cookie[] cookies) { if (cookies != null && cookies.length > 0) { List<String> cookieStr = new LinkedList<>(); for (Cookie cookie : cookies) { cookieStr.add(cookie.getName() + "=" + cookie.getValue()); } request.setHeader("Cookie", StringUtils.join(cookieStr, "; ")); } }
public synchronized void addCookie(final org.apache.http.cookie.Cookie cookie) { if (cookie != null) { log.debug("Add cookie : name={}, path={}, value={},", cookie.getName(), cookie.getPath(), cookie.getValue()); // first remove any old cookie that is equivalent cookies.remove(cookie); if (!cookie.isExpired(new Date())) { cookies.add(cookie); } } }
/** Get login token cookie or null if not found */ private Cookie getLoginCookie(HttpContext context, String loginTokenName) { for (Cookie cookie : HttpClientContext.adapt(context).getCookieStore().getCookies()) { if (cookie.getName().equalsIgnoreCase(loginTokenName) && !cookie.getValue().isEmpty()) { return cookie; } } return null; } }
public void addCookie(Cookie cookie) { if (isCookieCountMaxedForDomain(cookie.getDomain())) { logger.log( Level.FINEST, "Maximum number of cookies reached for domain " + cookie.getDomain() + ". Will not add new cookie " + cookie.getName() + " with value " + cookie.getValue()); return; } addCookieImpl(cookie); }
Cookie(org.apache.http.cookie.Cookie cookie) { this.name = cookie.getName(); this.value = cookie.getValue(); this.expires = cookie.getExpiryDate(); this.path = cookie.getPath(); this.domain = cookie.getDomain(); this.httpOnly = false; this.secure = cookie.isSecure(); }
@Test public void testApacheCookielInput() { cookie.setDomain(".slides.com"); org.apache.http.cookie.Cookie resultCookie = CookieUtils.asApacheCookie(cookie); assertTrue(resultCookie.getName().equals("key1")); assertTrue(resultCookie.getValue().equals("value1")); assertTrue(resultCookie.getDomain().equals(".slides.com")); }
@Test public void testApacheCookielInputNullDomain() { org.apache.http.cookie.Cookie resultCookie = CookieUtils.asApacheCookie(cookie); assertTrue(resultCookie.getName().equals("key1")); assertTrue(resultCookie.getValue().equals("value1")); assertTrue(resultCookie.getDomain() == null); }
@Test public void testApacheCookielInputNullValue() { cookie.setValue(null); org.apache.http.cookie.Cookie resultCookie = CookieUtils.asApacheCookie(cookie); assertTrue(resultCookie.getName().equals("key1")); assertTrue(resultCookie.getValue() == null); }
@Test(expected = IllegalArgumentException.class) public void testApacheCookielInputNullKey() { cookie.setName(null); org.apache.http.cookie.Cookie resultCookie = CookieUtils.asApacheCookie(cookie); assertTrue(resultCookie.getName() == null); assertTrue(resultCookie.getValue().equals("value1")); }