use of java.net.CookieManager in project jabref by JabRef.
the class URLDownload method getCookieFromUrl.
public List<HttpCookie> getCookieFromUrl() throws IOException {
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
URLConnection con = this.openConnection();
// must be read to store the cookie
con.getHeaderFields();
try {
return cookieManager.getCookieStore().get(this.source.toURI());
} catch (URISyntaxException e) {
LOGGER.error("Unable to convert download URL to URI", e);
return Collections.emptyList();
}
}
use of java.net.CookieManager in project camel by apache.
the class ExchangeCookieHandler method getCookieManager.
@Override
protected CookieManager getCookieManager(Exchange exchange) {
Object handlerObj = exchange.getProperty(Exchange.COOKIE_HANDLER);
if (handlerObj instanceof java.net.CookieManager) {
return (CookieManager) handlerObj;
} else {
CookieManager handler = new CookieManager();
exchange.setProperty(Exchange.COOKIE_HANDLER, handler);
return handler;
}
}
use of java.net.CookieManager in project android-oss by kickstarter.
the class RefTagUtilsTest method testFindRefTagCookieForProject_WhenCookieExists.
@Test
public void testFindRefTagCookieForProject_WhenCookieExists() {
final CookieManager cookieManager = new CookieManager();
final CookieStore cookieStore = cookieManager.getCookieStore();
final Project project = ProjectFactory.project();
final RefTag refTag = RefTag.recommended();
// set and retrieve the cookie
cookieStore.add(null, new HttpCookie("ref_" + project.id(), refTag.tag() + "%3F" + SystemUtils.secondsSinceEpoch()));
final HttpCookie cookie = RefTagUtils.findRefTagCookieForProject(project, cookieManager, sharedPreferences);
assertNotNull(cookie);
assertEquals(RefTagUtils.cookieNameForProject(project), cookie.getName());
assertEquals(RefTagUtils.cookieValueForRefTag(refTag), cookie.getValue());
}
use of java.net.CookieManager in project ion by koush.
the class CookieMiddleware method reinit.
public void reinit() {
manager = new CookieManager(null, null);
preferences = ion.getContext().getSharedPreferences(ion.getName() + "-cookies", Context.MODE_PRIVATE);
Map<String, ?> allPrefs = preferences.getAll();
for (String key : allPrefs.keySet()) {
try {
String value = preferences.getString(key, null);
Headers headers = new Headers();
String[] lines = value.split("\n");
boolean first = true;
for (String line : lines) {
if (first) {
first = false;
} else if (!TextUtils.isEmpty(line)) {
headers.addLine(line);
}
}
manager.put(URI.create(key), headers.getMultiMap());
} catch (Exception e) {
Log.e("Ion", "unable to load cookies", e);
}
}
}
use of java.net.CookieManager in project ion by koush.
the class CookieTests method testReinit.
public void testReinit() throws Exception {
CookieMiddleware middleware = Ion.getDefault(getContext()).getCookieMiddleware();
Ion ion = Ion.getDefault(getContext());
ion.getCookieMiddleware().clear();
Headers headers = new Headers();
headers.set("Set-Cookie", "foo=bar");
URI uri = URI.create("http://example.com");
middleware.put(uri, headers);
headers.set("Set-Cookie", "poop=scoop");
middleware.put(uri, headers);
headers.set("Set-Cookie", "foo=goop");
middleware.put(uri, headers);
middleware.reinit();
CookieManager manager = middleware.getCookieManager();
Headers newHeaders = new Headers();
Map<String, List<String>> cookies = manager.get(uri, newHeaders.getMultiMap());
manager.get(uri, cookies);
CookieMiddleware.addCookies(cookies, newHeaders);
assertTrue(newHeaders.get("Cookie").contains("foo=goop"));
assertTrue(newHeaders.get("Cookie").contains("poop=scoop"));
assertFalse(newHeaders.get("Cookie").contains("bar"));
}
Aggregations