org.apache.commons.httpclient.cookie.MalformedCookieException Java Examples

The following examples show how to use org.apache.commons.httpclient.cookie.MalformedCookieException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DavMailCookieSpec.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}