org.apache.jmeter.protocol.http.control

## Class CookieManager

- java.lang.Object
- - org.apache.jmeter.testelement.AbstractTestElement
  - - org.apache.jmeter.config.ConfigTestElement
    - - org.apache.jmeter.protocol.http.control.CookieManager

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, ConfigElement, Searchable, TestElement, TestIterationListener, TestStateListener

      public class CookieManager
      extends ConfigTestElement
      implements TestStateListener, TestIterationListener, java.io.Serializable

  This class provides an interface to the netscape cookies file to pass cookies along with a request.
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.apache.jmeter.config.ConfigTestElement

      `PASSWORD, USERNAME`

    - ### Fields inherited from interface org.apache.jmeter.testelement.TestElement

      `COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CookieManager()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(Cookie c)` Add a cookie.
    `void` | `addCookieFromHeader(java.lang.String cookieHeader, java.net.URL url)`
    `void` | `addFile(java.lang.String cookieFile)` Add cookie data from a file.
    `void` | `clear()` Clear the TestElement of all data.
    `java.lang.Object` | `clone()`
    `Cookie` | `get(int i)` Return the cookie at index i.
    `boolean` | `getClearEachIteration()`
    `int` | `getCookieCount()`
    `java.lang.String` | `getCookieHeaderForURL(java.net.URL url)` Find cookies applicable to the given URL and build the Cookie header from them.
    `CollectionProperty` | `getCookies()`
    `java.lang.String` | `getImplementation()`
    `java.lang.String` | `getPolicy()`
    `void` | `recoverRunningVersion()` Tells the test element to return to the state it was in when setRunningVersion(true) was called.
    `void` | `remove(int index)` Remove a cookie.
    `void` | `save(java.lang.String authFile)` Save the static cookie data to a file.
    `void` | `setClearEachIteration(boolean clear)`
    `void` | `setCookiePolicy(java.lang.String policy)`
    `void` | `setImplementation(java.lang.String implementation)`
    `void` | `setRunningVersion(boolean running)` Sets the runningVersion.
    `void` | `testEnded()` Called once for all threads after the end of a test.
    `void` | `testEnded(java.lang.String host)` Called once for all threads after the end of a test.
    `void` | `testIterationStart(LoopIterationEvent event)` Each time through a Thread Group's test script, an iteration event is fired for each thread.
    `void` | `testStarted()` Called just before the start of the test from the main engine thread.
    `void` | `testStarted(java.lang.String host)` Called just before the start of the test from the main engine thread.

    - ### Methods inherited from class org.apache.jmeter.config.ConfigTestElement

      `addConfigElement, addTestElement, expectsModification`

    - ### Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement

      `addPropertiesValues, addProperty, addProperty, canRemove, clearTemporary, clearTestElementChildren, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.jmeter.testelement.TestElement

      `removed`

- - ### Constructor Detail

    - #### CookieManager

          public CookieManager()

  - ### Method Detail

    - #### clone

          public java.lang.Object clone()

      Specified by:
        `clone` in interface `ConfigElement`
      Specified by:
        `clone` in interface `TestElement`
      Overrides:
        `clone` in class `AbstractTestElement`

    - #### getPolicy

          public java.lang.String getPolicy()

    - #### setCookiePolicy

          public void setCookiePolicy(java.lang.String policy)

    - #### getCookies

          public CollectionProperty getCookies()

    - #### getCookieCount

          public int getCookieCount()

    - #### getClearEachIteration

          public boolean getClearEachIteration()

    - #### setClearEachIteration

          public void setClearEachIteration(boolean clear)

    - #### getImplementation

          public java.lang.String getImplementation()

    - #### setImplementation

          public void setImplementation(java.lang.String implementation)

    - #### save

          public void save(java.lang.String authFile)
                    throws java.io.IOException

      Save the static cookie data to a file.

      Cookies are only taken from the GUI - runtime cookies are not included.

      Parameters:
        `authFile` - name of the file to store the cookies into. If the name is relative, the system property `user.dir` will be prepended
      Throws:
        `java.io.IOException` - when writing to that file fails

    - #### addFile

          public void addFile(java.lang.String cookieFile)
                       throws java.io.IOException

      Add cookie data from a file.
      Parameters:
        `cookieFile` - name of the file to read the cookies from. If the name is relative, the system property `user.dir` will be prepended
      Throws:
        `java.io.IOException` - if reading the file fails

    - #### recoverRunningVersion

          public void recoverRunningVersion()

      Tells the test element to return to the state it was in when setRunningVersion(true) was called.
      Specified by:
        `recoverRunningVersion` in interface `TestElement`
      Overrides:
        `recoverRunningVersion` in class `AbstractTestElement`

    - #### setRunningVersion

          public void setRunningVersion(boolean running)

      Sets the runningVersion.
      Specified by:
        `setRunningVersion` in interface `TestElement`
      Overrides:
        `setRunningVersion` in class `AbstractTestElement`
      Parameters:
        `running` - the runningVersion to set

    - #### add

          public void add(Cookie c)

      Add a cookie.
      Parameters:
        `c` - cookie to be added

    - #### clear

          public void clear()

      Clear the TestElement of all data.
      Specified by:
        `clear` in interface `TestElement`
      Overrides:
        `clear` in class `AbstractTestElement`

    - #### remove

          public void remove(int index)

      Remove a cookie.
      Parameters:
        `index` - index of the cookie to remove

    - #### get

          public Cookie get(int i)

      Return the cookie at index i.
      Parameters:
        `i` - index of the cookie to get
      Returns:
        cookie at index `i`

    - #### getCookieHeaderForURL

          public java.lang.String getCookieHeaderForURL(java.net.URL url)

      Find cookies applicable to the given URL and build the Cookie header from them.
      Parameters:
        `url` - URL of the request to which the returned header will be added.
      Returns:
        the value string for the cookie header (goes after "Cookie: ").

    - #### addCookieFromHeader

          public void addCookieFromHeader(java.lang.String cookieHeader,
                                          java.net.URL url)

    - #### testStarted

          public void testStarted()

      Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testStarted` in interface `TestStateListener`
      See Also:
        `StandardJMeterEngine.run()`

    - #### testEnded

          public void testEnded()

      Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testEnded` in interface `TestStateListener`
      See Also:
        `StandardJMeterEngine.stopTest()`

    - #### testStarted

          public void testStarted(java.lang.String host)

      Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testStarted` in interface `TestStateListener`
      Parameters:
        `host` - name of host
      See Also:
        `StandardJMeterEngine.run()`

    - #### testEnded

          public void testEnded(java.lang.String host)

      Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testEnded` in interface `TestStateListener`
      Parameters:
        `host` - name of host
      See Also:
        `StandardJMeterEngine.stopTest()`

    - #### testIterationStart

          public void testIterationStart(LoopIterationEvent event)

      Each time through a Thread Group's test script, an iteration event is fired for each thread. This will be after the test elements have been cloned, so in general the instance will not be the same as the ones the start/end methods call.
      Specified by:
        `testIterationStart` in interface `TestIterationListener`
      Parameters:
        `event` - the iteration event

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.