![JAR search and dependency download from the Maven repository](/logo.png)
com.github.iarellano.rest_client.cookie.CookieUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iad-rest-client-maven-plugin Show documentation
Show all versions of iad-rest-client-maven-plugin Show documentation
At times we need to consume external services as part of a build process, for example
to verify which version of an API is deployed, verify that a service is online, get
configurations from some remote storage provider, etc.
This plugin is aimed to provide a way to make HTTP request either to get resources,
upload files, submit forms, post json, post xml, etc.
package com.github.iarellano.rest_client.cookie;
import com.github.iarellano.rest_client.configuration.CookieConfig;
import org.apache.maven.plugin.logging.Log;
import java.io.IOException;
import java.net.CookieHandler;
import java.net.CookieManager;
public class CookieUtil {
private final CookieConfig cookieConfig;
private final CookieManager origCookieManager;
private final Log log;
private PersistentCookieStore cookieStore;
public CookieUtil(CookieConfig cookieConfig, Log log) {
this.cookieConfig = cookieConfig;
this.log = log;
origCookieManager = (CookieManager) CookieHandler.getDefault();
}
public void installCookieManager() throws IOException {
cookieStore = new PersistentCookieStore(cookieConfig, log);
CookieManager cm = cookieStore.getCookieManager();
cm.setCookiePolicy(new ConfigurableCookiePolicy(cookieConfig, log));
CookieHandler.setDefault(cm);
}
public void persistCookies() throws IOException {
cookieStore.persistCookies();
}
public void restoreOriginalCookieManager() {
CookieHandler.setDefault(origCookieManager);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy