Java Code Examples for org.apache.http.cookie.Cookie#getPath()

The following examples show how to use org.apache.http.cookie.Cookie#getPath() . 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: HC4ExchangeFormAuthenticator.java    From davmail with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Authenticated httpClientAdapter (with cookies).
 *
 * @return http client
 */
public org.apache.commons.httpclient.HttpClient getHttpClient() throws DavMailException {
    org.apache.commons.httpclient.HttpClient oldHttpClient;
    oldHttpClient = DavGatewayHttpClientFacade.getInstance(url);
    DavGatewayHttpClientFacade.setCredentials(oldHttpClient, username, password);
    DavGatewayHttpClientFacade.createMultiThreadedHttpConnectionManager(oldHttpClient);

    for (Cookie cookie : httpClientAdapter.getCookies()) {
        org.apache.commons.httpclient.Cookie oldCookie = new org.apache.commons.httpclient.Cookie(
                cookie.getDomain(),
                cookie.getName(),
                cookie.getValue(),
                cookie.getPath(),
                cookie.getExpiryDate(),
                cookie.isSecure());
        oldCookie.setPathAttributeSpecified(cookie.getPath() != null);
        oldHttpClient.getState().addCookie(oldCookie);
    }

    return oldHttpClient;
}
 
Example 2
Source File: HttpTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * @param cookieName name of cookie.
 * @return path of cookie in the cookie store.
 */
public String cookiePath(String cookieName) {
    String result = null;
    Cookie cookie = getCookie(cookieName);
    if (cookie != null) {
        result = cookie.getPath();
    }
    return result;
}
 
Example 3
Source File: DefaultCookieManager.java    From esigate with Apache License 2.0 5 votes vote down vote up
private String toString(Cookie cookie) {
    StringBuilder result = new StringBuilder(Parameters.SMALL_BUFFER_SIZE);
    result.append(cookie.getName());
    result.append("=");
    result.append(cookie.getValue());
    if (cookie.getDomain() != null) {
        result.append(";domain=");
        result.append(cookie.getDomain());
    }
    if (cookie.getPath() != null) {
        result.append(";path=");
        result.append(cookie.getPath());
    }
    if (cookie.getExpiryDate() != null) {
        result.append(";expires=");
        result.append(cookie.getExpiryDate());
    }
    if (cookie.getCommentURL() != null) {
        result.append(";comment=");
        result.append(cookie.getComment());
    }
    if (cookie.getCommentURL() != null) {
        result.append(";comment=");
        result.append(cookie.getCommentURL());
    }
    return result.toString();
}
 
Example 4
Source File: DefaultCookieManager.java    From esigate with Apache License 2.0 4 votes vote down vote up
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;
}