类org.apache.commons.httpclient.cookie.MalformedCookieException源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.cookie.MalformedCookieException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: davmail   文件: DavMailCookieSpec.java
@Override
public void validate(String host, int port, String path,
                     boolean secure, final Cookie cookie) throws MalformedCookieException {
    // workaround for space in cookie name
    String cookieName = cookie.getName();
    if (cookieName != null && cookieName.indexOf(' ') >= 0) {
        cookie.setName(cookieName.replaceAll(" ", ""));
    } else {
        cookieName = null;
    }
    // workaround for invalid cookie path
    String cookiePath = cookie.getPath();
    if (cookiePath != null && !path.startsWith(cookiePath)) {
        cookie.setPath(path);
    } else {
        cookiePath = null;
    }
    // workaround for invalid cookie domain
    int dotIndex = -1;
    if (host.endsWith(cookie.getDomain())) {
        String hostWithoutDomain = host.substring(0, host.length()
                - cookie.getDomain().length());
        dotIndex = hostWithoutDomain.indexOf('.');
    }
    if (".login.microsoftonline.com".equals(cookie.getDomain())) {
        cookie.setDomain(host);
    }
    if (dotIndex != -1) {
        // discard additional host name part
        super.validate(host.substring(dotIndex + 1), port, path, secure, cookie);
    } else {
        super.validate(host, port, path, secure, cookie);
    }
    if (cookieName != null) {
        cookie.setName(cookieName);
    }
    if (cookiePath != null) {
        cookie.setPath(cookiePath);
    }
}
 
 类方法
 同包方法