Example usage for org.apache.commons.httpclient.cookie CookiePolicy getCookieSpec

List of usage examples for org.apache.commons.httpclient.cookie CookiePolicy getCookieSpec

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.cookie CookiePolicy getCookieSpec.

Prototype

public static CookieSpec getCookieSpec(String paramString) throws IllegalStateException 

Source Link

Usage

From source file:net.sf.antcontrib.net.httpclient.GetCookieTask.java

protected void execute(HttpStateType stateType) throws BuildException {

    if (realm == null || path == null) {
        throw new BuildException("'realm' and 'path' attributes are required");
    }/*from  ww w  .j a  v  a 2s  . com*/

    HttpState state = stateType.getState();
    CookieSpec spec = CookiePolicy.getCookieSpec(cookiePolicy);
    Cookie cookies[] = state.getCookies();
    Cookie matches[] = spec.match(realm, port, path, secure, cookies);

    if (name != null) {
        Cookie c = findCookie(matches, name);
        if (c != null) {
            matches = new Cookie[] { c };
        } else {
            matches = new Cookie[0];
        }
    }

    if (property != null) {
        if (matches != null && matches.length > 0) {
            Property p = (Property) getProject().createTask("property");
            p.setName(property);
            p.setValue(matches[0].getValue());
            p.perform();
        }
    } else if (prefix != null) {
        if (matches != null && matches.length > 0) {
            for (int i = 0; i < matches.length; i++) {
                String propName = prefix + matches[i].getName();
                Property p = (Property) getProject().createTask("property");
                p.setName(propName);
                p.setValue(matches[i].getValue());
                p.perform();
            }
        }
    } else {
        throw new BuildException("Nothing to set");
    }
}

From source file:org.apache.jmeter.protocol.http.control.CookieManager.java

public void testStarted() {
    initialCookies = getCookies();/*from   w  w  w.ja  va2 s  .com*/
    cookieSpec = CookiePolicy.getCookieSpec(getPolicy());
    if (log.isDebugEnabled()) {
        log.debug("Policy: " + getPolicy() + " Clear: " + getClearEachIteration());
    }
}

From source file:org.apache.jmeter.protocol.http.control.HC3CookieHandler.java

/**
 * @param policy/*from  ww  w.j  a  va2s.com*/
 *            cookie policy to which to conform (see
 *            {@link CookiePolicy#getCookieSpec(String)}
 */
public HC3CookieHandler(String policy) {
    super();
    this.cookieSpec = CookiePolicy.getCookieSpec(policy);
}