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() 

Source Link

Document

Create a new cookie manager.

Usage

From source file:org.apache.nutch.protocol.httpclient.HttpFormAuthentication.java

public void login() throws Exception {
    // make sure cookies are turned on
    CookieHandler.setDefault(new CookieManager());
    String pageContent = httpGetPageContent(authConfigurer.getLoginUrl());
    List<NameValuePair> params = getLoginFormParams(pageContent);
    sendPost(authConfigurer.getLoginUrl(), params);
}

From source file:org.kegbot.api.KegbotApiImpl.java

public KegbotApiImpl(AppConfiguration config, String userAgent) {
    mConfig = config;//w  w  w  . jav  a2s .c om
    mCookieManager = new CookieManager();
    mClient = new OkHttpClient();
    mClient.setCookieHandler(mCookieManager);
    CookieHandler.setDefault(mCookieManager);
    mUserAgent = userAgent;
}

From source file:edgeserver.Publicador.java

private String testServer() throws Exception {
    // make sure cookies is turn on
    CookieHandler.setDefault(new CookieManager());

    HTTPClient http = new HTTPClient();

    List<NameValuePair> GatewayParams = new ArrayList<>();

    String result = http.GetPageContent(this.urlInsertDado, GatewayParams);

    return result;
}

From source file:com.chaosinmotion.securechat.network.SCNetwork.java

/**
 * Internal initialization/*from  w  ww .  j  a  v  a2 s . c  om*/
 */
private SCNetwork() {
    cookies = new CookieManager();
    callQueue = new ArrayList<Request>();
    retryQueue = new ArrayList<Request>();
}

From source file:net.sf.jabref.importer.fetcher.IEEEXploreFetcher.java

public IEEEXploreFetcher(JournalAbbreviationLoader abbreviationLoader) {
    super();// w  w w . jav a2  s .  c om
    this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader);
    CookieHandler.setDefault(new CookieManager());
}

From source file:edgeserver.Publicador.java

private void publicaDado(Sensor sensor) throws Exception {
    // make sure cookies is turn on
    CookieHandler.setDefault(new CookieManager());

    HTTPClient http = new HTTPClient();

    List<NameValuePair> postp = new ArrayList<>();
    postp.add(new BasicNameValuePair("login", "huberto"));
    postp.add(new BasicNameValuePair("password", "99766330"));

    http.sendPost(this.urlLogin, postp);

    sensor.updateDado();/* w  ww  .j  a  va2 s .  c  om*/

    List<NameValuePair> GatewayParams = new ArrayList<>();
    GatewayParams
            .add(new BasicNameValuePair("publicacao_servidorborda", Integer.toString(this.ServidorBordaID)));
    GatewayParams.add(new BasicNameValuePair("publicacao_sensor", Integer.toString(sensor.getId())));
    GatewayParams.add(new BasicNameValuePair("publicacao_datacoleta",
            new Timestamp(this.datapublicacao.getTime()).toString()));
    GatewayParams.add(new BasicNameValuePair("publicacao_datapublicacao",
            new Timestamp(this.datapublicacao.getTime()).toString()));
    GatewayParams.add(new BasicNameValuePair("publicacao_valorcoletado", Float.toString(sensor.getDado())));

    String result = http.GetPageContent(this.urlInsertDado, GatewayParams);
}

From source file:hanulhan.cas.client.CasRestActions.java

public String doLogoutCasUser() {

    jsonStatus = new JsonStatus();
    CookieHandler.setDefault(new CookieManager());
    StringBuilder myResult;//w w w .  j  a va  2s  . c  o  m
    return SUCCESS;
}

From source file:hudson.plugins.sitemonitor.SiteMonitorRecorder.java

/**
 * Performs the web site monitoring by checking the response code of the site's URL.
 * /*from w ww.  j  av a  2 s . co m*/
 * @param build
 *            the build
 * @param launcher
 *            the launcher
 * @param listener
 *            the listener
 * @return true if all sites give success response codes, false otherwise
 * @throws InterruptedException
 *             when there's an interruption
 * @throws IOException
 *             when there's an IO error
 */
