Package org.apache.commons.httpclient.cookie

Examples of org.apache.commons.httpclient.cookie.CookieSpec


      */
    public static Cookie[] parse(String domain, int port, String path, boolean secure, Header setCookie)
        throws HttpException, IllegalArgumentException {
  log.trace("enter Cookie.parse(String, int, String, boolean, Header)");

        CookieSpec parser = CookiePolicy.getDefaultSpec();
        Cookie[] cookies = parser.parse(domain, port, path, secure, setCookie);

        for (int i = 0; i < cookies.length; i++)
        {
            Cookie cookie = cookies[i];
            CookieSpec validator = CookiePolicy.getSpecByVersion(cookie.getVersion());
            validator.validate(domain, port, path, secure, cookie);
        }
        return cookies;
    }
View Full Code Here


        String path,
        boolean secure
    ) {
        log.trace("enter HttpState.getCookies(String, int, String, boolean)");

    CookieSpec matcher = CookiePolicy.getDefaultSpec();
        ArrayList list = new ArrayList(cookies.size());
        for(int i=0,m=cookies.size();i<m;i++) {
            Cookie cookie = (Cookie)(cookies.get(i));
            if(matcher.match(domain, port, path, secure, cookie)) {
                list.add(cookie);
            }
        }
        return (Cookie[])(list.toArray(new Cookie[list.size()]));
    }
View Full Code Here

     * Return a textual representation of the cookie.
     *
     * @return string.
     */
    public String toExternalForm() {
        CookieSpec spec = null;
        if (getVersion() > 0) {
            spec = CookiePolicy.getDefaultSpec();
        } else {
            spec = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE);
        }
        return spec.formatCookie(this);
    }
View Full Code Here

        String path,
        boolean secure
    ) {
        LOG.trace("enter HttpState.getCookies(String, int, String, boolean)");

        CookieSpec matcher = CookiePolicy.getDefaultSpec();
        ArrayList list = new ArrayList(cookies.size());
        for (int i = 0, m = cookies.size(); i < m; i++) {
            Cookie cookie = (Cookie) (cookies.get(i));
            if (matcher.match(domain, port, path, secure, cookie)) {
                list.add(cookie);
            }
        }
        return (Cookie[]) (list.toArray(new Cookie[list.size()]));
    }
View Full Code Here

            if (cookieheader.isAutogenerated()) {
                getRequestHeaderGroup().removeHeader(cookieheader);
            }
        }

        CookieSpec matcher = getCookieSpec(state);
        String host = this.params.getVirtualHost();
        if (host == null) {
            host = conn.getHost();
        }
        Cookie[] cookies = matcher.match(host, conn.getPort(),
            getPath(), conn.isSecure(), state.getCookies());
        if ((cookies != null) && (cookies.length > 0)) {
            if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) {
                // In strict mode put all cookies on the same header
                String s = matcher.formatCookies(cookies);
                getRequestHeaderGroup().addHeader(new Header("Cookie", s, true));
            } else {
                // In non-strict mode put each cookie on a separate header
                for (int i = 0; i < cookies.length; i++) {
                    String s = matcher.formatCookie(cookies[i]);
                    getRequestHeaderGroup().addHeader(new Header("Cookie", s, true));
                }
            }
        }
    }
