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:edu.richmond.bannerweb.NetworkManager.java

public NetworkManager() {
    //Bannerweb requires cookie handling, so we have to do all this stuff!
    mCookieStore = new BasicCookieStore();
    mLocalContext = new BasicHttpContext();
    mLocalContext.setAttribute(ClientContext.COOKIE_STORE, mCookieStore);

    mHttpClient = new DefaultHttpClient();

    //We also need to make an initial GET to the Bannerweb login page (To get the cookies).
    getInitialCookies();/*from  www .  j  a v a2  s  .  co m*/
}

From source file:com.cybussolutions.wikki.afri_pay.Networking.CheckAmount.java

@Override
protected String doInBackground(String... params) {

    LoginActivity.currentSession.authhttpClient = new DefaultHttpClient();
    HttpContext ctx = new BasicHttpContext();
    ctx.setAttribute(ClientContext.COOKIE_STORE, LoginActivity.currentSession.cookieStore);
    LoginActivity.currentSession.httppost = new HttpPost(
            LoginActivity.currentSession.base_url + "compliance/checkComplianceForTrans/");
    List<BasicNameValuePair> nameValuePairs = new ArrayList<>();
    String id = LoginActivity.currentSession.newProfile.getUserID();
    String sending = LoginActivity.currentSession.newProfile.getCountryID();
    nameValuePairs.add(new BasicNameValuePair("transAmount", params[0]));
    nameValuePairs.add(new BasicNameValuePair("localAmount", params[1]));
    nameValuePairs.add(new BasicNameValuePair("totalAmount", params[2]));
    nameValuePairs.add(new BasicNameValuePair("origenCountry", sending));
    nameValuePairs.add(new BasicNameValuePair("destCountry", params[3]));
    nameValuePairs.add(new BasicNameValuePair("action", "send"));
    nameValuePairs.add(new BasicNameValuePair("originCYY", params[4]));
    nameValuePairs.add(new BasicNameValuePair("destCYY", params[5]));
    nameValuePairs.add(new BasicNameValuePair("customerID", id));

    try {/*from   ww  w.  jav  a  2 s  .c  o  m*/
        LoginActivity.currentSession.httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        responsebody = LoginActivity.currentSession.authhttpClient
                .execute(LoginActivity.currentSession.httppost, ctx);
        responseString = new BasicResponseHandler().handleResponse(responsebody);

        if (responseString.equals("1")) {

            return "1";
        }

        else if (responseString.equals("nodocuments%")) {
            String complience;
            complience = "Documents Needed to Proceed this transaction";

            return complience;
        }

        else if (responseString.equals("nodocuments%\n"
                + " Message: Docs Needed Please Go back to manage Documents to Upload missing documents. \n"
                + "Documents Need : Passport OR Driver License - Source of Funds - ")) {

            message = responseString.split("%");

        }

        else {
            message = responseString.split("%");
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "Exception";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "Exception";
    }
    if (responseString.contains("unable to allocate memory for pool") && responseString == null) {

        return "Exception";
    }
    if (responseString.contains("logout")) {
        return "Exception";
    }
    return message[1];
}

From source file:eu.masconsult.bgbanking.utils.CookieQuotesFixerResponseInterceptor.java

@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
    CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
    for (Header header : response.getAllHeaders()) {
        if (!header.getName().equalsIgnoreCase("Set-Cookie")) {
            continue;
        }//from   www .  ja v  a 2 s . c  o  m
        Matcher matcher = pattern.matcher(header.getValue());
        if (!matcher.find()) {
            continue;
        }
        for (Cookie cookie : cookieStore.getCookies()) {
            if (cookie.getName().equalsIgnoreCase(matcher.group(1))) {
                if (cookie instanceof BasicClientCookie) {
                    ((BasicClientCookie) cookie).setValue('"' + cookie.getValue() + '"');
                } else if (cookie instanceof BasicClientCookie2) {
                    ((BasicClientCookie2) cookie).setValue('"' + cookie.getValue() + '"');
                } else {
                    Log.w(TAG, "unhandled cookie implementation " + cookie.getClass().getName());
                }
                break;
            }
        }
    }
}

From source file:com.aurel.track.master.ModuleBL.java

