Example usage for org.apache.commons.httpclient Cookie getVersion

List of usage examples for org.apache.commons.httpclient Cookie getVersion

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Cookie getVersion.

Prototype

public int getVersion() 

Source Link

Usage

From source file:com.owncloud.android.lib.common.OwnCloudClient.java

@SuppressWarnings("unused")
private void logCookie(Cookie cookie) {
    Log_OC.d(TAG, "Cookie name: " + cookie.getName());
    Log_OC.d(TAG, "       value: " + cookie.getValue());
    Log_OC.d(TAG, "       domain: " + cookie.getDomain());
    Log_OC.d(TAG, "       path: " + cookie.getPath());
    Log_OC.d(TAG, "       version: " + cookie.getVersion());
    Log_OC.d(TAG, "       expiryDate: "
            + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
    Log_OC.d(TAG, "       comment: " + cookie.getComment());
    Log_OC.d(TAG, "       secure: " + cookie.getSecure());
}

From source file:com.cerema.cloud2.lib.common.OwnCloudClient.java

private void logCookie(Cookie cookie) {
    Log_OC.d(TAG, "Cookie name: " + cookie.getName());
    Log_OC.d(TAG, "       value: " + cookie.getValue());
    Log_OC.d(TAG, "       domain: " + cookie.getDomain());
    Log_OC.d(TAG, "       path: " + cookie.getPath());
    Log_OC.d(TAG, "       version: " + cookie.getVersion());
    Log_OC.d(TAG, "       expiryDate: "
            + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
    Log_OC.d(TAG, "       comment: " + cookie.getComment());
    Log_OC.d(TAG, "       secure: " + cookie.getSecure());
}

From source file:com.sun.faban.driver.transport.hc3.FabanCookieSpec.java

/**
 * Performs most common {@link org.apache.commons.httpclient.Cookie} validation
 *
 * @param host the host from which the {@link org.apache.commons.httpclient.Cookie} was received
 * @param port the port from which the {@link org.apache.commons.httpclient.Cookie} was received
 * @param path the path from which the {@link org.apache.commons.httpclient.Cookie} was received
 * @param secure <tt>true</tt> when the {@link org.apache.commons.httpclient.Cookie} was received using a
 * secure connection/*from  w  ww. java  2  s  .  co  m*/
 * @param cookie The cookie to validate.
 * @throws org.apache.commons.httpclient.cookie.MalformedCookieException if an exception occurs during
 * validation
 */

public void validate(String host, int port, String path, boolean secure, final Cookie cookie)
        throws MalformedCookieException {

    logger.finer("enter CookieSpecBase.validate(" + "String, port, path, boolean, Cookie)");
    if (host == null) {
        throw new IllegalArgumentException("Host of origin may not be null");
    }
    if (host.trim().equals("")) {
        throw new IllegalArgumentException("Host of origin may not be blank");
    }
    if (port < 0) {
        throw new IllegalArgumentException("Invalid port: " + port);
    }
    if (path == null) {
        throw new IllegalArgumentException("Path of origin may not be null.");
    }
    if (path.trim().equals("")) {
        path = PATH_DELIM;
    }
    host = host.toLowerCase();
    // check version
    if (cookie.getVersion() < 0) {
        throw new MalformedCookieException("Illegal version number " + cookie.getValue());
    }

    // security check... we musn't allow the server to give us an
    // invalid domain scope

    // Validate the cookies domain attribute.  NOTE:  Domains without
    // any dots are allowed to support hosts on private LANs that don't
    // have DNS names.  Since they have no dots, to domain-match the
    // request-host and domain must be identical for the cookie to sent
    // back to the origin-server.
    if (host.indexOf(".") >= 0) {
        // Not required to have at least two dots.  RFC 2965.
        // A Set-Cookie2 with Domain=ajax.com will be accepted.

        // domain must match host
        if (!host.endsWith(cookie.getDomain())) {
            String s = cookie.getDomain();
            if (s.startsWith(".")) {
                s = s.substring(1, s.length());
            }
            if (!host.equals(s)) {
                throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain()
                        + "\". Domain of origin: \"" + host + "\"");
            }
        }
    } else {
        if (!host.equals(cookie.getDomain())) {
            throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain()
                    + "\". Domain of origin: \"" + host + "\"");
        }
    }
}

From source file:org.glite.slcs.shibclient.ShibbolethClient.java

private void dumpHttpClientCookies() {
    if (LOG.isDebugEnabled()) {
        Cookie[] cookies = this.httpClient_.getState().getCookies();
        StringBuffer sb = new StringBuffer();
        sb.append("\n");
        sb.append("---[CookiePolicy=").append(httpClient_.getParams().getCookiePolicy()).append("]---\n");
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            String path = cookie.getPath();
            String domain = cookie.getDomain();
            boolean secure = cookie.getSecure();
            int version = cookie.getVersion();
            // sb.append(name).append('=').append(value).append("\n");
            sb.append(i).append(": ").append(cookie);
            sb.append(" domain:").append(domain);
            sb.append(" path:").append(path);
            sb.append(" secure:").append(secure);
            sb.append(" version:").append(version);
            sb.append("\n");
        }// w  w w  .  j a  va 2  s. com
        sb.append("---[End]---");
        LOG.debug(sb.toString());
    }
}

From source file:org.mule.transport.http.CookieHelper.java

