Example usage for java.net CookieManager CookieManager

List of usage examples for java.net CookieManager CookieManager

Introduction

In this page you can find the example usage for java.net CookieManager CookieManager.

Prototype

public CookieManager(CookieStore store, CookiePolicy cookiePolicy) 

Source Link

Document

Create a new cookie manager with specified cookie store and cookie policy.

Usage

From source file:com.yanzhenjie.nohttp.NoHttp.java

private NoHttp(Config config) {
    mConnectTimeout = config.mConnectTimeout;
    mReadTimeout = config.mReadTimeout;/*w  ww.  j  ava2  s  .com*/

    CookieStore cookieStore = config.mCookieStore == null ? new DBCookieStore(NoHttp.getContext())
            : config.mCookieStore;
    mCookieManager = new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
    mCacheStore = config.mCacheStore == null ? new DBCacheStore(NoHttp.getContext()) : config.mCacheStore;
    mNetworkExecutor = config.mNetworkExecutor == null ? new URLConnectionNetworkExecutor()
            : config.mNetworkExecutor;
}

From source file:at.gv.egiz.bku.binding.AbstractBindingProcessor.java

@Override
public void init(String id, STAL stal, SLCommandInvoker commandInvoker) {
    if (id == null) {
        throw new NullPointerException("Id must not be null.");
    }/*from   ww  w .ja va 2 s  .  c o  m*/
    if (stal == null) {
        throw new NullPointerException("STAL must not null.");
    }
    if (commandInvoker == null) {
        throw new NullPointerException("CommandInvoker must null.");
    }
    this.id = IdFactory.getInstance().createId(id);
    this.stal = stal;
    this.commandInvoker = commandInvoker;
    // disable cookies
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_NONE));
}

From source file:com.yolanda.nohttp.NoHttp.java

/**
 * Initialization NoHttp, Should invoke on {@link Application#onCreate()}.
 *
 * @param application {@link Application}.
 *///from  www .ja va  2s  . c  o  m
public static void initialize(Application application) {
    if (sApplication == null) {
        sApplication = application;
        sCookieHandler = new CookieManager(DiskCookieStore.INSTANCE, CookiePolicy.ACCEPT_ALL);
    }
}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ESUP_NFC_TAG_SERVER_URL = getEsupNfcTagServerUrl(getApplicationContext());
    //To keep session for desfire async requests
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
    LocalStorage.getInstance(getApplicationContext());
    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(getApplicationContext()));
    setContentView(R.layout.activity_main);
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    checkHardware(mAdapter);//from  w  w  w  .j  a  v  a 2s .c  om
    localStorageDBHelper = LocalStorage.getInstance(this.getApplicationContext());
    String numeroId = localStorageDBHelper.getValue("numeroId");
    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();
    url = ESUP_NFC_TAG_SERVER_URL + "/nfc-index?numeroId=" + numeroId + "&imei=" + imei + "&macAddress="
            + getMacAddr() + "&apkVersion=" + getApkVersion();
    view = (WebView) this.findViewById(R.id.webView);
    view.clearCache(true);
    view.addJavascriptInterface(new LocalStorageJavaScriptInterface(this.getApplicationContext()),
            "AndroidLocalStorage");
    view.addJavascriptInterface(new AndroidJavaScriptInterface(this.getApplicationContext()), "Android");

    view.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                AUTH_TYPE = localStorageDBHelper.getValue("authType");
            }
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            log.info("Webview console message : " + consoleMessage.message());
            return false;
        }

    });

    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            view.reload();
            return true;
        }
    });
    view.getSettings().setAllowContentAccess(true);
    WebSettings webSettings = view.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(this.getFilesDir().getParentFile().getPath() + "/databases/");

    view.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }

    });

    view.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
        }
    });

    view.loadUrl(url);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

From source file:jmc.util.UtlFbComents.java

public static String getJSONComentarios(String url, Long numComents) throws JMCException {
    String linea = "";
    String buf = "";

    try {/*from   ww  w.  j av a  2s .  co m*/
        Properties props = ConfigPropiedades.getProperties("props_config.properties");
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
        URL ur = new URL(
                "http://graph.facebook.com/comments?id=" + url + "&limit=" + numComents + "&filter=stream");
        HttpURLConnection cn = (HttpURLConnection) ur.openConnection();

        cn.setRequestProperty("user-agent", props.getProperty("navegador"));
        cn.setInstanceFollowRedirects(false);
        cn.setUseCaches(false);
        cn.connect();

        BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream()));

        while ((linea = br.readLine()) != null) {
            buf.concat(linea);
        }
        cn.disconnect();

    } catch (IOException e) {
        throw new JMCException(e);
    }
    return buf;
}

