List of usage examples for org.apache.http.client CookieStore addCookie
void addCookie(Cookie cookie);
From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java
static boolean onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { final BearerAuthenticator ba = ourAuthenticators.get(activity); boolean processed = true; try {/*from w w w . j av a2 s.c om*/ switch (requestCode) { default: processed = false; break; case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER: if (resultCode == Activity.RESULT_OK && data != null) { ba.myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); } break; case NetworkLibraryActivity.REQUEST_AUTHORISATION: if (resultCode == Activity.RESULT_OK) { ba.myAuthorizationConfirmed = true; } break; case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN: if (resultCode == Activity.RESULT_OK && data != null) { final CookieStore store = ZLNetworkManager.Instance().cookieStore(); final Map<String, String> cookies = (Map<String, String>) data .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY); if (cookies != null) { for (Map.Entry<String, String> entry : cookies.entrySet()) { final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue()); c.setDomain(data.getData().getHost()); c.setPath("/"); final Calendar expire = Calendar.getInstance(); expire.add(Calendar.YEAR, 1); c.setExpiryDate(expire.getTime()); c.setSecure(true); c.setDiscard(false); store.addCookie(c); } } } break; } } finally { if (processed) { synchronized (ba) { ba.notifyAll(); } } return processed; } }
From source file:fr.ippon.wip.http.hc.LtpaRequestInterceptor.java
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { PortletRequest portletRequest = HttpClientResourceManager.getInstance().getCurrentPortletRequest(); PortletWindow windowState = PortletWindow.getInstance(portletRequest); WIPConfiguration wipConfig = WIPUtil.getConfiguration(portletRequest); // If it is the first request if (windowState.getActualURL() == null) { // If LTPA SSO enabled for this portlet if (wipConfig.isLtpaSsoAuthentication()) { // Create LTPA cookie & add it ot store String[] valueAndDomain = LtpaCookieUtil.getCookieValueAndDomain(portletRequest, wipConfig); if (valueAndDomain != null) { BasicClientCookie ltpaCookie = new BasicClientCookie(LtpaCookieUtil.COOKIE_NAME, valueAndDomain[0]); if (valueAndDomain[1] != null && !valueAndDomain[1].equals("")) { ltpaCookie.setDomain(valueAndDomain[1]); }// w w w . j ava 2 s .c om CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE); cookieStore.addCookie(ltpaCookie); } } } }
From source file:com.phonty.improved.Sms.java
public Sms(String url, Context _context) { context = _context;//w ww . j a va2 s . c o m APIURL = url; httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); }
From source file:com.phonty.improved.DirectionCost.java
public DirectionCost(String url, Context _context) { context = _context;/*w w w.j a v a 2s. c om*/ BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); APIURL = url; httppost = new HttpPost(APIURL); }
From source file:org.herrlado.engeo.Utils.java
/** * Get a fresh HTTP-Connection.//from w w w . j a v a2s .c o m * * @param url * URL to open * @param cookies * cookies to transmit * @param postData * post data * @param userAgent * user agent * @param referer * referer * @param encoding * encoding; default encoding: ISO-8859-15 * @param trustAll * trust all SSL certificates; only used on first call! * @param knownFingerprints * fingerprints that are known to be valid; only used on first * call! Only used if {@code trustAll == false} * @return the connection * @throws IOException * IOException */ private static HttpResponse getHttpClient(final String url, final ArrayList<Cookie> cookies, final ArrayList<BasicNameValuePair> postData, final String userAgent, final String referer, final String encoding, final boolean trustAll, final String... knownFingerprints) throws IOException { Log.d(TAG, "HTTPClient URL: " + url); SchemeRegistry registry = null; if (httpClient == null) { if (trustAll || (// . knownFingerprints != null && // . knownFingerprints.length > 0)) { registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), PORT_HTTP)); // final FakeSocketFactory httpsSocketFactory; // if (trustAll) { // httpsSocketFactory = new FakeSocketFactory(); // } else { // httpsSocketFactory = new FakeSocketFactory( // knownFingerprints); // } // registry.register(new Scheme("https", httpsSocketFactory, // PORT_HTTPS)); HttpParams params = new BasicHttpParams(); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, registry), params); } else { httpClient = new DefaultHttpClient(); } httpClient.addResponseInterceptor(new HttpResponseInterceptor() { @Override public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); Header contentEncodingHeader = entity.getContentEncoding(); if (contentEncodingHeader != null) { HeaderElement[] codecs = contentEncodingHeader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase(GZIP)) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } }); } if (cookies != null && cookies.size() > 0) { final int l = cookies.size(); CookieStore cs = httpClient.getCookieStore(); for (int i = 0; i < l; i++) { cs.addCookie(cookies.get(i)); } } Log.d(TAG, getCookies(httpClient)); HttpRequestBase request; if (postData == null) { request = new HttpGet(url); } else { HttpPost pr = new HttpPost(url); if (encoding != null && encoding.length() > 0) { pr.setEntity(new UrlEncodedFormEntity(postData, encoding)); } else { pr.setEntity(new UrlEncodedFormEntity(postData, "ISO-8859-15")); } // Log.d(TAG, "HTTPClient POST: " + postData); request = pr; } request.addHeader(ACCEPT_ENCODING, GZIP); if (referer != null) { request.setHeader("Referer", referer); // Log.d(TAG, "HTTPClient REF: " + referer); } if (userAgent != null) { request.setHeader("User-Agent", userAgent); // Log.d(TAG, "HTTPClient AGENT: " + userAgent); } // Log.d(TAG, getHeaders(request)); return httpClient.execute(request); }
From source file:org.tellervo.desktop.wsi.util.WSCookieStore.java
public CookieStore toCookieStore() { CookieStore cs = new BasicCookieStore(); for (Entry<String, WSCookieWrapper> c : cookies.entrySet()) cs.addCookie(c.getValue().toApacheCookie()); return cs;/*w w w . j a v a2s. c o m*/ }
From source file:com.phonty.improved.Balance.java
public String get() { StringBuilder builder = new StringBuilder(); String value = "0"; CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore);/*www. j a v a 2 s . c o m*/ try { String locale = context.getResources().getConfiguration().locale.getCountry(); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("locale", locale)); httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = client.execute(httppost); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); value = Parse(line); this.VALUE = value; } } else { this.VALUE = "0.0"; } } catch (ClientProtocolException e) { this.VALUE = "0.0"; e.printStackTrace(); } catch (IOException e) { this.VALUE = "0.0"; e.printStackTrace(); } return value; }
From source file:com.phonty.improved.Calls.java
public Calls(String url, Context _context) { context = _context;/*from w w w. ja v a 2 s. co m*/ APIURL = url; httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); VALUES = new ArrayList<CallItem>(); type = "Calls:"; }
From source file:com.phonty.improved.Rates.java
public Rates(String url, Context _context) { context = _context;/*ww w . j a v a 2s. co m*/ APIURL = url; httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); VALUES = new ArrayList<PriceItem>(); type = "Calls:"; }
From source file:com.phonty.improved.Contacts.java
public Contacts(String url, Context _context) { context = _context;// ww w. ja va 2 s .com APIURL = url; httppost = new HttpPost(APIURL); httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\""); BasicHttpParams params = new BasicHttpParams(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); schemeRegistry.register(new Scheme("https", sslSocketFactory, 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); client = new PhontyHttpClient(cm, params, context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client"); CookieStore cookieStore = new BasicCookieStore(); cookieStore.addCookie(Login.SESSION_COOKIE); client.setCookieStore(cookieStore); }