Search in sources :

Example 1 with CookieManager

use of com.gargoylesoftware.htmlunit.CookieManager in project spring-framework by spring-projects.

the class MockMvcWebConnection method storeCookies.

private void storeCookies(WebRequest webRequest, javax.servlet.http.Cookie[] cookies) {
    if (cookies == null) {
        return;
    }
    Date now = new Date();
    CookieManager cookieManager = this.webClient.getCookieManager();
    for (javax.servlet.http.Cookie cookie : cookies) {
        if (cookie.getDomain() == null) {
            cookie.setDomain(webRequest.getUrl().getHost());
        }
        Cookie toManage = MockWebResponseBuilder.createCookie(cookie);
        Date expires = toManage.getExpires();
        if (expires == null || expires.after(now)) {
            cookieManager.addCookie(toManage);
        } else {
            cookieManager.removeCookie(toManage);
        }
    }
}
Also used : Cookie(com.gargoylesoftware.htmlunit.util.Cookie) Date(java.util.Date) CookieManager(com.gargoylesoftware.htmlunit.CookieManager)

Aggregations

CookieManager (com.gargoylesoftware.htmlunit.CookieManager)1 Cookie (com.gargoylesoftware.htmlunit.util.Cookie)1 Date (java.util.Date)1