Tabnine Logo
org.apache.commons.httpclient.cookie
Code IndexAdd Tabnine to your IDE (free)

How to use org.apache.commons.httpclient.cookie

Best Java code snippets using org.apache.commons.httpclient.cookie (Showing top 20 results out of 315)

origin: commons-httpclient/commons-httpclient

/**
 * Return a textual representation of the cookie.
 *
 * @return string.
 */
public String toExternalForm() {
  CookieSpec spec =
      CookiePolicy.getCookieSpec(CookiePolicy.RFC_2965);
  return spec.formatCookie(this);
}
origin: commons-httpclient/commons-httpclient

public void parse(final Cookie cookie, final String commenturl)
    throws MalformedCookieException {
  if (cookie instanceof Cookie2) {
    Cookie2 cookie2 = (Cookie2) cookie;
    cookie2.setCommentURL(commenturl);
  }
}
origin: commons-httpclient/commons-httpclient

/**
 * @return cookie specification interface that provides high compatibilty 
 * with common cookie management of popular HTTP agents
 * 
 * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
 */
public static CookieSpec getCompatibilitySpec() {
  return getSpecByPolicy(COMPATIBILITY);
}
origin: commons-httpclient/commons-httpclient

/** 
 * Default constructor 
 * */
public RFC2965Spec() {
  super();
  this.formatter = new ParameterFormatter();
  this.formatter.setAlwaysUseQuotes(true);
  this.attribHandlerMap = new HashMap(10);        
  this.attribHandlerList = new ArrayList(10);
  this.rfc2109 = new RFC2109Spec();
  
  registerAttribHandler(Cookie2.PATH, new Cookie2PathAttributeHandler());
  registerAttribHandler(Cookie2.DOMAIN, new Cookie2DomainAttributeHandler());
  registerAttribHandler(Cookie2.PORT, new Cookie2PortAttributeHandler());
  registerAttribHandler(Cookie2.MAXAGE, new Cookie2MaxageAttributeHandler());
  registerAttribHandler(Cookie2.SECURE, new CookieSecureAttributeHandler());
  registerAttribHandler(Cookie2.COMMENT, new CookieCommentAttributeHandler());
  registerAttribHandler(Cookie2.COMMENTURL, new CookieCommentUrlAttributeHandler());
  registerAttribHandler(Cookie2.DISCARD, new CookieDiscardAttributeHandler());
  registerAttribHandler(Cookie2.VERSION, new Cookie2VersionAttributeHandler());
}
origin: commons-httpclient/commons-httpclient

  throw new MalformedCookieException("Cookie name may not contain blanks");
  throw new MalformedCookieException("Cookie name may not start with $");