/**
 * This method formats the cookie so it can be send from server to client in a
 * {@linkplain HttpConstants#HEADER_COOKIE_SET "Set-Cookie"} header.
 */// ww  w.  j a v  a 2  s  .  c  o  m
public static String formatCookieForASetCookieHeader(Cookie cookie) {
    StringBuffer sb = new StringBuffer();
    ServerCookie.appendCookieValue(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),
            cookie.getPath(), cookie.getDomain(), cookie.getComment(), -1, cookie.getSecure());

    Date expiryDate = cookie.getExpiryDate();
    if (expiryDate != null) {
        sb.append("; Expires=");
        sb.append(EXPIRE_FORMATTER.format(expiryDate));
    }

    return sb.toString();
}

From source file:org.mule.transport.http.CookieWrapperTestCase.java

@Test
public void testCookieWrapper() throws ParseException {
    cookieWrapper.setName("test");
    cookieWrapper.setValue("test");
    cookieWrapper.setDomain("localhost");
    cookieWrapper.setPath("/");
    cookieWrapper.setMaxAge("3600");
    cookieWrapper.setSecure("true");
    cookieWrapper.setVersion("1");

    mockParse();/*from   www  . j  a  v a  2s  . c  o m*/

    cookieWrapper.parse(mockMuleMessage, mockExpressionManager);
    Cookie cookie = cookieWrapper.createCookie();

    assertEquals("test", cookie.getName());
    assertEquals("test", cookie.getValue());
    assertEquals("localhost", cookie.getDomain());
    assertEquals("/", cookie.getPath());
    assertTrue(cookie.getSecure());
    assertEquals(1, cookie.getVersion());
}

From source file:org.mule.transport.http.CookieWrapperTestCase.java

@Test
public void testCookieWrapperWithExpressions() throws ParseException {
    cookieWrapper.setName("#[name]");
    cookieWrapper.setValue("#[value]");
    cookieWrapper.setDomain("#[domain]");
    cookieWrapper.setPath("#[path]");
    cookieWrapper.setMaxAge("#[maxAge]");
    cookieWrapper.setSecure("#[secure]");
    cookieWrapper.setVersion("#[version]");

    when(mockExpressionManager.parse("#[name]", mockMuleMessage)).thenReturn("test");
    when(mockExpressionManager.parse("#[value]", mockMuleMessage)).thenReturn("test");
    when(mockExpressionManager.parse("#[domain]", mockMuleMessage)).thenReturn("localhost");
    when(mockExpressionManager.parse("#[path]", mockMuleMessage)).thenReturn("/");
    when(mockExpressionManager.parse("#[maxAge]", mockMuleMessage)).thenReturn("3600");
    when(mockExpressionManager.parse("#[secure]", mockMuleMessage)).thenReturn("true");
    when(mockExpressionManager.parse("#[version]", mockMuleMessage)).thenReturn("1");

    cookieWrapper.parse(mockMuleMessage, mockExpressionManager);
    Cookie cookie = cookieWrapper.createCookie();

    assertEquals("test", cookie.getName());
    assertEquals("test", cookie.getValue());
    assertEquals("localhost", cookie.getDomain());
    assertEquals("/", cookie.getPath());
    assertTrue(cookie.getSecure());/*  w  w w .  ja  va  2 s.  c  om*/
    assertEquals(1, cookie.getVersion());
}

From source file:org.zaproxy.zap.network.ZapCookieSpec.java

@Override
public void validate(String host, int port, String path, boolean secure, Cookie cookie)
        throws MalformedCookieException {
    LOG.trace("enter CookieSpecBase.validate(" + "String, port, path, boolean, Cookie)");
    if (host == null) {
        throw new IllegalArgumentException("Host of origin may not be null");
    }/*ww  w .  j  ava 2s .  c om*/
    if (host.trim().equals("")) {
        throw new IllegalArgumentException("Host of origin may not be blank");
    }
    if (port < 0) {
        throw new IllegalArgumentException("Invalid port: " + port);
    }
    if (path == null) {
        throw new IllegalArgumentException("Path of origin may not be null.");
    }
    host = host.toLowerCase();
    // check version
    if (cookie.getVersion() < 0) {
        throw new MalformedCookieException("Illegal version number " + cookie.getValue());
    }

    // security check... we musn't allow the server to give us an
    // invalid domain scope

    // Validate the cookies domain attribute.  NOTE:  Domains without 
    // any dots are allowed to support hosts on private LANs that don't 
    // have DNS names.  Since they have no dots, to domain-match the 
    // request-host and domain must be identical for the cookie to sent 
    // back to the origin-server.
    if (host.indexOf(".") >= 0) {
        // Not required to have at least two dots.  RFC 2965.
        // A Set-Cookie2 with Domain=ajax.com will be accepted.

        // domain must match host
        if (!host.endsWith(cookie.getDomain())) {
            String s = cookie.getDomain();
            if (s.startsWith(".")) {
                s = s.substring(1, s.length());
            }
            if (!host.equals(s)) {
                throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain()
                        + "\". Domain of origin: \"" + host + "\"");
            }
        }
    } else {
        if (!host.equals(cookie.getDomain())) {
            throw new MalformedCookieException("Illegal domain attribute \"" + cookie.getDomain()
                    + "\". Domain of origin: \"" + host + "\"");
        }
    }
}