Search in sources :

Example 31 with CookieManager

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();
}
Also used : DashboardSplashScreen(net.sourceforge.processdash.ui.DashboardSplashScreen) CookieManager(java.net.CookieManager)

Example 32 with CookieManager

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();
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) CookieManager(java.net.CookieManager) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 33 with CookieManager

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;
}
Also used : JavaNetCookieJar(okhttp3.JavaNetCookieJar) Disposable(io.reactivex.disposables.Disposable) HashMap(java.util.HashMap) IOException(java.io.IOException) UserEntity(com.nextcloud.talk.models.database.UserEntity) PushConfigurationState(com.nextcloud.talk.models.json.push.PushConfigurationState) CompletableObserver(io.reactivex.CompletableObserver) Observer(io.reactivex.Observer) CompletableObserver(io.reactivex.CompletableObserver) NcApi(com.nextcloud.talk.api.NcApi) GenericOverall(com.nextcloud.talk.models.json.generic.GenericOverall) CookieManager(java.net.CookieManager) NonNull(android.support.annotation.NonNull)

Example 34 with CookieManager

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Logger(java.util.logging.Logger) ConsoleHandler(java.util.logging.ConsoleHandler) URI(java.net.URI) URL(java.net.URL) URLConnection(java.net.URLConnection) BufferedReader(java.io.BufferedReader) ParseException(java.text.ParseException) HttpCookie(java.net.HttpCookie) SimpleDateFormat(java.text.SimpleDateFormat) CookieManager(java.net.CookieManager) CookieHandler(java.net.CookieHandler)

Example 35 with CookieManager

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);
}
Also used : HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager)

Aggregations

CookieManager (java.net.CookieManager)162 URI (java.net.URI)89 HttpCookie (java.net.HttpCookie)82 CookieStore (java.net.CookieStore)49 MockResponse (com.google.mockwebserver.MockResponse)20 List (java.util.List)20 ArrayList (java.util.ArrayList)18 MockWebServer (com.google.mockwebserver.MockWebServer)15 IOException (java.io.IOException)13 HashMap (java.util.HashMap)12 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)11 RecordedRequest (com.google.mockwebserver.RecordedRequest)8 MockResponse (mockwebserver3.MockResponse)8 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 RecordedRequest (mockwebserver3.RecordedRequest)5 JavaNetCookieJar (okhttp3.JavaNetCookieJar)4