Java Code Examples for org.apache.http.impl.cookie.BasicClientCookie#setVersion()
The following examples show how to use
org.apache.http.impl.cookie.BasicClientCookie#setVersion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSDNLoginApater.java From crawler-jsoup-maven with Apache License 2.0 | 6 votes |
public static void setCookieStore(HttpResponse httpResponse) { System.out.println("----setCookieStore"); cookieStore = new BasicCookieStore(); // JSESSIONID String setCookie = httpResponse.getFirstHeader("Set-Cookie") .getValue(); String JSESSIONID = setCookie.substring("JSESSIONID=".length(), setCookie.indexOf(";")); System.out.println("JSESSIONID:" + JSESSIONID); // 新建一个Cookie BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", JSESSIONID); cookie.setVersion(0); //cookie.setDomain("127.0.0.1"); //cookie.setPath("/CwlProClient"); // cookie.setAttribute(ClientCookie.VERSION_ATTR, "0"); // cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "127.0.0.1"); // cookie.setAttribute(ClientCookie.PORT_ATTR, "8080"); // cookie.setAttribute(ClientCookie.PATH_ATTR, "/CwlProWeb"); cookieStore.addCookie(cookie); }
Example 2
Source File: ZdsHttp.java From zest-writer with GNU General Public License v3.0 | 6 votes |
/** * Authentication with google account * @param cookies cookies list keys from google auth * @param login username associated to zds login * @param id user id on ZdS associated to login */ public void authToGoogle(List<HttpCookie> cookies, String login, String id) { if(login != null && id != null) { this.login = login; this.idUser = id; log.info("L'identifiant de l'utilisateur " + this.login + " est : " + idUser); cookieStore = new BasicCookieStore(); for(HttpCookie cookie:cookies) { BasicClientCookie c = new BasicClientCookie(cookie.getName(), cookie.getValue()); c.setDomain(cookie.getDomain()); c.setPath(cookie.getPath()); c.setSecure(cookie.getSecure()); c.setVersion(cookie.getVersion()); c.setComment(cookie.getComment()); cookieStore.addCookie(c); } context.setCookieStore(cookieStore); this.authenticated = true; } else { log.debug("Le login de l'utilisateur n'a pas pu être trouvé"); } }
Example 3
Source File: CookieHttpClientFactory.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override public DefaultHttpClient create(final HttpMethod method, final URI uri) { final CookieStore cookieStore = new BasicCookieStore(); // Populate cookies if needed final BasicClientCookie cookie = new BasicClientCookie("name", "value"); cookie.setVersion(0); cookie.setDomain(".mycompany.com"); cookie.setPath("/"); cookieStore.addCookie(cookie); final DefaultHttpClient httpClient = super.create(method, uri); httpClient.setCookieStore(cookieStore); return httpClient; }
Example 4
Source File: BasicHttpSolrClientTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { BasicClientCookie cookie = new BasicClientCookie(cookieName, cookieValue); cookie.setVersion(0); cookie.setPath("/"); cookie.setDomain(jetty.getBaseUrl().getHost()); CookieStore cookieStore = new BasicCookieStore(); CookieSpec cookieSpec = new SolrPortAwareCookieSpecFactory().create(context); // CookieSpec cookieSpec = registry.lookup(policy).create(context); // Add the cookies to the request List<Header> headers = cookieSpec.formatCookies(Collections.singletonList(cookie)); for (Header header : headers) { request.addHeader(header); } context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore); }
Example 5
Source File: AsyncHttpClient.java From letv with Apache License 2.0 | 6 votes |
public static CookieStore getuCookie() { CookieStore uCookie = new BasicCookieStore(); try { String COOKIE_S_LINKDATA = LemallPlatform.getInstance().getCookieLinkdata(); if (!TextUtils.isEmpty(COOKIE_S_LINKDATA)) { String[] cookies = COOKIE_S_LINKDATA.split("&"); for (String item : cookies) { String[] keyValue = item.split(SearchCriteria.EQ); if (keyValue.length == 2) { if (OtherUtil.isContainsChinese(keyValue[1])) { keyValue[1] = URLEncoder.encode(keyValue[1], "UTF-8"); } BasicClientCookie cookie = new BasicClientCookie(keyValue[0], keyValue[1]); cookie.setVersion(0); cookie.setDomain(".lemall.com"); cookie.setPath("/"); uCookie.addCookie(cookie); } } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return uCookie; }
Example 6
Source File: SerializableCookie.java From android-project-wo2b with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 7
Source File: SerializableCookie.java From bither-android with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 8
Source File: cfHttpConnection.java From openbd-core with GNU General Public License v3.0 | 5 votes |
private void addCookies() { Map<String, List<String>> cookies = httpData.getCookies(); Iterator<String> keys = cookies.keySet().iterator(); String domain = ""; domain = message.getURI().getHost(); CookieStore cookieStore = new BasicCookieStore(); HttpContext localContext = new BasicHttpContext(); // Bind custom cookie store to the local context localContext.setAttribute( ClientContext.COOKIE_STORE, cookieStore ); client.getParams().setParameter( ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY ); while ( keys.hasNext() ) { String nextKey = keys.next(); List<String> values = cookies.get( nextKey ); Date date = new Date( 2038, 1, 1 ); for ( int i = 0; i < values.size(); i++ ) { BasicClientCookie cookie = new BasicClientCookie( nextKey, values.get( i ) ); cookieStore.addCookie( cookie ); cookie.setVersion( 1 ); cookie.setDomain( domain ); cookie.setPath( "/" ); cookie.setExpiryDate( date ); cookie.setSecure( false ); } } client.setCookieStore( cookieStore ); }
Example 9
Source File: PreferencesCookieStore.java From android-open-project-demo with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 10
Source File: SerializableCookie.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 11
Source File: PreferencesCookieStore.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String)in.readObject(); String value = (String)in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String)in.readObject()); clientCookie.setDomain((String)in.readObject()); clientCookie.setExpiryDate((Date)in.readObject()); clientCookie.setPath((String)in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 12
Source File: SerializableCookie.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 13
Source File: SerializableCookie.java From bither-desktop-java with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 14
Source File: FusionPipelineClient.java From storm-solr with Apache License 2.0 | 5 votes |
protected synchronized void clearCookieForHost(String sessionHost) throws Exception { Cookie sessionCookie = null; for (Cookie cookie : cookieStore.getCookies()) { String cookieDomain = cookie.getDomain(); if (cookieDomain != null) { if (sessionHost.equals(cookieDomain) || sessionHost.indexOf(cookieDomain) != -1 || cookieDomain.indexOf(sessionHost) != -1) { sessionCookie = cookie; break; } } } if (sessionCookie != null) { BasicClientCookie httpCookie = new BasicClientCookie(sessionCookie.getName(),sessionCookie.getValue()); httpCookie.setExpiryDate(new Date(0)); httpCookie.setVersion(1); httpCookie.setPath(sessionCookie.getPath()); httpCookie.setDomain(sessionCookie.getDomain()); cookieStore.addCookie(httpCookie); } cookieStore.clearExpired(new Date()); // this should clear the cookie }
Example 15
Source File: SerializableCookie.java From Roid-Library with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 16
Source File: PreferencesCookieStore.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 17
Source File: SerializableCookie.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { String name = (String) in.readObject(); String value = (String) in.readObject(); clientCookie = new BasicClientCookie(name, value); clientCookie.setComment((String) in.readObject()); clientCookie.setDomain((String) in.readObject()); clientCookie.setExpiryDate((Date) in.readObject()); clientCookie.setPath((String) in.readObject()); clientCookie.setVersion(in.readInt()); clientCookie.setSecure(in.readBoolean()); }
Example 18
Source File: Checkin.java From Mobilyzer with Apache License 2.0 | 5 votes |
/** Return a fake authentication cookie for a test server instance */ private Cookie getFakeAuthCookie() { BasicClientCookie cookie = new BasicClientCookie( "dev_appserver_login", "[email protected]:False:185804764220139124118"); cookie.setDomain(".google.com"); cookie.setVersion(1); cookie.setPath("/"); cookie.setSecure(false); return cookie; }
Example 19
Source File: MyCookieDBManager.java From Huochexing12306 with Apache License 2.0 | 5 votes |
public List<Cookie> getAllCookies() { List<Cookie> cookies = new ArrayList<Cookie>(); Cursor cursor = db .query(TABLE_NAME, null, null, null, null, null, null); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { String name = cursor.getString(cursor.getColumnIndex(Column.NAME)); String value = cursor .getString(cursor.getColumnIndex(Column.VALUE)); BasicClientCookie cookie = new BasicClientCookie(name, value); cookie.setComment(cursor.getString(cursor .getColumnIndex(Column.COMMENT))); cookie.setDomain(cursor.getString(cursor .getColumnIndex(Column.DOMAIN))); long expireTime = cursor.getLong(cursor .getColumnIndex(Column.EXPIRY_DATE)); if (expireTime != 0) { cookie.setExpiryDate(new Date(expireTime)); } cookie.setPath(cursor.getString(cursor.getColumnIndex(Column.PATH))); cookie.setSecure(cursor.getInt(cursor.getColumnIndex(Column.SECURE)) == 1); cookie.setVersion(cursor.getInt(cursor .getColumnIndex(Column.VERSION))); cookies.add(cookie); } cursor.close(); return cookies; }
Example 20
Source File: DefaultCookieManager.java From esigate with Apache License 2.0 | 4 votes |
protected static Cookie rewriteForBrowser(Cookie cookie, DriverRequest request) { String name = cookie.getName(); // Rewrite name if JSESSIONID because it will interfere with current // server session if ("JSESSIONID".equalsIgnoreCase(name)) { name = "_" + name; } // Rewrite domain String domain = rewriteDomain(cookie.getDomain(), request.getBaseUrl().getHost(), UriUtils.extractHostName(request.getOriginalRequest().getRequestLine().getUri())); // Rewrite path String originalPath = cookie.getPath(); String requestPath = UriUtils.getPath(request.getOriginalRequest().getRequestLine().getUri()); String path = originalPath; if (requestPath == null || !requestPath.startsWith(originalPath)) { path = "/"; } // Rewrite secure boolean secure = (cookie.isSecure() && request.getOriginalRequest().getRequestLine().getUri().startsWith("https")); BasicClientCookie cookieToForward = new BasicClientCookie(name, cookie.getValue()); if (domain != null) { cookieToForward.setDomain(domain); } cookieToForward.setPath(path); cookieToForward.setSecure(secure); cookieToForward.setComment(cookie.getComment()); cookieToForward.setVersion(cookie.getVersion()); cookieToForward.setExpiryDate(cookie.getExpiryDate()); if (((BasicClientCookie) cookie).containsAttribute(CookieUtil.HTTP_ONLY_ATTR)) { cookieToForward.setAttribute(CookieUtil.HTTP_ONLY_ATTR, ""); } if (LOG.isDebugEnabled()) { // Ensure .toString is only called if debug enabled. LOG.debug("Forwarding cookie {} -> {}", cookie.toString(), cookieToForward.toString()); } return cookieToForward; }