public static Cookie sendPOSTRequest(String urlString) {
    Cookie responseCookie = null;//ww  w.j av a 2 s . c  o m
    try {
        HttpClient httpclient = new DefaultHttpClient();//HttpClients.createDefault();
        HttpPost httppost = new HttpPost(urlString);
        // Request parameters and other properties.
        //Execute and get the response.
        HttpContext localContext = new BasicHttpContext();
        CookieStore cookieStore = new BasicCookieStore();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        HttpResponse response = httpclient.execute(httppost, localContext);

        if (cookieStore.getCookies().size() > 0) {
            List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies();
            for (org.apache.http.cookie.Cookie cookie : cookies) {
                if (cookie.getName().equals("JSESSIONID")) {
                    responseCookie = new Cookie(cookie.getName(), cookie.getValue());
                    responseCookie.setPath(cookie.getPath());
                    responseCookie.setDomain(cookie.getDomain());
                }
            }
        }
        if (response.getEntity() != null) {
            response.getEntity().consumeContent();
        }

    } catch (Exception ex) {
        LOGGER.debug(ExceptionUtils.getStackTrace(ex));
    }
    return responseCookie;
}

From source file:hu.sztaki.lpds.dcibridge.util.io.HttpHandler.java

public void open(String pURL) {

    httpclient = new DefaultHttpClient();
    cookieStore = new BasicCookieStore();
    localContext = new BasicHttpContext();
    httpPost = new HttpPost(pURL.trim());
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    /*//from  www  .j  ava2  s .  co  m
            URL n=new URL(pURL);
            httpclient.getCredentialsProvider().setCredentials(
            new AuthScope(n.getHost(),n.getPort()), 
            new UsernamePasswordCredentials("guse", "guse"));        
     */
}

From source file:info.ajaxplorer.client.http.AjxpHttpClient.java

public AjxpHttpClient(boolean trustSSL) {
    super();// w w w  . j av  a2 s .co  m
    this.trustSelfSignedSSL = trustSSL;
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    this.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
}

From source file:com.strato.hidrive.api.HttpClientManager.java

public HttpContext getLocalHttpContext() {
    if (localHttpContext == null) {
        CookieStore cookieStore = new BasicCookieStore();
        HttpContext localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    }// w  w w  .j a  va 2s. c  om
    return localHttpContext;
}

From source file:hu.sztaki.lpds.portal.util.stream.HttpClient.java

/**
 * Opening the connection//from   w w  w  . j  a v a 2 s.c om
 * @param pURL resource URL
 */
public void open(String pURL) {
    httpclient = new DefaultHttpClient();
    cookieStore = new BasicCookieStore();
    localContext = new BasicHttpContext();
    httpPost = new HttpPost(pURL);
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}

From source file:org.semanticscience.PDBAptamerRetriever.shared.URLReader.java

public URLReader(String scheme, String host, String path, String query) {
    cookieStore = new BasicCookieStore();
    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    contents = this.getStringFromURLGET(scheme, host, path, query);

}

From source file:com.googlecode.noweco.webmail.httpclient.UnsecureResponseProcessCookies.java

public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }//from w ww  .j av a2s .  c  o m
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }

    // Obtain actual CookieSpec instance
    CookieSpec cookieSpec = (CookieSpec) context.getAttribute(ClientContext.COOKIE_SPEC);
    if (cookieSpec == null) {
        this.log.debug("Cookie spec not specified in HTTP context");
        return;
    }
    // Obtain cookie store
    CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
    if (cookieStore == null) {
        this.log.debug("Cookie store not specified in HTTP context");
        return;
    }
    // Obtain actual CookieOrigin instance
    CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(ClientContext.COOKIE_ORIGIN);
    if (cookieOrigin == null) {
        this.log.debug("Cookie origin not specified in HTTP context");
        return;
    }
    HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
    processCookies(it, cookieSpec, cookieOrigin, cookieStore);

    // see if the cookie spec supports cookie versioning.
    if (cookieSpec.getVersion() > 0) {
        // process set-cookie2 headers.
        // Cookie2 will replace equivalent Cookie instances
        it = response.headerIterator(SM.SET_COOKIE2);
        processCookies(it, cookieSpec, cookieOrigin, cookieStore);
    }
}