當前位置: 首頁>>代碼示例>>Java>>正文


Java Cookie.getDomain方法代碼示例

本文整理匯總了Java中org.apache.commons.httpclient.Cookie.getDomain方法的典型用法代碼示例。如果您正苦於以下問題:Java Cookie.getDomain方法的具體用法?Java Cookie.getDomain怎麽用?Java Cookie.getDomain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.httpclient.Cookie的用法示例。


在下文中一共展示了Cookie.getDomain方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: match

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
 * Match cookie domain attribute.
 */
public boolean match(final Cookie cookie, final CookieOrigin origin) {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    String host = origin.getHost().toLowerCase();
    String cookieDomain = cookie.getDomain();

    // The effective host name MUST domain-match the Domain
    // attribute of the cookie.
    if (!domainMatch(host, cookieDomain)) {
        return false;
    }
    // effective host name minus domain must not contain any dots
    String effectiveHostWithoutDomain = host.substring(
            0, host.length() - cookieDomain.length());
    if (effectiveHostWithoutDomain.indexOf('.') != -1) {
        return false;
    }
    return true;
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:27,代碼來源:RFC2965Spec.java

示例2: formatCookieAsVer

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
 * 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 string buffer to use for output
 * @param cookie The {@link Cookie} to be formatted as string
 * @param version The version to use.
 */
private void formatCookieAsVer(final StringBuffer buffer, final Cookie cookie, int version) {
    String value = cookie.getValue();
    if (value == null) {
        value = "";
    }
    formatParam(buffer, new NameValuePair(cookie.getName(), value), version);
    if ((cookie.getPath() != null) && cookie.isPathAttributeSpecified()) {
      buffer.append("; ");
      formatParam(buffer, new NameValuePair("$Path", cookie.getPath()), version);
    }
    if ((cookie.getDomain() != null) 
        && cookie.isDomainAttributeSpecified()) {
        buffer.append("; ");
        formatParam(buffer, new NameValuePair("$Domain", cookie.getDomain()), version);
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:24,代碼來源:RFC2109Spec.java

示例3: getCookieStrings

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
public Vector<String> getCookieStrings() {
	// Use the HandleCookie Property of the transaction to return or not the cookies.
	//
	// We noticed a Bug in tomcat when too much cookies where set in the response to the client. This causes a 
	// IndexOutOfBoundException:  4096 in coyote.
	// To overcome this situation, now you can configure HandleCookies to false in the transaction to prevent cookies to be reflected
	// to the client.
	if (requestedObject instanceof AbstractHttpTransaction ) {
		if (!((AbstractHttpTransaction)requestedObject).isHandleCookie())
			return new Vector<String>();
	}
	
	Vector<String> cookies = new Vector<String>();
	if (httpState != null) {
		Cookie[] httpCookies = httpState.getCookies();
		int len = httpCookies.length;
		Cookie cookie = null;
		String sCookie;
		
		DateFormat df = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US);
		df.setTimeZone(TimeZone.getTimeZone("GMT"));
		for (int i=0; i<len; i++) {
			cookie = httpCookies[i];
			sCookie = 	cookie.getName() + "=" + cookie.getValue() + ";";
			sCookie +=	(cookie.getExpiryDate() != null) ? "expires=" + df.format(cookie.getExpiryDate())+ ";":"";
			sCookie +=	"path=" + cookie.getPath() + ";";
			sCookie +=	"domain=" + cookie.getDomain() + ";";
			sCookie +=	cookie.getSecure() ? "secure": "";
			cookies.add(sCookie);
		}
	}
	return cookies;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:34,代碼來源:Context.java

示例4: formatCookie

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
public static String formatCookie(Cookie cookie) {
	StringBuffer buf = new StringBuffer();
	Date d = cookie.getExpiryDate();
	String[][] datas = {
			// {"$Version",Integer.toString(cookie.getVersion())},
			{ cookie.getName(), cookie.getValue() }, { "$Domain", cookie.getDomain() },
			{ "$Path", cookie.getPath() }, { "$Secure", Boolean.toString(cookie.getSecure()) },
			{ "$Date", d == null ? "null" : DateFormat.getDateTimeInstance().format(d) } };
	buf.append(datas[0][0] + "=" + datas[0][1]);
	for (int i = 1; i < datas.length; i++) {
		if (datas[i][1] != null)
			buf.append("; " + datas[i][0] + "=" + datas[i][1]);
	}
	return buf.toString();
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:16,代碼來源:CookiesUtils.java

示例5: validate

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
  * Performs Netscape draft compliant {@link Cookie} validation
  *
  * @param host the host from which the {@link Cookie} was received
  * @param port the port from which the {@link Cookie} was received
  * @param path the path from which the {@link Cookie} was received
  * @param secure <tt>true</tt> when the {@link Cookie} was received 
  * using a secure connection
  * @param cookie The cookie to validate.
  * @throws MalformedCookieException if an exception occurs during
  * validation
  */
public void validate(String host, int port, String path, 
    boolean secure, final Cookie cookie) 
    throws MalformedCookieException {
        
    LOG.trace("enterNetscapeDraftCookieProcessor "
        + "RCF2109CookieProcessor.validate(Cookie)");
    // Perform generic validation
    super.validate(host, port, path, secure, cookie);
    // Perform Netscape Cookie draft specific validation
    if (host.indexOf(".") >= 0) {
        int domainParts = new StringTokenizer(cookie.getDomain(), ".")
            .countTokens();

        if (isSpecialDomain(cookie.getDomain())) {
            if (domainParts < 2) {
                throw new MalformedCookieException("Domain attribute \""
                    + cookie.getDomain() 
                    + "\" violates the Netscape cookie specification for "
                    + "special domains");
            }
        } else {
            if (domainParts < 3) {
                throw new MalformedCookieException("Domain attribute \""
                    + cookie.getDomain() 
                    + "\" violates the Netscape cookie specification");
            }            
        }
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:42,代碼來源:NetscapeDraftSpec.java

示例6: validate

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
 * Validate cookie domain attribute.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
        throws MalformedCookieException {
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    String host = origin.getHost().toLowerCase();
    if (cookie.getDomain() == null) {
        throw new MalformedCookieException("Invalid cookie state: " +
                                           "domain not specified");
    }
    String cookieDomain = cookie.getDomain().toLowerCase();

    if (cookie.isDomainAttributeSpecified()) {
        // Domain attribute must start with a dot
        if (!cookieDomain.startsWith(".")) {
            throw new MalformedCookieException("Domain attribute \"" +
                cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot");
        }

        // Domain attribute must contain atleast one embedded dot,
        // or the value must be equal to .local.
        int dotIndex = cookieDomain.indexOf('.', 1);
        if (((dotIndex < 0) || (dotIndex == cookieDomain.length() - 1))
            && (!cookieDomain.equals(".local"))) {
            throw new MalformedCookieException(
                    "Domain attribute \"" + cookie.getDomain()
                    + "\" violates RFC 2965: the value contains no embedded dots "
                    + "and the value is not .local");
        }

        // The effective host name must domain-match domain attribute.
        if (!domainMatch(host, cookieDomain)) {
            throw new MalformedCookieException(
                    "Domain attribute \"" + cookie.getDomain()
                    + "\" violates RFC 2965: effective host name does not "
                    + "domain-match domain attribute.");
        }

        // effective host name minus domain must not contain any dots
        String effectiveHostWithoutDomain = host.substring(
                0, host.length() - cookieDomain.length());
        if (effectiveHostWithoutDomain.indexOf('.') != -1) {
            throw new MalformedCookieException("Domain attribute \""
                                               + cookie.getDomain() + "\" violates RFC 2965: "
                                               + "effective host minus domain may not contain any dots");
        }
    } else {
        // Domain was not specified in header. In this case, domain must
        // string match request host (case-insensitive).
        if (!cookie.getDomain().equals(host)) {
            throw new MalformedCookieException("Illegal domain attribute: \""
                                               + cookie.getDomain() + "\"."
                                               + "Domain of origin: \""
                                               + host + "\"");
        }
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:64,代碼來源:RFC2965Spec.java

示例7: match

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
 * Return <tt>true</tt> if the cookie should be submitted with a request
 * with given attributes, <tt>false</tt> otherwise.
 * @param host the host to which the request is being submitted
 * @param port the port to which the request is being submitted (ignored)
 * @param path the path to which the request is being submitted
 * @param secure <tt>true</tt> if the request is using a secure connection
 * @param cookie {@link Cookie} to be matched
 * @return true if the cookie matches the criterium
 */

public boolean match(String host, int port, String path, 
    boolean secure, final Cookie cookie) {
        
    LOG.trace("enter CookieSpecBase.match("
        + "String, int, String, boolean, Cookie");
        
    if (host == null) {
        throw new IllegalArgumentException(
            "Host of origin may not be null");
    }
    if (host.trim().equals("")) {
        throw new IllegalArgumentException(
            "Host of origin may not be blank");
    }
    if (port < 0) {
        throw new IllegalArgumentException("Invalid port: " + port);
    }
    if (path == null) {
        throw new IllegalArgumentException(
            "Path of origin may not be null.");
    }
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null");
    }
    if (path.trim().equals("")) {
        path = PATH_DELIM;
    }
    host = host.toLowerCase();
    if (cookie.getDomain() == null) {
        LOG.warn("Invalid cookie state: domain not specified");
        return false;
    }
    if (cookie.getPath() == null) {
        LOG.warn("Invalid cookie state: path not specified");
        return false;
    }
    
    return
        // only add the cookie if it hasn't yet expired 
        (cookie.getExpiryDate() == null 
            || cookie.getExpiryDate().after(new Date()))
        // and the domain pattern matches 
        && (domainMatch(host, cookie.getDomain()))
        // and the path is null or matching
        && (pathMatch(path, cookie.getPath()))
        // and if the secure flag is set, only if the request is 
        // actually secure 
        && (cookie.getSecure() ? secure : true);      
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:61,代碼來源:CookieSpecBase.java

示例8: validate

import org.apache.commons.httpclient.Cookie; //導入方法依賴的package包/類
/**
  * Performs RFC 2109 compliant {@link Cookie} validation
  *
  * @param host the host from which the {@link Cookie} was received
  * @param port the port from which the {@link Cookie} was received
  * @param path the path from which the {@link Cookie} was received
  * @param secure <tt>true</tt> when the {@link Cookie} was received using a
  * secure connection
  * @param cookie The cookie to validate
  * @throws MalformedCookieException if an exception occurs during
  * validation
  */
public void validate(String host, int port, String path, 
    boolean secure, final Cookie cookie) throws MalformedCookieException {
        
    LOG.trace("enter RFC2109Spec.validate(String, int, String, "
        + "boolean, Cookie)");
        
    // Perform generic validation
    super.validate(host, port, path, secure, cookie);
    // Perform RFC 2109 specific validation
    
    if (cookie.getName().indexOf(' ') != -1) {
        throw new MalformedCookieException("Cookie name may not contain blanks");
    }
    if (cookie.getName().startsWith("$")) {
        throw new MalformedCookieException("Cookie name may not start with $");
    }
    
    if (cookie.isDomainAttributeSpecified() 
        && (!cookie.getDomain().equals(host))) {
            
        // domain must start with dot
        if (!cookie.getDomain().startsWith(".")) {
            throw new MalformedCookieException("Domain attribute \"" 
                + cookie.getDomain() 
                + "\" violates RFC 2109: domain must start with a dot");
        }
        // domain must have at least one embedded dot
        int dotIndex = cookie.getDomain().indexOf('.', 1);
        if (dotIndex < 0 || dotIndex == cookie.getDomain().length() - 1) {
            throw new MalformedCookieException("Domain attribute \"" 
                + cookie.getDomain() 
                + "\" violates RFC 2109: domain must contain an embedded dot");
        }
        host = host.toLowerCase();
        if (!host.endsWith(cookie.getDomain())) {
            throw new MalformedCookieException(
                "Illegal domain attribute \"" + cookie.getDomain() 
                + "\". Domain of origin: \"" + host + "\"");
        }
        // host minus domain may not contain any dots
        String hostWithoutDomain = host.substring(0, host.length() 
            - cookie.getDomain().length());
        if (hostWithoutDomain.indexOf('.') != -1) {
            throw new MalformedCookieException("Domain attribute \"" 
                + cookie.getDomain() 
                + "\" violates RFC 2109: host minus domain may not contain any dots");
        }
    }
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:62,代碼來源:RFC2109Spec.java


注:本文中的org.apache.commons.httpclient.Cookie.getDomain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。