Example usage for org.apache.http.client.protocol ClientContext COOKIE_STORE

List of usage examples for org.apache.http.client.protocol ClientContext COOKIE_STORE

Introduction

In this page you can find the example usage for org.apache.http.client.protocol ClientContext COOKIE_STORE.

Prototype

String COOKIE_STORE

To view the source code for org.apache.http.client.protocol ClientContext COOKIE_STORE.

Click Source Link

Document

Attribute name of a org.apache.http.client.CookieStore object that represents the actual cookie store.

Usage

From source file:net.giovannicapuano.galax.util.Utils.java

/**
 * Perform a HTTP GET request./*from w  w  w .j ava  2  s  . c o  m*/
 */
public static HttpData get(String path, Context context) {
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);

    int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    String body = "";

    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    HttpContext localContext = new BasicHttpContext();

    localContext.setAttribute(ClientContext.COOKIE_STORE, new PersistentCookieStore(context));
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());

    try {
        HttpGet httpGet = new HttpGet(context.getString(R.string.server) + path);
        HttpResponse response = httpClient.execute(httpGet, localContext);

        status = response.getStatusLine().getStatusCode();
        body = EntityUtils.toString(response.getEntity());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return new HttpData(status, body);
}

From source file:org.s1.testing.httpclient.TestHttpClient.java

/**
 *
 * @param schema/*from  ww  w.jav a2  s  . c  o  m*/
 * @param host
 * @param port
 */