From source file:se.leap.bitmaskclient.ProviderAPI.java

@Override
public void onCreate() {
    super.onCreate();

    preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE);
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
}

From source file:edu.stanford.epadd.launcher.Main.java

private static boolean isURLAlive(String url) throws IOException {
    try {//from   w  w w.  j ava  2  s  .com
        // attempt to fetch the page
        // throws a connect exception if the server is not even running
        // so catch it and return false

        // since "index" may auto load default archive, attach it to session, and redirect to "info" page,
        // we need to maintain the session across the pages.
        // see "Maintaining the session" at http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

        HttpURLConnection u = (HttpURLConnection) new URL(url).openConnection();
        if (u.getResponseCode() == 200) {
            u.disconnect();
            return true;
        }
        u.disconnect();
    } catch (ConnectException ce) {
    }
    return false;
}

From source file:at.becast.youploader.account.Account.java

public void loadCookie() throws IOException {
    CookieJar persistentCookieStore = new CookieJar();
    CookieManager cmrCookieMan = new CookieManager(persistentCookieStore, null);
    persistentCookieStore.setSerializeableCookies(this.getCookie());
    CookieHandler.setDefault(cmrCookieMan);
    LOG.info("Updating cookies");
    OAuth2 auth = new OAuth2(s.setting.get("client_id"), s.setting.get("clientSecret"), this.refreshToken);
    Map<String, String> headers = new HashMap<>();
    try {//from  w  w  w  .j  a va2  s  .  com
        headers.put("Authorization", auth.getHeader());
    } catch (NullPointerException e) {
    }
    SimpleHTTP Videoget = new SimpleHTTP();
    String resp = Videoget.get(
            "https://www.googleapis.com/youtube/v3/search?part=id&forMine=true&maxResults=1&type=video",
            headers);
    Pattern MY_PATTERN = Pattern.compile("\"videoId\": \"(.*?)\"");
    Matcher m = MY_PATTERN.matcher(resp);
    String vidID = null;
    while (m.find()) {
        vidID = m.group(1);
    }
    String url = String.format("https://www.youtube.com/edit?o=U&ns=1&video_id=%s", vidID);
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", Main.APP_NAME + " " + Main.VERSION);
    int responseCode = con.getResponseCode();

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();
    if (responseCode < 400) {
        this.setCookie(persistentCookieStore.getSerializeableCookies());
        LOG.info("Got cookie: {}", persistentCookieStore.getSerializeableCookies().toString());
    } else {
        LOG.info("Could not fetch Cookie {}", response.toString());
    }
}

From source file:edu.stanford.muse.launcher.Splash.java

private static boolean isURLAlive(String url) throws IOException {
    try {/* w ww  .  j  a  v a2 s.co m*/
        // attempt to fetch the page
        // throws a connect exception if the server is not even running
        // so catch it and return false

        // since "index" may auto load default archive, attach it to session, and redirect to "info" page,
        // we need to maintain the session across the pages.
        // see "Maintaining the session" at http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

        out.println("Testing liveness at " + url);
        HttpURLConnection u = (HttpURLConnection) new URL(url).openConnection();
        if (u.getResponseCode() == 200) {
            u.disconnect();
            return true;
        }
        u.disconnect();
    } catch (ConnectException ce) {
    }
    return false;
}

From source file:edu.stanford.epadd.launcher.Splash.java

private static boolean isURLAlive(String url) throws IOException {
    try {//from w ww  . ja va  2 s  . c  om
        // attempt to fetch the page
        // throws a connect exception if the server is not even running
        // so catch it and return false

        // since "index" may auto load default archive, attach it to session, and redirect to "info" page,
        // we need to maintain the session across the pages.
        // see "Maintaining the session" at http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));

        out.println("Testing for already running ePADD by probing " + url);
        System.out.println("Testing for already running ePADD by probing " + url);
        HttpURLConnection u = (HttpURLConnection) new URL(url).openConnection();
        if (u.getResponseCode() == 200) {
            u.disconnect();
            out.println("ePADD is already running!");

            return true;
        }
        u.disconnect();
    } catch (ConnectException ce) {
    }
    out.println("Good, ePADD is not already running");
    return false;
}