CookieOrigin origin = new CookieOrigin(getEffectiveHost(host), port, path, secure); 
for (Iterator i = getAttribHandlerIterator(); i.hasNext(); ) {
 CookieAttributeHandler handler = (CookieAttributeHandler) i.next();
 handler.validate(cookie, origin);
this.rfc2109.validate(host, port, path, secure, cookie);
origin: commons-httpclient/commons-httpclient

/**
 * @param policy cookie policy to get the CookieSpec for
 * @return cookie specification interface for the given policy
 * 
 * @deprecated Use {@link CookiePolicy#getCookieSpec(String)} 
 */
public static CookieSpec getSpecByPolicy(int policy) {
  switch(policy) {
    case COMPATIBILITY: 
      return new CookieSpecBase(); 
    case NETSCAPE_DRAFT: 
      return new NetscapeDraftSpec(); 
    case RFC2109:
      return new RFC2109Spec();
    case RFC2965:
      return new RFC2965Spec();
    default:
      return getDefaultSpec(); 
  }
}
origin: commons-httpclient/commons-httpclient

/**
 * 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); 
}
origin: commons-httpclient/commons-httpclient

/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  if (cookie == null) {
    throw new IllegalArgumentException("Cookie may not be null");
  }
  if (origin == null) {
    throw new IllegalArgumentException("Cookie origin may not be null");
  }
  if (cookie instanceof Cookie2) {
    Cookie2 cookie2 = (Cookie2) cookie;
    int port = origin.getPort();
    if (cookie2.isPortAttributeSpecified()) {
      if (!portMatch(port, cookie2.getPorts())) {
        throw new MalformedCookieException(
            "Port attribute violates RFC 2965: "
            + "Request port not found in cookie's port list.");
      }
    }
  }
}
origin: commons-httpclient/commons-httpclient

/** 
 * Returns the actual cookie policy
 * 
 * @param state HTTP state. TODO: to be removed in the future
 * 
 * @return cookie spec
 */
private CookieSpec getCookieSpec(final HttpState state) {
  if (this.cookiespec == null) {
    int i = state.getCookiePolicy();
    if (i == -1) {
      this.cookiespec = CookiePolicy.getCookieSpec(this.params.getCookiePolicy());
    } else {
      this.cookiespec = CookiePolicy.getSpecByPolicy(i);
    }
    this.cookiespec.setValidDateFormats(
        (Collection)this.params.getParameter(HttpMethodParams.DATE_PATTERNS));
  }
  return this.cookiespec;
}
origin: commons-httpclient/commons-httpclient

/**
 * Gets the CookieSpec for a particular cookie version.
 * 
 * <p>Supported versions:
 * <ul>
 *  <li><tt>version 0</tt> corresponds to the Netscape draft
 *  <li><tt>version 1</tt> corresponds to the RFC 2109
 *  <li>Any other cookie value coresponds to the default spec
 * <ul>
 *
 * @param ver the cookie version to get the spec for
 * @return cookie specification interface intended for processing 
 *  cookies with the given version
 * 
 * @deprecated Use {@link CookiePolicy#getCookieSpec(String)}
 */
public static CookieSpec getSpecByVersion(int ver) {
  switch(ver) {
    case 0: 
      return new NetscapeDraftSpec(); 
    case 1:
      return new RFC2109Spec();
    default:
      return getDefaultSpec(); 
  }
}
origin: commons-httpclient/commons-httpclient

/**
 * Returns {@link CookieSpec cookie specification} registered as {@link #DEFAULT}. 
 * If no default {@link CookieSpec cookie specification} has been registered, 
 * {@link RFC2109Spec RFC2109 specification} is returned.
 *  
 * @return default {@link CookieSpec cookie specification}
 * 
 * @see #DEFAULT
 */
public static CookieSpec getDefaultSpec() {
  try {
    return getCookieSpec(DEFAULT);
  } catch (IllegalStateException e) {
    LOG.warn("Default cookie policy is not registered");
    return new RFC2109Spec();
  }
}

origin: commons-httpclient/commons-httpclient

/**
 * validate cookie version attribute. Version attribute is REQUIRED.
 */
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  if (cookie == null) {
    throw new IllegalArgumentException("Cookie may not be null");
  }
  if (cookie instanceof Cookie2) {
    Cookie2 cookie2 = (Cookie2) cookie;
    if (!cookie2.isVersionAttributeSpecified()) {
      throw new MalformedCookieException(
          "Violates RFC 2965. Version attribute is required.");
    }
  }
}
origin: commons-httpclient/commons-httpclient

public void parse(final Cookie cookie, final String commenturl)
    throws MalformedCookieException {
  if (cookie instanceof Cookie2) {
    Cookie2 cookie2 = (Cookie2) cookie;
    cookie2.setDiscard(true);
  }
}
origin: commons-httpclient/commons-httpclient

/**
 * Returns <tt>false</tt> if the cookie should be discarded at the end
 * of the "session"; <tt>true</tt> otherwise.
 *
 * @return <tt>false</tt> if the cookie should be discarded at the end
 *         of the "session"; <tt>true</tt> otherwise
 */
public boolean isPersistent() {
  return (null != getExpiryDate()) && !discard;
}
origin: commons-httpclient/commons-httpclient

/**
 * Creates a cookie with the given name, value, domain attribute,
 * path attribute, expiration attribute, secure attribute, and ports
 * attribute.
 *
 * @param name    the cookie name
 * @param value   the cookie value
 * @param domain  the domain this cookie can be sent to
 * @param path    the path prefix for which this cookie can be sent
 * @param expires the {@link Date} at which this cookie expires,
 *                or <tt>null</tt> if the cookie expires at the end
 *                of the session
 * @param secure if true this cookie can only be sent over secure
 * connections
 * @param ports   the ports for which this cookie can be sent
 * @throws IllegalArgumentException If cookie name is null or blank,
 *   cookie name contains a blank, or cookie name starts with character $
 *
 */
