use of java.net.CookieManager in project processdash by dtuma.
the class ProcessDashboard method mainImpl.
private static void mainImpl(String[] args) {
DashboardSecurity.setupSecurityManager();
LargeFontsHelper.maybeInitialize();
ss = new DashboardSplashScreen();
// show for at least 3 seconds.
ss.displayFor(3000);
if (Boolean.getBoolean("readOnly"))
InternalSettings.setReadOnly(true);
String title = null;
String location = null;
for (int i = 0; i < args.length; i++) {
if ("readOnly".equalsIgnoreCase(args[i]))
InternalSettings.setReadOnly(true);
else if ("readOnlyFollow".equalsIgnoreCase(args[i]))
InternalSettings.setReadOnlyFollowMode();
else if (args[i].startsWith(LOCATION_ARG_PREFIX))
location = args[i].substring(LOCATION_ARG_PREFIX.length());
else
title = args[i];
}
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
HttpAuthenticator.maybeInitialize(title);
MacGUIUtils.tweakLookAndFeel();
ProcessDashboard dash = new ProcessDashboard(location, title);
HttpAuthenticator.setParentComponent(dash);
DashboardIconFactory.setWindowIcon(dash);
dash.setVisible(true);
dash.initializeWindowSize();
dropSplashScreen();
dash.maybeNotifyOpened();
dash.aum.maybePerformCheck(dash);
DataImporter.refreshCachedFiles();
}
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 talk-android by nextcloud.
the class AccountRemovalJob method onRunJob.
@NonNull
@Override
protected Result onRunJob(Params params) {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
PushConfigurationState pushConfigurationState;
for (Object userEntityObject : userUtils.getUsersScheduledForDeletion()) {
UserEntity userEntity = (UserEntity) userEntityObject;
try {
if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), PushConfigurationState.class);
PushConfigurationState finalPushConfigurationState = pushConfigurationState;
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
ncApi.unregisterDeviceForNotificationsWithNextcloud(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlNextcloudPush(userEntity.getBaseUrl())).subscribe(new Observer<GenericOverall>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(GenericOverall genericOverall) {
if (genericOverall.getOcs().getMeta().getStatusCode() == 200 || genericOverall.getOcs().getMeta().getStatusCode() == 202) {
HashMap<String, String> queryMap = new HashMap<>();
queryMap.put("deviceIdentifier", finalPushConfigurationState.deviceIdentifier);
queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
queryMap.put("deviceIdentifierSignature", finalPushConfigurationState.getDeviceIdentifierSignature());
ncApi.unregisterDeviceForNotificationsWithProxy(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlPushProxy(), queryMap).subscribe(new Observer<Void>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Void aVoid) {
userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
} else {
userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
}
} catch (IOException e) {
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
userUtils.deleteUser(userEntity.getUsername(), userEntity.getBaseUrl()).subscribe(new CompletableObserver() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
}
});
}
}
return Result.SUCCESS;
}
use of java.net.CookieManager in project ojAlgo by optimatika.
the class CookieTest method main.
public static void main(final String[] args) {
try {
final ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINE);
final Logger logger = Logger.getLogger("");
logger.setLevel(Level.FINE);
logger.setUseParentHandlers(false);
logger.addHandler(handler);
final CookieHandler manager = new CookieManager();
CookieHandler.setDefault(manager);
final URI uri = new URI("https", "finance.yahoo.com", "/quote/AAPL", null);
final URL url = uri.toURL();
final URLConnection connection = url.openConnection();
final InputStream stream = connection.getInputStream();
final Reader reader = new InputStreamReader(stream);
final BufferedReader buffered = new BufferedReader(reader);
while (buffered.readLine() != null) {
}
// manager.getCookieStore().getCookies().forEach(cookie -> System.out.println("Cookie store entry: " + cookie.toString()));
// Setting a breakpoint inside HttpCookie.parse(...) you can see that the input is a string like this
final String header = "B=5i0hk85ck33v2&b=3&s=4v; expires=Wed, 14-Jun-2018 19:34:58 GMT; path=/; domain=.yahoo.com";
final List<HttpCookie> cookies = HttpCookie.parse(header);
cookies.forEach(cookie -> {
System.out.println("Explicitly created cookie: " + cookie.toString());
System.out.println("\twith max age = " + cookie.getMaxAge());
});
// 1 cookie was craeted, but with max age == 0
final String timestamp = "Wed, 14-Jun-2018 19:34:58 GMT";
final CookieTest test = new CookieTest();
test.expiryDate2DeltaSeconds(timestamp);
for (final String pattern : COOKIE_DATE_FORMATS) {
final SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.US);
try {
System.out.println(format.parse(timestamp).toString());
} catch (final ParseException exception) {
System.out.println("Failed!");
}
}
} catch (URISyntaxException | IOException xcptn) {
xcptn.printStackTrace();
}
}
use of java.net.CookieManager in project ServiceStack.Java by ServiceStack.
the class JsonServiceClient method setCookie.
@Override
public void setCookie(String name, String value, Long expiresInSecs) {
CookieManager cookieManager = (CookieManager) CookieHandler.getDefault();
HttpCookie cookie = new HttpCookie(name, value);
if (expiresInSecs != null) {
cookie.setMaxAge(expiresInSecs);
}
cookieManager.getCookieStore().getCookies().add(cookie);
}
Aggregations