List of usage examples for java.net HttpCookie setVersion
public void setVersion(int v)
From source file:com.github.parisoft.resty.utils.CookieUtils.java
public static String toString(Cookie... cookies) { if (isEmpty(cookies)) { return null; }//from w ww . j av a2 s . co m final HttpCookie[] httpCookies = new HttpCookie[cookies.length]; for (int i = 0; i < cookies.length; i++) { final Cookie srcCookie = cookies[i]; final HttpCookie httpCookie = new HttpCookie(srcCookie.getName(), srcCookie.getValue()); httpCookie.setDomain(srcCookie.getDomain()); httpCookie.setPath(srcCookie.getPath()); httpCookie.setVersion(srcCookie.getVersion()); httpCookies[i] = httpCookie; } return toString(httpCookies); }
From source file:keywhiz.cli.JsonCookie.java
public static HttpCookie toHttpCookie(JsonCookie cookieContents) { HttpCookie cookie = new HttpCookie(cookieContents.name(), cookieContents.value()); cookie.setDomain(cookieContents.domain()); cookie.setPath(cookieContents.path()); cookie.setSecure(cookieContents.isSecure()); cookie.setHttpOnly(cookieContents.isHttpOnly()); cookie.setVersion(1); // Always set version to 1 or important fields will be dropped return cookie; }
From source file:cn.ttyhuo.common.MyApplication.java
public static void getJavaCookieStore(java.net.CookieStore jCookieStore) { if (cookieStore == null) return;//from w w w . j ava 2 s . c o m for (Cookie h : cookieStore.getCookies()) { HttpCookie newCookie = new HttpCookie(h.getName(), h.getValue()); newCookie.setVersion(h.getVersion()); newCookie.setDomain(h.getDomain()); newCookie.setPath(h.getPath()); newCookie.setSecure(h.isSecure()); newCookie.setComment(h.getComment()); jCookieStore.add(URI.create("http://" + h.getDomain()), newCookie); } }
From source file:com.github.parisoft.resty.utils.CookieUtils.java
public static String toString(org.apache.http.cookie.Cookie... cookies) { if (isEmpty(cookies)) { return null; }/*from w ww .j a va 2s. com*/ final HttpCookie[] httpCookies = new HttpCookie[cookies.length]; for (int i = 0; i < cookies.length; i++) { final org.apache.http.cookie.Cookie srcCookie = cookies[i]; final HttpCookie httpCookie = new HttpCookie(srcCookie.getName(), srcCookie.getValue()); httpCookie.setComment(srcCookie.getComment()); httpCookie.setDomain(srcCookie.getDomain()); httpCookie.setPath(srcCookie.getPath()); httpCookie.setSecure(srcCookie.isSecure()); httpCookie.setVersion(srcCookie.getVersion()); final Date now = new Date(); if (srcCookie.isExpired(now)) { httpCookie.setMaxAge(0); } else { httpCookie.setMaxAge( TimeUnit.MILLISECONDS.toSeconds(srcCookie.getExpiryDate().getTime() - now.getTime())); } httpCookies[i] = httpCookie; } return toString(httpCookies); }
From source file:interactivespaces.service.web.server.internal.netty.NettyHttpRequest.java
public static HttpCookie convertFromNettyCookie(Cookie cookie) { HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue()); httpCookie.setComment(cookie.getComment()); httpCookie.setDomain(cookie.getDomain()); httpCookie.setMaxAge(cookie.getMaxAge()); httpCookie.setPath(cookie.getPath()); httpCookie.setPortlist(createPortString(cookie.getPorts())); httpCookie.setVersion(cookie.getVersion()); httpCookie.setSecure(cookie.isSecure()); httpCookie.setDiscard(cookie.isDiscard()); return httpCookie; }
From source file:Main.java
@Deprecated // Deprecated because this uses org.apache.http, which is itself deprecated public static HttpCookie servletCookieFromApacheCookie(org.apache.http.cookie.Cookie apacheCookie) { if (apacheCookie == null) { return null; }//from www . j ava 2 s . co m String name = apacheCookie.getName(); String value = apacheCookie.getValue(); HttpCookie cookie = new HttpCookie(name, value); value = apacheCookie.getDomain(); if (value != null) { cookie.setDomain(value); } value = apacheCookie.getPath(); if (value != null) { cookie.setPath(value); } cookie.setSecure(apacheCookie.isSecure()); value = apacheCookie.getComment(); if (value != null) { cookie.setComment(value); } // version cookie.setVersion(apacheCookie.getVersion()); // From the Apache source code, maxAge is converted to expiry date using the following formula // if (maxAge >= 0) { // setExpiryDate(new Date(System.currentTimeMillis() + maxAge * 1000L)); // } // Reverse this to get the actual max age Date expiryDate = apacheCookie.getExpiryDate(); if (expiryDate != null) { long maxAge = (expiryDate.getTime() - System.currentTimeMillis()) / 1000; // we have to lower down, no other option cookie.setMaxAge((int) maxAge); } // return the servlet cookie return cookie; }
From source file:org.exoplatform.utils.image.CookieAwarePicassoDownloader.java
/** * Syncs all cookies from ExoConnectionUtils cookieStore from Apache's * HttpClient to HttpURLConnection.//from www .j a v a2s. c o m * * @param manager the CookieManager in which to store the retrieved cookies */ private void syncCookies(CookieManager manager) { CookieStore store = ExoConnectionUtils.cookiesStore; if (store == null) return; for (Cookie cookie : store.getCookies()) { HttpCookie c = new HttpCookie(cookie.getName(), cookie.getValue()); c.setDomain(cookie.getDomain()); c.setPath(cookie.getPath()); c.setVersion(cookie.getVersion()); String url = AccountSetting.getInstance().getDomainName() + "/" + cookie.getPath(); try { manager.getCookieStore().add(new URI(url), c); } catch (URISyntaxException e) { Log.e(TAG, e.getMessage(), e); } } }
From source file:at.becast.youploader.youtube.data.Cookie.java
public HttpCookie getCookie() { final HttpCookie cookie = new HttpCookie(name, value); cookie.setComment(comment);/*from w ww .ja v a 2s . com*/ cookie.setCommentURL(commentUrl); cookie.setDiscard(discard); cookie.setDomain(domain); cookie.setPath(path); cookie.setPortlist(portList); cookie.setMaxAge(maxAge); cookie.setSecure(secure); cookie.setVersion(version); return cookie; }
From source file:org.nextlets.erc.defaults.http.ERCHttpInvokerImpl.java
private HttpCookie toHttpCookie(Cookie cookie) { HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue()); httpCookie.setComment(cookie.getComment()); httpCookie.setDomain(cookie.getDomain()); if (cookie.getExpiryDate() != null) { httpCookie.setMaxAge(cookie.getExpiryDate().getTime() / 1000); }/* ww w . ja v a 2 s . c o m*/ httpCookie.setPath(cookie.getPath()); httpCookie.setSecure(cookie.isSecure()); httpCookie.setVersion(cookie.getVersion()); return httpCookie; }
From source file:org.mariotaku.twidere.util.OAuthPasswordAuthenticator.java
public OAuthToken getOAuthAccessToken(final String username, final String password) throws AuthenticationException { final OAuthToken requestToken; try {//w ww.jav a 2 s.c om requestToken = oauth.getRequestToken(OAUTH_CALLBACK_OOB); } catch (final TwitterException e) { // if (e.isCausedByNetworkIssue()) throw new AuthenticationException(e); throw new AuthenticityTokenException(e); } RestHttpResponse authorizePage = null, authorizeResult = null; try { final String oauthToken = requestToken.getOauthToken(); final HashMap<String, String> inputMap = new HashMap<>(); final RestHttpRequest.Builder authorizePageBuilder = new RestHttpRequest.Builder(); authorizePageBuilder.method(GET.METHOD); authorizePageBuilder.url(endpoint.construct("/oauth/authorize", Pair.create("oauth_token", requestToken.getOauthToken()))); final RestHttpRequest authorizePageRequest = authorizePageBuilder.build(); authorizePage = client.execute(authorizePageRequest); final String[] cookieHeaders = authorizePage.getHeaders("Set-Cookie"); readInputFromHtml(BaseTypedData.reader(authorizePage.getBody()), inputMap, INPUT_AUTHENTICITY_TOKEN, INPUT_REDIRECT_AFTER_LOGIN); final List<Pair<String, String>> params = new ArrayList<>(); params.add(Pair.create("oauth_token", oauthToken)); params.add(Pair.create(INPUT_AUTHENTICITY_TOKEN, inputMap.get(INPUT_AUTHENTICITY_TOKEN))); if (inputMap.containsKey(INPUT_REDIRECT_AFTER_LOGIN)) { params.add(Pair.create(INPUT_REDIRECT_AFTER_LOGIN, inputMap.get(INPUT_REDIRECT_AFTER_LOGIN))); } params.add(Pair.create("session[username_or_email]", username)); params.add(Pair.create("session[password]", password)); final FormTypedBody authorizationResultBody = new FormTypedBody(params); final ArrayList<Pair<String, String>> requestHeaders = new ArrayList<>(); requestHeaders.add(Pair.create("Origin", "https://twitter.com")); requestHeaders.add(Pair.create("Referer", Endpoint.constructUrl("https://twitter.com/oauth/authorize", Pair.create("oauth_token", requestToken.getOauthToken())))); final String host = parseUrlHost(endpoint.getUrl()); for (String cookieHeader : cookieHeaders) { for (HttpCookie cookie : HttpCookie.parse(cookieHeader)) { if (HttpCookie.domainMatches(cookie.getDomain(), host)) { cookie.setVersion(1); cookie.setDomain("twitter.com"); } requestHeaders.add(Pair.create("Cookie", cookie.toString())); } } final RestHttpRequest.Builder authorizeResultBuilder = new RestHttpRequest.Builder(); authorizeResultBuilder.method(POST.METHOD); authorizeResultBuilder.url(endpoint.construct("/oauth/authorize")); authorizeResultBuilder.headers(requestHeaders); authorizeResultBuilder.body(authorizationResultBody); authorizeResult = client.execute(authorizeResultBuilder.build()); final String oauthPin = readOAuthPINFromHtml(BaseTypedData.reader(authorizeResult.getBody())); if (isEmpty(oauthPin)) throw new WrongUserPassException(); return oauth.getAccessToken(requestToken, oauthPin); } catch (final IOException | NullPointerException | XmlPullParserException | TwitterException e) { throw new AuthenticationException(e); } finally { if (authorizePage != null) { IoUtils.closeSilently(authorizePage); } if (authorizeResult != null) { IoUtils.closeSilently(authorizeResult); } } }