Thank you. I went with a hackier solution:
#!/usr/bin/env groovy
import com.gargoylesoftware.htmlunit.WebClient
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
import java.io.File
import org.apache.http.impl.cookie.BasicClientCookie
class HTTPBuilder extends groovyx.net.http.HTTPBuilder {
...
/**
* Load cookies from specified file
*/
def loadCookies(file) {
file.withObjectInputStream { ois->
ois.readObject().each { cookieMap->
def cookie=new BasicClientCookie(cookieMap.name,cookieMap.value)
cookieMap.remove("name")
cookieMap.remove("value")
cookieMap.entrySet().each { entry->
cookie."${entry.key}"=entry.value
}
client.cookieStore.addCookie(cookie)
println cookie
}
}
}
/**
* Save cookies to specified file
*/
def saveCookies(file) {
def cookieMaps=new ArrayList(new LinkedHashMap())
client.cookieStore.getCookies().each { cookie->
def cookieMap=[:]
cookieMap.version=cookie.version
cookieMap.name=cookie.name
cookieMap.value=cookie.value
cookieMap.domain=cookie.domain
cookieMap.path=cookie.path
cookieMap.expiryDate=cookie.expiryDate
cookieMaps.add(cookieMap)
println cookie
}
file.withObjectOutputStream { oos->
oos.writeObject(cookieMaps)
}
}
...
}