public TestHttpClient(String schema, String host, int port) {
    //System.setProperty("javax.net.debug", "ssl");
    this.client = new DefaultHttpClient();
    this.context = new BasicHttpContext();
    this.host = new HttpHost(host, port, schema);

    CookieStore cookieStore = new BasicCookieStore();
    context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:com.subgraph.vega.internal.http.requests.HttpRequestEngine.java

@Override
public IHttpResponse sendRequest(HttpUriRequest request, HttpContext context) throws RequestEngineException {
    final HttpContext requestContext = (context == null) ? (new BasicHttpContext()) : (context);
    requestContext.setAttribute(ClientContext.COOKIE_STORE, config.getCookieStore());
    Future<IHttpResponse> future = executor
            .submit(new RequestTask(client, rateLimit, request, requestContext, config, htmlParser));
    try {/*from   w  w  w  .jav a  2 s.c om*/
        return future.get();
    } catch (InterruptedException e) {
        logger.info("Request " + request.getURI() + " was interrupted before completion");
    } catch (ExecutionException e) {
        throw translateException(request, e.getCause());
    }
    return null;
}

From source file:org.mobicents.slee.ra.httpclient.nio.ra.HttpClientNIORequestActivityImpl.java

private HttpContext processHttpContext(HttpContext context) {
    // Maintains HttpSession on server side
    if (context == null) {
        context = new BasicHttpContext();

    }/*  ww w.j  av a  2 s  .c o  m*/
    if (context.getAttribute(ClientContext.COOKIE_STORE) == null) {
        BasicCookieStore cookieStore = new BasicCookieStore();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    }
    return context;
}

From source file:vee.vee.string.downloader.StringDownloader.java

/**
 * <b>Details: </b> Pass <b>Activity</b>, DO NOT pass <b><i>context</i></b>.<br>
 *
 * @param Activity activity/*from   ww w.j  a v a  2 s.  co m*/
 * @param <b>boolean</b> debug
 */
public StringDownloader(Activity activity, boolean debug) {
    this.activity = activity;
    this.debug = debug;
    mCookieJar.getLocalContext().setAttribute(ClientContext.COOKIE_STORE, mCookieJar.getCookieStore());
}

From source file:biz.mosil.webtools.MosilWeb.java

/**
 * Setting Cookie//from w  w w.ja  v  a  2  s.co m
 * @param _cookie
 * */
public MosilWeb setCookie(BasicCookieStore _cookie) {
    mHttpContext.setAttribute(ClientContext.COOKIE_STORE, _cookie);
    return this;
}

From source file:org.mobicents.client.slee.resource.http.HttpClientResourceAdaptorSbbInterfaceImpl.java

@Override
public HttpClientActivity createHttpClientActivity(boolean endOnReceivingResponse, HttpContext context)
        throws StartActivityException {

    if (tracer.isFinestEnabled()) {
        tracer.finest("createHttpClientActivity(endOnReceivingResponse=" + endOnReceivingResponse + ",context="
                + context + ")");
    }//from   ww w .  ja  va2 s  .  c  om

    if (!this.ra.isActive) {
        throw new IllegalStateException("ra is not in active state");
    }

    // Maintain HttpSession on server side
    if (context == null) {
        context = new BasicHttpContext();

    }
    if (context.getAttribute(ClientContext.COOKIE_STORE) == null) {
        BasicCookieStore cookieStore = new BasicCookieStore();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    }

    HttpClientActivity activity = new HttpClientActivityImpl(this.ra, endOnReceivingResponse, context);

    HttpClientActivityHandle handle = new HttpClientActivityHandle(activity.getSessionId());

    // this happens with a tx context
    this.ra.getResourceAdaptorContext().getSleeEndpoint().startActivitySuspended(handle, activity,
            ACTIVITY_FLAGS);

    this.ra.addActivity(handle, activity);

    if (tracer.isFineEnabled()) {
        tracer.fine("Started activity " + activity.getSessionId() + ", context is " + context
                + ", endOnReceivingResponse is " + endOnReceivingResponse);
    }

    return activity;
}

From source file:fedroot.dacs.http.DacsClientContext.java

public DacsClientContext(HttpParams httpParams) {

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    ClientConnectionManager cm = new ThreadSafeClientConnManager(schemeRegistry);
    if (httpParams.getParameter(ClientPNames.COOKIE_POLICY) == null) {
        httpParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
    }//from   w w  w  . j a  v a 2  s  .  c  om
    httpClient = new DefaultHttpClient(cm, httpParams);

    cookieStore = new BasicCookieStore();
    httpContext = new BasicHttpContext();
    // Bind custom cookie store to the local context
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:com.citrix.g2w.webdriver.util.FileDownloader.java

public String downloader(String fileToDownloadLocation, String localDownloadPath)
        throws IOException, URISyntaxException {
    URL fileToDownload = new URL(fileToDownloadLocation);
    String fileNameURI = fileToDownload.getFile();
    String filePath = "";
    if (fileNameURI.contains("?")) {
        filePath = localDownloadPath//  w w w.ja  v  a2s. c o  m
                + fileNameURI.substring(fileNameURI.substring(0, fileNameURI.indexOf("?")).lastIndexOf("/") + 1,
                        fileNameURI.indexOf("?"));
    } else {
        filePath = localDownloadPath + fileNameURI.substring(fileNameURI.lastIndexOf("/") + 1);
    }
    File downloadedFile = new File(filePath);
    if (downloadedFile.canWrite() == false) {
        downloadedFile.setWritable(true);
    }

    HttpClient client = new DefaultHttpClient();
    BasicHttpContext localContext = new BasicHttpContext();

    if (this.mimicWebDriverCookieState) {
        localContext.setAttribute(ClientContext.COOKIE_STORE,
                this.mimicCookieState(this.driver.manage().getCookies()));
    }

    HttpGet httpget = new HttpGet(fileToDownload.toURI());
    HttpParams httpRequestParameters = httpget.getParams();
    httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
    httpget.setParams(httpRequestParameters);

    HttpResponse response = client.execute(httpget, localContext);

    FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile);
    response.getEntity().getContent().close();

    String downloadedFileAbsolutePath = downloadedFile.getAbsolutePath();
    this.logger.log("File downloaded to '" + downloadedFileAbsolutePath + "'");

    return downloadedFileAbsolutePath;
}

From source file:com.janoz.usenet.processors.impl.WebbasedProcessor.java

public WebbasedProcessor() {
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(CookieSpecPNames.DATE_PATTERNS,
            Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd MMM yyyy HH:mm:ss z"));
    httpClient = new DefaultHttpClient(params);
    cookieStore = new BasicCookieStore();
    context = new BasicHttpContext();
    context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}