Code example for CookieOrigin

Methods: getHost

0
    @Override 
    public void validate(final Cookie cookie, final CookieOrigin origin) 
            throws MalformedCookieException { 
        super.validate(cookie, origin);
        // Perform Netscape Cookie draft specific validation 
        String host = origin.getHost();
        String domain = cookie.getDomain();
        if (host.contains(".")) {
            int domainParts = new StringTokenizer(domain, ".").countTokens();
 
            if (isSpecialDomain(domain)) {
                if (domainParts < 2) {
                    throw new MalformedCookieException("Domain attribute \""
                        + domain 
                        + "\" violates the Netscape cookie specification for " 
                        + "special domains"); 
                } 
            } else { 
                if (domainParts < 3) {
                    throw new MalformedCookieException("Domain attribute \""
                        + domain 
                        + "\" violates the Netscape cookie specification"); 
                }             
            } 
        } 
    } 
 
   /** 
    * Checks if the given domain is in one of the seven special 
    * top level domains defined by the Netscape cookie specification. 
    * @param domain The domain. 
    * @return True if the specified domain is "special"