@Override
public final boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
        final BuildListener listener) throws InterruptedException, IOException {
    List<Result> results = new ArrayList<Result>();
    SiteMonitorDescriptor descriptor = (SiteMonitorDescriptor) getDescriptor();

    if (CookieHandler.getDefault() == null) {
        CookieHandler.setDefault(new CookieManager());
    }

    boolean hasFailure = false;
    for (Site site : mSites) {

        Integer responseCode = null;
        Status status;
        String note = "";
        HttpURLConnection connection = null;

        try {
            connection = getConnection(site.getUrl());

            if (site.getTimeout() != null) {
                connection.setConnectTimeout(site.getTimeout() * MILLISECS_IN_SECS);
            } else {
                connection.setConnectTimeout(descriptor.getTimeout() * MILLISECS_IN_SECS);
            }

            responseCode = connection.getResponseCode();

            List<Integer> successResponseCodes = descriptor.getSuccessResponseCodes();

            if (site.getSuccessResponseCodes() != null && site.getSuccessResponseCodes().size() > 0) {
                successResponseCodes = site.getSuccessResponseCodes();
            }

            if (successResponseCodes.contains(responseCode)) {
                status = Status.UP;
            } else {
                status = Status.ERROR;
            }
        } catch (SocketTimeoutException ste) {
            listener.getLogger().println(ste + " - " + ste.getMessage());
            status = Status.DOWN;
        } catch (Exception e) {
            note = e + " - " + e.getMessage();
            listener.getLogger().println(note);
            status = Status.EXCEPTION;
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }

        note = "[" + status + "] " + note;
        listener.getLogger()
                .println(Messages.SiteMonitor_Console_URL() + site.getUrl() + ", "
                        + Messages.SiteMonitor_Console_ResponseCode() + responseCode + ", "
                        + Messages.SiteMonitor_Console_Status() + status);

        if (!hasFailure && status != Status.UP) {
            hasFailure = true;
        }

        Result result = new Result(site, responseCode, status, note);
        results.add(result);
    }

    build.addAction(new SiteMonitorRootAction(results));
    hudson.model.Result result;
    if (hasFailure) {
        result = hudson.model.Result.FAILURE;
    } else {
        result = hudson.model.Result.SUCCESS;
    }
    build.setResult(result);

    // the return value is not used when this class implements a Recorder,
    // it's left here just in case this class switches to a Builder.
    // http://n4.nabble.com/how-can-a-Recorder-mark-build-as-failure-td1746654.html
    return !hasFailure;
}

From source file:org.zaproxy.zap.spider.Spider.java

/**
 * Instantiates a new spider.//from w w  w  . java  2 s . c o  m
 *
 * @param extension the extension
 * @param spiderParam the spider param
 * @param connectionParam the connection param
 * @param model the model
 * @param scanContext if a scan context is set, only URIs within the context are fetched and processed
 */
public Spider(ExtensionSpider extension, SpiderParam spiderParam, ConnectionParam connectionParam, Model model,
        Context scanContext) {
    super();
    log.info("Spider initializing...");
    this.spiderParam = spiderParam;
    this.connectionParam = connectionParam;
    this.model = model;
    this.controller = new SpiderController(this, extension.getCustomParsers());
    this.listeners = new LinkedList<>();
    this.seedList = new ArrayList<>();
    this.cookieManager = new CookieManager();
    this.scanContext = scanContext;
    this.extension = extension;

    init();
}

From source file:com.example.android.networkconnect.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //View fechview= findViewById(R.id.fetch_action);

    // CookieManager cookieManager = new CookieManager();
    CookieHandler.setDefault(new CookieManager());

    View UsbBouton = findViewById(R.id.usb_item);

    this.setContentView(R.layout.mainlayout);

    mfragment_nom = getIntent().getStringExtra("fragment");
    setupFragments();//from   www  .  j  a  v  a2s.c  om

    showFragment(mbureauFragment);

    //SensorActivity sa;

    //jsonobjet
    //initialisation de la boite de dialog login
    DialogFragment mLoginDialog = new LoginDialog();
    mLoginDialog.show(getSupportFragmentManager(), "LoginDialog");

}