List of usage examples for org.apache.commons.httpclient Cookie setPath
public void setPath(String paramString)
From source file:ir.keloud.android.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies/* w ww . j av a 2 s . c o m*/ * @param account * @param client * @param context */ public static void restoreCookies(Account account, KeloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + account.name); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { String[] cookies = cookiesString.split(";"); if (cookies.length > 0) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = new Cookie(); int equalPos = cookies[i].indexOf('='); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }
From source file:com.cerema.cloud2.lib.common.accounts.AccountUtils.java
/** * Restore the client cookies/*from w w w .ja v a 2 s . co m*/ * @param account * @param client * @param context */ public static void restoreCookies(Account account, OwnCloudClient client, Context context) { Log_OC.d(TAG, "Restoring cookies for " + account.name); // Account Manager AccountManager am = AccountManager.get(context.getApplicationContext()); Uri serverUri = (client.getBaseUri() != null) ? client.getBaseUri() : client.getWebdavUri(); String cookiesString = am.getUserData(account, Constants.KEY_COOKIES); if (cookiesString != null) { String[] cookies = cookiesString.split(";"); if (cookies.length > 0) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = new Cookie(); int equalPos = cookies[i].indexOf('='); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }
From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.AnnotationManager.java
private RESTAnnotationServer getAnnotationServer() { HttpClient client = new HttpClient(); // Forward all cookies from the calling request if (request != null) { javax.servlet.http.Cookie[] cookies = request.getCookies(); if (cookies != null) { for (javax.servlet.http.Cookie c : cookies) { c.setDomain(request.getServerName()); c.setPath("/"); Cookie apacheCookie = new Cookie(c.getDomain(), c.getName(), c.getValue(), c.getPath(), c.getMaxAge(), c.getSecure()); client.getState().addCookie(apacheCookie); }//from w w w . j av a2 s . c o m client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); } } return ProxyFactory.create(RESTAnnotationServer.class, annotationServerBaseUrl, new ApacheHttpClientExecutor(client)); }
From source file:at.ait.dme.yuma.server.annotation.ImageAnnotationManager.java
private EuropeanaAnnotationService getAnnotationService(MultivaluedMap<String, String> headers) { List<String> cookieHeaders = (headers != null) ? headers.get("Set-Cookie") : new ArrayList<String>(); HttpClient client = new HttpClient(); // make sure to forward all cookies javax.servlet.http.Cookie[] cookies = clientRequest.getCookies(); for (javax.servlet.http.Cookie c : cookies) { c.setDomain(clientRequest.getServerName()); c.setPath("/"); String value = c.getValue(); for (String cookieHeader : cookieHeaders) { if (cookieHeader.startsWith(c.getName())) { String cookieHeaderParts[] = cookieHeader.split("="); if (cookieHeaderParts.length >= 2) value = cookieHeaderParts[1]; }//from w w w . j a v a2 s . c o m } Cookie apacheCookie = new Cookie(c.getDomain(), c.getName(), value, c.getPath(), c.getMaxAge(), c.getSecure()); client.getState().addCookie(apacheCookie); } client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); return ProxyFactory.create(EuropeanaAnnotationService.class, annotationServiceBaseUrl, new ApacheHttpClientExecutor(client)); }
From source file:com.intuit.tank.httpclient3.TankHttpClient3.java
/** * /*from w w w. j a va2 s . c om*/ */ @Override public void setCookie(TankCookie cookie) { Cookie c = new Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue()); c.setPath(cookie.getPath()); httpclient.getState().addCookie(c); }
From source file:arena.httpclient.commons.JakartaCommonsHttpClient.java
public void addCookie(String name, String value, int maxAge, String domain, String path) { org.apache.commons.httpclient.Cookie commonsCookie = new org.apache.commons.httpclient.Cookie(); commonsCookie.setName(name);/*from w ww .ja va2 s. com*/ commonsCookie.setValue(value); if (maxAge >= 0) { commonsCookie.setExpiryDate(new Date(System.currentTimeMillis() + maxAge)); } if (path != null) { commonsCookie.setPath(path); } if (domain != null) { commonsCookie.setDomain(domain); } this.state.addCookie(commonsCookie); }
From source file:ir.keloud.android.lib.common.KeloudSamlSsoCredentials.java
@Override public void applyTo(KeloudClient client) { client.getParams().setAuthenticationPreemptive(false); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.setFollowRedirects(false);/*w w w . j a va2 s . c o m*/ Uri serverUri = client.getBaseUri(); String[] cookies = mSessionCookie.split(";"); if (cookies.length > 0) { Cookie cookie = null; for (int i = 0; i < cookies.length; i++) { int equalPos = cookies[i].indexOf('='); if (equalPos >= 0) { cookie = new Cookie(); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }
From source file:com.cerema.cloud2.lib.common.OwnCloudSamlSsoCredentials.java
@Override public void applyTo(OwnCloudClient client) { client.getParams().setAuthenticationPreemptive(false); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.setFollowRedirects(false);//from w w w . ja v a 2 s.co m Uri serverUri = client.getBaseUri(); String[] cookies = mSessionCookie.split(";"); if (cookies.length > 0) { Cookie cookie = null; for (int i = 0; i < cookies.length; i++) { int equalPos = cookies[i].indexOf('='); if (equalPos >= 0) { cookie = new Cookie(); cookie.setName(cookies[i].substring(0, equalPos)); cookie.setValue(cookies[i].substring(equalPos + 1)); cookie.setDomain(serverUri.getHost()); // VERY IMPORTANT cookie.setPath(serverUri.getPath()); // VERY IMPORTANT client.getState().addCookie(cookie); } } } }
From source file:com.gs.jrpip.client.FastServletProxyFactory.java
private Cookie createCookieFromToken(String token, String path, String domain) { Cookie cookie = new Cookie(); cookie.setPath(path); cookie.setDomain(domain);//from w ww . java2s . co m cookie.setName(token.substring(0, token.indexOf('='))); cookie.setValue(token.substring(token.indexOf('=') + 1)); return cookie; }
From source file:davmail.http.DavMailCookieSpec.java
@Override public void validate(String host, int port, String path, boolean secure, final Cookie cookie) throws MalformedCookieException { // workaround for space in cookie name String cookieName = cookie.getName(); if (cookieName != null && cookieName.indexOf(' ') >= 0) { cookie.setName(cookieName.replaceAll(" ", "")); } else {//w w w . j a va 2 s .c om cookieName = null; } // workaround for invalid cookie path String cookiePath = cookie.getPath(); if (cookiePath != null && !path.startsWith(cookiePath)) { cookie.setPath(path); } else { cookiePath = null; } String hostWithoutDomain = host.substring(0, host.length() - cookie.getDomain().length()); int dotIndex = hostWithoutDomain.indexOf('.'); if (dotIndex != -1) { // discard additional host name part super.validate(host.substring(dotIndex + 1), port, path, secure, cookie); } else { super.validate(host, port, path, secure, cookie); } if (cookieName != null) { cookie.setName(cookieName); } if (cookiePath != null) { cookie.setPath(cookiePath); } }