List of usage examples for org.apache.http.impl.cookie CookieSpecBase parse
protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin) throws MalformedCookieException
From source file:org.herrlado.engeo.Utils.java
/** * Update cookies from response.//from w w w .j av a2 s . c o m * * @param cookies * old {@link Cookie} list * @param headers * {@link Header}s from {@link HttpResponse} * @param url * requested URL * @throws URISyntaxException * malformed URI * @throws MalformedCookieException * malformed {@link Cookie} */ @Deprecated public static void updateCookies(final ArrayList<Cookie> cookies, final Header[] headers, final String url) throws URISyntaxException, MalformedCookieException { final URI uri = new URI(url); int port = uri.getPort(); if (port < 0) { if (url.startsWith("https")) { port = PORT_HTTPS; } else { port = PORT_HTTP; } } final CookieOrigin origin = new CookieOrigin(uri.getHost(), port, uri.getPath(), false); final CookieSpecBase cookieSpecBase = new BrowserCompatSpec(); String name; String value; for (final Header header : headers) { for (final Cookie cookie : cookieSpecBase.parse(header, origin)) { // THE cookie name = cookie.getName(); value = cookie.getValue(); if (value == null || value.equals("")) { continue; } for (final Cookie c : cookies) { if (name.equals(c.getName())) { cookies.remove(c); cookies.add(cookie); name = null; break; } } if (name != null) { cookies.add(cookie); } } } }
From source file:org.sigmond.net.AsyncHttpTask.java
protected HttpRequestInfo doInBackground(HttpRequestInfo... params) { HttpRequestInfo rinfo = params[0];/* w ww .j av a 2 s . c o m*/ try { client.setCookieStore(rinfo.getCookieStore()); //cookie handling HttpResponse resp = client.execute(rinfo.getRequest()); //execute request //store any new cookies recieved CookieStore store = rinfo.getCookieStore(); Header[] allHeaders = resp.getAllHeaders(); CookieSpecBase base = new BrowserCompatSpec(); URI uri = rinfo.getRequest().getURI(); int port = uri.getPort(); if (port <= 0) port = 80; CookieOrigin origin = new CookieOrigin(uri.getHost(), port, uri.getPath(), false); for (Header header : allHeaders) { List<Cookie> parse = base.parse(header, origin); for (Cookie cookie : parse) { if (cookie.getValue() != null && cookie.getValue() != "") store.addCookie(cookie); } } rinfo.setCookieStore(store); //store the response rinfo.setResponse(resp); //process the response string. This is required in newer Android versions. //newer versions will not allow reading from a network response input stream in the main thread. rinfo.setResponseString(HttpUtils.responseToString(resp)); } catch (Exception e) { rinfo.setException(e); } return rinfo; }