org.apache.http.cookie.Cookie.getPorts()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.apache.http.cookie.Cookie.getPorts()方法的一些代码示例,展示了Cookie.getPorts()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cookie.getPorts()方法的具体详情如下:
包路径:org.apache.http.cookie.Cookie
类名称:Cookie
方法名:getPorts

Cookie.getPorts介绍

[英]Get the Port attribute. It restricts the ports to which a cookie may be returned in a Cookie request header.
[中]获取端口属性。它限制cookie请求头中可返回cookie的端口。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
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");
  }
  int port = origin.getPort();
  if (cookie instanceof ClientCookie 
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (cookie.getPorts() == null) {
      // Invalid cookie state: port not specified
      return false;
    }
    if (!portMatch(port, cookie.getPorts())) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: robovm/robovm

/**
 * 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");
  }
  int port = origin.getPort();
  if (cookie instanceof ClientCookie 
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new MalformedCookieException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Adds valid Port attribute value, e.g. "8000,8001,8002"
 */
@Override
protected void formatCookieAsVer(final CharArrayBuffer buffer, 
    final Cookie cookie, int version) {
  super.formatCookieAsVer(buffer, cookie, version);
  // format port attribute
  if (cookie instanceof ClientCookie) {
    // Test if the port attribute as set by the origin server is not blank
    String s = ((ClientCookie) cookie).getAttribute(ClientCookie.PORT_ATTR);
    if (s != null) {
      buffer.append("; $Port");
      buffer.append("=\"");
      if (s.trim().length() > 0) {
        int[] ports = cookie.getPorts();
        if (ports != null) {
          for (int i = 0, len = ports.length; i < len; i++) {
            if (i > 0) {
              buffer.append(",");
            }
            buffer.append(Integer.toString(ports[i]));
          }
        }
      }
      buffer.append("\"");
    }
  }
}

代码示例来源:origin: apache/knox

@Override
public int[] getPorts() {
 return delegate.getPorts();
}

代码示例来源:origin: org.apache.knox/gateway-spi

@Override
public int[] getPorts() {
 return delegate.getPorts();
}

代码示例来源:origin: slartus/4pdaClient-plus

public int[] getPorts() {
  return cookie.getPorts();
}

代码示例来源:origin: MobiVM/robovm

/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
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");
  }
  int port = origin.getPort();
  if (cookie instanceof ClientCookie 
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (cookie.getPorts() == null) {
      // Invalid cookie state: port not specified
      return false;
    }
    if (!portMatch(port, cookie.getPorts())) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * 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");
  }
  int port = origin.getPort();
  if (cookie instanceof ClientCookie 
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new MalformedCookieException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: org.apache.httpcomponents/httpclient-android

/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
public boolean match(final Cookie cookie, final CookieOrigin origin) {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (cookie.getPorts() == null) {
      // Invalid cookie state: port not specified
      return false;
    }
    if (!portMatch(port, cookie.getPorts())) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: MobiVM/robovm

/**
 * 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");
  }
  int port = origin.getPort();
  if (cookie instanceof ClientCookie 
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new MalformedCookieException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * 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");
  }
  int port = origin.getPort();
  if (cookie instanceof ClientCookie 
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new MalformedCookieException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
@Override
public boolean match(final Cookie cookie, final CookieOrigin origin) {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (cookie.getPorts() == null) {
      // Invalid cookie state: port not specified
      return false;
    }
    if (!portMatch(port, cookie.getPorts())) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.httpclient

/**
 * Match cookie port attribute. If the Port attribute is not specified
 * in header, the cookie can be sent to any port. Otherwise, the request port
 * must be in the cookie's port list.
 */
public boolean match(final Cookie cookie, final CookieOrigin origin) {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (cookie.getPorts() == null) {
      // Invalid cookie state: port not specified
      return false;
    }
    if (!portMatch(port, cookie.getPorts())) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: org.apache.httpcomponents/httpclient-android

/**
 * 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 {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.apache.httpcomponents.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 {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: com.hynnet/httpclient

/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

代码示例来源:origin: Nextdoor/bender

/**
 * Validate cookie port attribute. If the Port attribute was specified
 * in header, the request port must be in cookie's port list.
 */
@Override
public void validate(final Cookie cookie, final CookieOrigin origin)
    throws MalformedCookieException {
  Args.notNull(cookie, "Cookie");
  Args.notNull(origin, "Cookie origin");
  final int port = origin.getPort();
  if (cookie instanceof ClientCookie
      && ((ClientCookie) cookie).containsAttribute(ClientCookie.PORT_ATTR)) {
    if (!portMatch(port, cookie.getPorts())) {
      throw new CookieRestrictionViolationException(
          "Port attribute violates RFC 2965: "
          + "Request port not found in cookie's port list.");
    }
  }
}

相关文章