public Cookie2(String domain, String name, String value,
        String path, Date expires, boolean secure, int[] ports) {
  super(domain, name, value, path, expires, secure);
  setPorts(ports);
}
origin: commons-httpclient/commons-httpclient

/**
 * Gets attribute handler {@link CookieAttributeHandler} for the
 * given attribute.
 *
 * @param name attribute name. e.g. Domain, Path, etc.
 * @throws IllegalStateException if handler not found for the
 *          specified attribute.
 */
protected CookieAttributeHandler getAttribHandler(final String name) {
  CookieAttributeHandler handler = findAttribHandler(name);
  if (handler == null) {
    throw new IllegalStateException("Handler not registered for " +
                    name + " attribute.");
  } else {
    return handler;
  }
}
origin: commons-httpclient/commons-httpclient

public int compare(final Object o1, final Object o2) {
  Cookie c1 = (Cookie) o1;
  Cookie c2 = (Cookie) o2;
  String path1 = normalizePath(c1);
  String path2 = normalizePath(c2);
  if (path1.equals(path2)) {
    return 0;
  } else if (path1.startsWith(path2)) {
    return -1;
  } else if (path2.startsWith(path1)) {
    return 1;
  } else {
    // Does not really matter
    return 0;
  }
}
origin: commons-httpclient/commons-httpclient

public boolean match(final Cookie cookie, final CookieOrigin origin) {
  if (cookie == null) {
    throw new IllegalArgumentException("Cookie may not be null");
  }
  if (origin == null) {
    throw new IllegalArgumentException("Cookie origin may not be null");
  }
  return cookie.getSecure() == origin.isSecure();
}

origin: commons-httpclient/commons-httpclient

/**
 * Create a <tt>"Cookie"</tt> {@link Header} containing all {@link Cookie}s
 * in <i>cookies</i>.
 * @param cookies an array of {@link Cookie}s to be formatted as a <tt>"
 * Cookie"</tt> header
 * @return a <tt>"Cookie"</tt> {@link Header}.
 */
public Header formatCookieHeader(Cookie[] cookies) {
  LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie[])");
  return new Header("Cookie", formatCookies(cookies));
}
origin: commons-httpclient/commons-httpclient

/**
 * Create a <tt>"Cookie"</tt> {@link Header} containing the {@link Cookie}.
 * @param cookie <tt>Cookie</tt>s to be formatted as a <tt>Cookie</tt>
 * header
 * @return a Cookie header.
 */
public Header formatCookieHeader(Cookie cookie) {
  LOG.trace("enter CookieSpecBase.formatCookieHeader(Cookie)");
  return new Header("Cookie", formatCookie(cookie));
}
org.apache.commons.httpclient.cookie

Most used classes

  • CookieSpec
    Defines the cookie management specification.Cookie management specification must define * rules of
  • CookiePolicy
    Cookie management policy class. The cookie policy provides corresponding cookie management interfrac
  • MalformedCookieException
    Signals that a cookie is in some way invalid or illegal in a given context
  • RFC2109Spec
    RFC 2109 specific cookie management functions
  • CookieVersionSupport
    Defines cookie specification specific capabilities
  • Cookie2,
  • CookieAttributeHandler,
  • CookieOrigin,
  • CookiePathComparator,
  • CookieSpecBase,
  • RFC2965Spec$Cookie2DomainAttributeHandler,
  • RFC2965Spec$Cookie2MaxageAttributeHandler,
  • RFC2965Spec$Cookie2PathAttributeHandler,
  • RFC2965Spec$Cookie2PortAttributeHandler,
  • RFC2965Spec$Cookie2VersionAttributeHandler,
  • RFC2965Spec$CookieCommentAttributeHandler,
  • RFC2965Spec$CookieCommentUrlAttributeHandler,
  • RFC2965Spec$CookieDiscardAttributeHandler,
  • RFC2965Spec$CookieSecureAttributeHandler
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now