View Full Code Here

        //are not present
        if (headers.length == 0) {
            headers = getResponseHeaderGroup().getHeaders("set-cookie");
        }
       
        CookieSpec parser = getCookieSpec(state);
        String host = this.params.getVirtualHost();
        if (host == null) {
            host = conn.getHost();
        }
        for (int i = 0; i < headers.length; i++) {
            Header header = headers[i];
            Cookie[] cookies = null;
            try {
                cookies = parser.parse(
                  host,
                  conn.getPort(),
                  getPath(),
                  conn.isSecure(),
                  header);
            } catch (MalformedCookieException e) {
                if (LOG.isWarnEnabled()) {
                    LOG.warn("Invalid cookie header: \""
                        + header.getValue()
                        + "\". " + e.getMessage());
                }
            }
            if (cookies != null) {
                for (int j = 0; j < cookies.length; j++) {
                    Cookie cookie = cookies[j];
                    try {
                        parser.validate(
                          host,
                          conn.getPort(),
                          getPath(),
                          conn.isSecure(),
                          cookie);
                        state.addCookie(cookie);
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Cookie accepted: \""
                                + parser.formatCookie(cookie) + "\"");
                        }
                    } catch (MalformedCookieException e) {
                        if (LOG.isWarnEnabled()) {
                            LOG.warn("Cookie rejected: \"" + parser.formatCookie(cookie)
                                + "\". " + e.getMessage());
                        }
                    }
                }
            }
View Full Code Here

        // all the headers, looking for cookies
        String headerName = this.connection.getHeaderFieldKey(0);
        String headerValue = this.connection.getHeaderField(0);

        Vector cookieVector = new Vector();
        CookieSpec cookieSpec = CookiePolicy.getDefaultSpec();

        for (int i = 1; (headerName != null) || (headerValue != null); i++)
        {
            LOGGER.debug("Header name  = [" + headerName + "]");
            LOGGER.debug("Header value = [" + headerValue + "]");

            if ((headerName != null)
                && (headerName.toLowerCase().equals("set-cookie")
                || headerName.toLowerCase().equals("set-cookie2")))
            {
                // Parse the cookie definition
                org.apache.commons.httpclient.Cookie[] cookies;
                try
                {
                    cookies = cookieSpec.parse(
                        CookieUtil.getCookieDomain(getWebRequest(),
                            getConnection().getURL().getHost()),
                        CookieUtil.getCookiePort(getWebRequest(),
                            getConnection().getURL().getPort()),
                        CookieUtil.getCookiePath(getWebRequest(),
View Full Code Here

            catch (URISyntaxException e)
            {
                throw new RuntimeException("This should have not happened", e);
            }
        }
        CookieSpec cookieSpec = getCookieSpec(spec);
        boolean secure = uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("https");
        String host = uri.getHost();
        int port = getPortFromURI(uri);
        String path = uri.getPath();

        return cookieSpec.parse(host, port, path, secure, cookieHeaderValue);
    }
View Full Code Here

        // all the headers, looking for cookies
        String headerName = this.connection.getHeaderFieldKey(0);
        String headerValue = this.connection.getHeaderField(0);

        Vector cookieVector = new Vector();
        CookieSpec cookieSpec = CookiePolicy.getDefaultSpec();

        for (int i = 1; (headerName != null) || (headerValue != null); i++)
        {
            LOGGER.debug("Header name  = [" + headerName + "]");
            LOGGER.debug("Header value = [" + headerValue + "]");

            if ((headerName != null)
                && (headerName.toLowerCase().equals("set-cookie")
                || headerName.toLowerCase().equals("set-cookie2")))
            {
                // Parse the cookie definition
                org.apache.commons.httpclient.Cookie[] cookies;
                try
                {
                    cookies = cookieSpec.parse(
                        CookieUtil.getCookieDomain(getWebRequest(),
                            getConnection().getURL().getHost()),
                        CookieUtil.getCookiePort(getWebRequest(),
                            getConnection().getURL().getPort()),
                        CookieUtil.getCookiePath(getWebRequest(),
View Full Code Here

        {
            host = host.substring(0, portIndex);
            port = Integer.parseInt(theDomain.substring(portIndex + 1));
        }

        CookieSpec matcher = CookiePolicy.getDefaultSpec();
        org.apache.commons.httpclient.Cookie[] cookies =
            matcher.match(host, port, thePath, false, theCookies);
        if ((cookies != null) && (cookies.length > 0))
        {
            cookieHeader = matcher.formatCookieHeader(cookies);
        }
       
        if (cookieHeader == null)
        {
            throw new ClientException("Failed to create Cookie header for ["
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.cookie.CookieSpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.