本文整理了Java中org.apache.http.cookie.Cookie.getName()
方法的一些代码示例,展示了Cookie.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.getName()
方法的具体详情如下:
包路径:org.apache.http.cookie.Cookie
类名称:Cookie
方法名:getName
[英]Returns the name.
[中]
代码示例来源:origin: ninjaframework/ninja
public Cookie getCookieWithName(String name) {
List<Cookie> cookies = getCookies();
// skip through cookies and return cookie you want
for (Cookie cookie : cookies) {
if (cookie.getName().equals(name)) {
return cookie;
}
}
return null;
}
代码示例来源:origin: robovm/robovm
public int compare(final Cookie c1, final Cookie c2) {
int res = c1.getName().compareTo(c2.getName());
if (res == 0) {
// do not differentiate empty and null domains
String d1 = c1.getDomain();
if (d1 == null) {
d1 = "";
}
String d2 = c2.getDomain();
if (d2 == null) {
d2 = "";
}
res = d1.compareToIgnoreCase(d2);
}
return res;
}
代码示例来源:origin: alibaba/canal
while (iteratorCookie.hasNext()) {
Cookie cookie = iteratorCookie.next();
cookieStr.append(cookie.getName() + "=" + cookie.getValue());
if (iteratorCookie.hasNext()) {
cookieStr.append(";");
代码示例来源:origin: yaphone/itchat4j
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;
}
代码示例来源:origin: internetarchive/heritrix3
/**
* Returns a string that uniquely identifies the cookie, The format The
* format of the key is {@code "normalizedDomain;name;path"}. Adapted from
* {@link CookieIdentityComparator#compare(Cookie, Cookie)}.
*/
protected String sortableKey(Cookie cookie) {
String normalizedDomain = normalizeHost(cookie.getDomain());
// use ";" as delimiter since it is the delimiter in the cookie header,
// so presumably can't appear in any of these values
StringBuilder buf = new StringBuilder(normalizedDomain);
buf.append(";").append(cookie.getName());
buf.append(";").append(cookie.getPath() != null ? cookie.getPath() : "/");
return buf.toString();
}
代码示例来源:origin: robovm/robovm
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
throws MalformedCookieException {
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
String name = cookie.getName();
if (name.indexOf(' ') != -1) {
throw new MalformedCookieException("Cookie name may not contain blanks");
}
if (name.startsWith("$")) {
throw new MalformedCookieException("Cookie name may not start with $");
}
super.validate(cookie, origin);
}
代码示例来源:origin: apache/hive
/**
* The function iterates through the list of cookies in the cookiestore and tries to
* match them with the cookieName. If there is a match, the cookieStore already
* has a valid cookie and the client need not send Credentials for validation purpose.
* @param cookieStore The cookie Store
* @param cookieName Name of the cookie which needs to be validated
* @param isSSL Whether this is a http/https connection
* @return true or false based on whether the client needs to send the credentials or
* not to the server.
*/
static boolean needToSendCredentials(CookieStore cookieStore, String cookieName, boolean isSSL) {
if (cookieName == null || cookieStore == null) {
return true;
}
List<Cookie> cookies = cookieStore.getCookies();
for (Cookie c : cookies) {
// If this is a secured cookie and the current connection is non-secured,
// then, skip this cookie. We need to skip this cookie because, the cookie
// replay will not be transmitted to the server.
if (c.isSecure() && !isSSL) {
continue;
}
if (c.getName().equals(cookieName)) {
return false;
}
}
return true;
}
代码示例来源:origin: robovm/robovm
/**
* Don't log the cookie's value; that's potentially sensitive information.
*/
private String cookieToString(Cookie cookie) {
return cookie.getClass().getSimpleName()
+ "[version=" + cookie.getVersion()
+ ",name=" + cookie.getName()
+ ",domain=" + cookie.getDomain()
+ ",path=" + cookie.getPath()
+ ",expiry=" + cookie.getExpiryDate()
+ "]";
}
// END android-added
代码示例来源:origin: internetarchive/heritrix3
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);
}
代码示例来源:origin: robovm/robovm
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;
}
代码示例来源:origin: rest-assured/rest-assured
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;
}
代码示例来源:origin: robovm/robovm
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;
}
代码示例来源:origin: cloudfoundry/uaa
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;
}
代码示例来源:origin: internetarchive/heritrix3
line.append(cookie.getExpiryDate() != null ? cookie.getExpiryDate().getTime() / 1000 : -1);
line.append(tab);
line.append(cookie.getName());
line.append(tab);
line.append(cookie.getValue() != null ? cookie.getValue() : "");
代码示例来源:origin: robovm/robovm
/**
* 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);
}
}
}
代码示例来源:origin: NationalSecurityAgency/timely
public TimelyEndpointConfig(Cookie sessionCookie) {
if (null != sessionCookie) {
this.sessionCookie = String.format(FORMAT, sessionCookie.getName(), sessionCookie.getValue());
}
}
代码示例来源:origin: org.wildfly/wildfly-testsuite-shared
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;
}
代码示例来源:origin: org.doctester/doctester-core
private void printCookie(Cookie cookie) {
htmlDocument.add("Name: " + cookie.getName() + "<br/>");
htmlDocument.add("Path: " + cookie.getPath() + "<br/>");
htmlDocument.add("Domain: " + cookie.getDomain() + "<br/>");
htmlDocument.add("Value: " + cookie.getValue() + "<br/>");
}
代码示例来源:origin: SpringForAll/springcloud-thoth
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, "; "));
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.clients
/** 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;
}
}
内容来源于网络,如有侵权,请联系作者删除!