com.crashlytics.tools.android_2.1.0

      return doFormatOneHeader(cookieList);
    }
    return doFormatManyHeaders(cookieList);
  }
  
  private List<Header> doFormatOneHeader(List<Cookie> cookies)
  {
    int version = Integer.MAX_VALUE;
    for (Cookie cookie : cookies) {
      if (cookie.getVersion() < version) {
        version = cookie.getVersion();
      }
    }
    CharArrayBuffer buffer = new CharArrayBuffer(40 * cookies.size());
    buffer.append("Cookie");
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(version));
    for (Cookie cooky : cookies)
    {
      buffer.append("; ");
      Cookie cookie = cooky;
      formatCookieAsVer(buffer, cookie, version);
    }
    List<Header> headers = new ArrayList(1);
    headers.add(new BufferedHeader(buffer));
    return headers;
  }
  
  private List<Header> doFormatManyHeaders(List<Cookie> cookies)
  {
    List<Header> headers = new ArrayList(cookies.size());
    for (Cookie cookie : cookies)
    {
      int version = cookie.getVersion();
      CharArrayBuffer buffer = new CharArrayBuffer(40);
      buffer.append("Cookie: ");
      buffer.append("$Version=");
      buffer.append(Integer.toString(version));
      buffer.append("; ");
      formatCookieAsVer(buffer, cookie, version);
      headers.add(new BufferedHeader(buffer));
    }
    return headers;
  }
  
  protected void formatParamAsVer(CharArrayBuffer buffer, String name, String value, int version)
  {
    buffer.append(name);
    buffer.append("=");
    if (value != null) {
      if (version > 0)
      {
        buffer.append('"');
        buffer.append(value);
        buffer.append('"');
      }
      else
      {
        buffer.append(value);
      }
    }
  }
  
  protected void formatCookieAsVer(CharArrayBuffer buffer, Cookie cookie, int version)
  {
    formatParamAsVer(buffer, cookie.getName(), cookie.getValue(), version);
    if ((cookie.getPath() != null) && 
      ((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("path")))
    {
      buffer.append("; ");
      formatParamAsVer(buffer, "$Path", cookie.getPath(), version);
    }
    if ((cookie.getDomain() != null) && 
      ((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("domain")))
    {
      buffer.append("; ");
      formatParamAsVer(buffer, "$Domain", cookie.getDomain(), version);
    }
  }
  
  public int getVersion()
  {
    return 1;
  }
  
  public Header getVersionHeader()
  {
    return null;
  }
  
  public String toString()
  {
    return "rfc2109";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109Spec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class RFC2109SpecFactory
  implements CookieSpecFactory, CookieSpecProvider
{
  private final String[] datepatterns;
  private final boolean oneHeader;
  
  public RFC2109SpecFactory(String[] datepatterns, boolean oneHeader)
  {
    this.datepatterns = datepatterns;
    this.oneHeader = oneHeader;
  }
  
  public RFC2109SpecFactory()
  {
    this(null, false);
  }
  
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      boolean singleHeader = params.getBooleanParameter("http.protocol.single-cookie-header", false);
      
      return new RFC2109Spec(patterns, singleHeader);
    }
    return new RFC2109Spec();
  }
  
  public CookieSpec create(HttpContext context)
  {
    return new RFC2109Spec(datepatterns, oneHeader);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109SpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.Args;

@Immutable
public class RFC2109VersionHandler
  extends AbstractCookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (value == null) {
      throw new MalformedCookieException("Missing value for version attribute");
    }
    if (value.trim().length() == 0) {
      throw new MalformedCookieException("Blank value for version attribute");
    }
    try
    {
      cookie.setVersion(Integer.parseInt(value));
    }
    catch (NumberFormatException e)
    {
      throw new MalformedCookieException("Invalid version: " + e.getMessage());
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (cookie.getVersion() < 0) {
      throw new CookieRestrictionViolationException("Cookie version may not be negative");
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2109VersionHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;

@Immutable
public class RFC2965CommentUrlAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String commenturl)
    throws MalformedCookieException
  {
    if ((cookie instanceof SetCookie2))
    {
      SetCookie2 cookie2 = (SetCookie2)cookie;
      cookie2.setCommentURL(commenturl);
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {}
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965CommentUrlAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;

@Immutable
public class RFC2965DiscardAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String commenturl)
    throws MalformedCookieException
  {
    if ((cookie instanceof SetCookie2))
    {
      SetCookie2 cookie2 = (SetCookie2)cookie;
      cookie2.setDiscard(true);
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {}
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965DiscardAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Locale;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.util.Args;

@Immutable
public class RFC2965DomainAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String domain)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (domain == null) {
      throw new MalformedCookieException("Missing value for domain attribute");
    }
    if (domain.trim().length() == 0) {
      throw new MalformedCookieException("Blank value for domain attribute");
    }
    String s = domain;
    s = s.toLowerCase(Locale.ENGLISH);
    if (!domain.startsWith(".")) {
      s = '.' + s;
    }
    cookie.setDomain(s);
  }
  
  public boolean domainMatch(String host, String domain)
  {
    boolean match = (host.equals(domain)) || ((domain.startsWith(".")) && (host.endsWith(domain)));
    
    return match;
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    String host = origin.getHost().toLowerCase(Locale.ENGLISH);
    if (cookie.getDomain() == null) {
      throw new CookieRestrictionViolationException("Invalid cookie state: domain not specified");
    }
    String cookieDomain = cookie.getDomain().toLowerCase(Locale.ENGLISH);
    if (((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("domain")))
    {
      if (!cookieDomain.startsWith(".")) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2109: domain must start with a dot");
      }
      int dotIndex = cookieDomain.indexOf('.', 1);
      if (((dotIndex < 0) || (dotIndex == cookieDomain.length() - 1)) && (!cookieDomain.equals(".local"))) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: the value contains no embedded dots " + "and the value is not .local");
      }
      if (!domainMatch(host, cookieDomain)) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: effective host name does not " + "domain-match domain attribute.");
      }
      String effectiveHostWithoutDomain = host.substring(0, host.length() - cookieDomain.length());
      if (effectiveHostWithoutDomain.indexOf('.') != -1) {
        throw new CookieRestrictionViolationException("Domain attribute \"" + cookie.getDomain() + "\" violates RFC 2965: " + "effective host minus domain may not contain any dots");
      }
    }
    else if (!cookie.getDomain().equals(host))
    {
      throw new CookieRestrictionViolationException("Illegal domain attribute: \"" + cookie.getDomain() + "\"." + "Domain of origin: \"" + host + "\"");
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    String host = origin.getHost().toLowerCase(Locale.ENGLISH);
    String cookieDomain = cookie.getDomain();
    if (!domainMatch(host, cookieDomain)) {
      return false;
    }
    String effectiveHostWithoutDomain = host.substring(0, host.length() - cookieDomain.length());
    
    return effectiveHostWithoutDomain.indexOf('.') == -1;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965DomainAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.StringTokenizer;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.util.Args;

@Immutable
public class RFC2965PortAttributeHandler
  implements CookieAttributeHandler
{
  private static int[] parsePortAttribute(String portValue)
    throws MalformedCookieException
  {
    StringTokenizer st = new StringTokenizer(portValue, ",");
    int[] ports = new int[st.countTokens()];
    try
    {
      int i = 0;
      while (st.hasMoreTokens())
      {
        ports[i] = Integer.parseInt(st.nextToken().trim());
        if (ports[i] < 0) {
          throw new MalformedCookieException("Invalid Port attribute.");
        }
        i++;
      }
    }
    catch (NumberFormatException e)
    {
      throw new MalformedCookieException("Invalid Port attribute: " + e.getMessage());
    }
    return ports;
  }
  
  private static boolean portMatch(int port, int[] ports)
  {
    boolean portInList = false;
    for (int port2 : ports) {
      if (port == port2)
      {
        portInList = true;
        break;
      }
    }
    return portInList;
  }
  
  public void parse(SetCookie cookie, String portValue)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if ((cookie instanceof SetCookie2))
    {
      SetCookie2 cookie2 = (SetCookie2)cookie;
      if ((portValue != null) && (portValue.trim().length() > 0))
      {
        int[] ports = parsePortAttribute(portValue);
        cookie2.setPorts(ports);
      }
    }
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    int port = origin.getPort();
    if (((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("port"))) {
      if (!portMatch(port, cookie.getPorts())) {
        throw new CookieRestrictionViolationException("Port attribute violates RFC 2965: Request port not found in cookie's port list.");
      }
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    int port = origin.getPort();
    if (((cookie instanceof ClientCookie)) && (((ClientCookie)cookie).containsAttribute("port")))
    {
      if (cookie.getPorts() == null) {
        return false;
      }
      if (!portMatch(port, cookie.getPorts())) {
        return false;
      }
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965PortAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.message.BufferedHeader;
import org.apache.http.util.Args;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public class RFC2965Spec
  extends RFC2109Spec
{
  public RFC2965Spec()
  {
    this(null, false);
  }
  
  public RFC2965Spec(String[] datepatterns, boolean oneHeader)
  {
    super(datepatterns, oneHeader);
    registerAttribHandler("domain", new RFC2965DomainAttributeHandler());
    registerAttribHandler("port", new RFC2965PortAttributeHandler());
    registerAttribHandler("commenturl", new RFC2965CommentUrlAttributeHandler());
    registerAttribHandler("discard", new RFC2965DiscardAttributeHandler());
    registerAttribHandler("version", new RFC2965VersionAttributeHandler());
  }
  
  public List<Cookie> parse(Header header, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(header, "Header");
    Args.notNull(origin, "Cookie origin");
    if (!header.getName().equalsIgnoreCase("Set-Cookie2")) {
      throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'");
    }
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, adjustEffectiveHost(origin));
  }
  
  protected List<Cookie> parse(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    return createCookies(elems, adjustEffectiveHost(origin));
  }
  
  private List<Cookie> createCookies(HeaderElement[] elems, CookieOrigin origin)
    throws MalformedCookieException
  {
    List<Cookie> cookies = new ArrayList(elems.length);
    for (HeaderElement headerelement : elems)
    {
      String name = headerelement.getName();
      String value = headerelement.getValue();
      if ((name == null) || (name.length() == 0)) {
        throw new MalformedCookieException("Cookie name may not be empty");
      }
      BasicClientCookie2 cookie = new BasicClientCookie2(name, value);
      cookie.setPath(getDefaultPath(origin));
      cookie.setDomain(getDefaultDomain(origin));
      cookie.setPorts(new int[] { origin.getPort() });
      
      NameValuePair[] attribs = headerelement.getParameters();
      
      Map<String, NameValuePair> attribmap = new HashMap(attribs.length);
      for (int j = attribs.length - 1; j >= 0; j--)
      {
        NameValuePair param = attribs[j];
        attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
      }
      for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet())
      {
        NameValuePair attrib = (NameValuePair)entry.getValue();
        String s = attrib.getName().toLowerCase(Locale.ENGLISH);
        
        cookie.setAttribute(s, attrib.getValue());
        
        CookieAttributeHandler handler = findAttribHandler(s);
        if (handler != null) {
          handler.parse(cookie, attrib.getValue());
        }
      }
      cookies.add(cookie);
    }
    return cookies;
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    super.validate(cookie, adjustEffectiveHost(origin));
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    Args.notNull(cookie, "Cookie");
    Args.notNull(origin, "Cookie origin");
    return super.match(cookie, adjustEffectiveHost(origin));
  }
  
  protected void formatCookieAsVer(CharArrayBuffer buffer, Cookie cookie, int version)
  {
    super.formatCookieAsVer(buffer, cookie, version);
    if ((cookie instanceof ClientCookie))
    {
      String s = ((ClientCookie)cookie).getAttribute("port");
      if (s != null)
      {
        buffer.append("; $Port");
        buffer.append("=\"");
        if (s.trim().length() > 0)
        {
          int[] ports = cookie.getPorts();
          if (ports != null)
          {
            int len = ports.length;
            for (int i = 0; i < len; i++)
            {
              if (i > 0) {
                buffer.append(",");
              }
              buffer.append(Integer.toString(ports[i]));
            }
          }
        }
        buffer.append("\"");
      }
    }
  }
  
  private static CookieOrigin adjustEffectiveHost(CookieOrigin origin)
  {
    String host = origin.getHost();
    
    boolean isLocalHost = true;
    for (int i = 0; i < host.length(); i++)
    {
      char ch = host.charAt(i);
      if ((ch == '.') || (ch == ':'))
      {
        isLocalHost = false;
        break;
      }
    }
    if (isLocalHost)
    {
      host = host + ".local";
      return new CookieOrigin(host, origin.getPort(), origin.getPath(), origin.isSecure());
    }
    return origin;
  }
  
  public int getVersion()
  {
    return 1;
  }
  
  public Header getVersionHeader()
  {
    CharArrayBuffer buffer = new CharArrayBuffer(40);
    buffer.append("Cookie2");
    buffer.append(": ");
    buffer.append("$Version=");
    buffer.append(Integer.toString(getVersion()));
    return new BufferedHeader(buffer);
  }
  
  public String toString()
  {
    return "rfc2965";
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965Spec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import java.util.Collection;
import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecFactory;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class RFC2965SpecFactory
  implements CookieSpecFactory, CookieSpecProvider
{
  private final String[] datepatterns;
  private final boolean oneHeader;
  
  public RFC2965SpecFactory(String[] datepatterns, boolean oneHeader)
  {
    this.datepatterns = datepatterns;
    this.oneHeader = oneHeader;
  }
  
  public RFC2965SpecFactory()
  {
    this(null, false);
  }
  
  public CookieSpec newInstance(HttpParams params)
  {
    if (params != null)
    {
      String[] patterns = null;
      Collection<?> param = (Collection)params.getParameter("http.protocol.cookie-datepatterns");
      if (param != null)
      {
        patterns = new String[param.size()];
        patterns = (String[])param.toArray(patterns);
      }
      boolean singleHeader = params.getBooleanParameter("http.protocol.single-cookie-header", false);
      
      return new RFC2965Spec(patterns, singleHeader);
    }
    return new RFC2965Spec();
  }
  
  public CookieSpec create(HttpContext context)
  {
    return new RFC2965Spec(datepatterns, oneHeader);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965SpecFactory
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.cookie;

import org.apache.http.annotation.Immutable;
import org.apache.http.cookie.ClientCookie;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieRestrictionViolationException;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.cookie.SetCookie;
import org.apache.http.cookie.SetCookie2;
import org.apache.http.util.Args;

@Immutable
public class RFC2965VersionAttributeHandler
  implements CookieAttributeHandler
{
  public void parse(SetCookie cookie, String value)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (value == null) {
      throw new MalformedCookieException("Missing value for version attribute");
    }
    int version = -1;
    try
    {
      version = Integer.parseInt(value);
    }
    catch (NumberFormatException e)
    {
      version = -1;
    }
    if (version < 0) {
      throw new MalformedCookieException("Invalid cookie version.");
    }
    cookie.setVersion(version);
  }
  
  public void validate(Cookie cookie, CookieOrigin origin)
    throws MalformedCookieException
  {
    Args.notNull(cookie, "Cookie");
    if (((cookie instanceof SetCookie2)) && 
      ((cookie instanceof ClientCookie)) && (!((ClientCookie)cookie).containsAttribute("version"))) {
      throw new CookieRestrictionViolationException("Violates RFC 2965. Version attribute is required.");
    }
  }
  
  public boolean match(Cookie cookie, CookieOrigin origin)
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.cookie.RFC2965VersionAttributeHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.execchain;

import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import org.apache.http.HttpException;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.BackoffManager;
import org.apache.http.client.ConnectionBackoffStrategy;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.util.Args;

@Immutable
public class BackoffStrategyExec
  implements ClientExecChain
{
  private final ClientExecChain requestExecutor;
  private final ConnectionBackoffStrategy connectionBackoffStrategy;
  private final BackoffManager backoffManager;
  
  public BackoffStrategyExec(ClientExecChain requestExecutor, ConnectionBackoffStrategy connectionBackoffStrategy, BackoffManager backoffManager)
  {
    Args.notNull(requestExecutor, "HTTP client request executor");
    Args.notNull(connectionBackoffStrategy, "Connection backoff strategy");
    Args.notNull(backoffManager, "Backoff manager");
    this.requestExecutor = requestExecutor;
    this.connectionBackoffStrategy = connectionBackoffStrategy;
    this.backoffManager = backoffManager;
  }
  
  public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext context, HttpExecutionAware execAware)
    throws IOException, HttpException
  {
    Args.notNull(route, "HTTP route");
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");
    CloseableHttpResponse out = null;
    try
    {
      out = requestExecutor.execute(route, request, context, execAware);
    }
    catch (Exception ex)
    {
      if (out != null) {
        out.close();
      }
      if (connectionBackoffStrategy.shouldBackoff(ex)) {
        backoffManager.backOff(route);
      }
      if ((ex instanceof RuntimeException)) {
        throw ((RuntimeException)ex);
      }
      if ((ex instanceof HttpException)) {
        throw ((HttpException)ex);
      }
      if ((ex instanceof IOException)) {
        throw ((IOException)ex);
      }
      throw new UndeclaredThrowableException(ex);
    }
    if (connectionBackoffStrategy.shouldBackoff(out)) {
      backoffManager.backOff(route);
    } else {
      backoffManager.probe(route);
    }
    return out;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.execchain.BackoffStrategyExec
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.execchain;

import java.io.IOException;
import org.apache.http.HttpException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;

public abstract interface ClientExecChain
{
  public abstract CloseableHttpResponse execute(HttpRoute paramHttpRoute, HttpRequestWrapper paramHttpRequestWrapper, HttpClientContext paramHttpClientContext, HttpExecutionAware paramHttpExecutionAware)
    throws IOException, HttpException;
}

/* Location:
 * Qualified Name:     org.apache.http.impl.execchain.ClientExecChain
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.execchain;

import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.http.HttpClientConnection;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.concurrent.Cancellable;
import org.apache.http.conn.ConnectionReleaseTrigger;
import org.apache.http.conn.HttpClientConnectionManager;

@ThreadSafe
class ConnectionHolder
  implements ConnectionReleaseTrigger, Cancellable, Closeable
{
  private final Log log;
  private final HttpClientConnectionManager manager;
  private final HttpClientConnection managedConn;
  private volatile boolean reusable;
  private volatile Object state;
  private volatile long validDuration;
  private volatile TimeUnit tunit;
  private volatile boolean released;
  
  public ConnectionHolder(Log log, HttpClientConnectionManager manager, HttpClientConnection managedConn)
  {
    this.log = log;
    this.manager = manager;
    this.managedConn = managedConn;
  }
  
  public boolean isReusable()
  {
    return reusable;
  }
  
  public void markReusable()
  {
    reusable = true;
  }
  
  public void markNonReusable()
  {
    reusable = false;
  }
  
  public void setState(Object state)
  {
    this.state = state;
  }
  
  public void setValidFor(long duration, TimeUnit tunit)
  {
    synchronized (managedConn)
    {
      validDuration = duration;
      this.tunit = tunit;
    }
  }
  
  public void releaseConnection()
  {
    synchronized (managedConn)
    {
      if (released) {
        return;
      }
      released = true;
      if (reusable) {
        manager.releaseConnection(managedConn, state, validDuration, tunit);
      } else {
        try
        {
          managedConn.close();
          log.debug("Connection discarded");
        }
        catch (IOException ex)
        {
          if (log.isDebugEnabled()) {
            log.debug(ex.getMessage(), ex);
          }
        }
        finally
        {
          manager.releaseConnection(managedConn, null, 0L, TimeUnit.MILLISECONDS);
        }
      }
    }
  }
  
  public void abortConnection()
  {
    synchronized (managedConn)
    {
      if (released) {
        return;
      }
      released = true;
      try
      {
        managedConn.shutdown();
        log.debug("Connection discarded");
      }
      catch (IOException ex)
      {
        if (log.isDebugEnabled()) {
          log.debug(ex.getMessage(), ex);
        }
      }
      finally
      {
        manager.releaseConnection(managedConn, null, 0L, TimeUnit.MILLISECONDS);
      }
    }
  }
  
  public boolean cancel()
  {
    boolean alreadyReleased = released;
    log.debug("Cancelling request execution");
    abortConnection();
    return !alreadyReleased;
  }
  
  public boolean isReleased()
  {
    return released;
  }
  
  public void close()
    throws IOException
  {
    abortConnection();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.execchain.ConnectionHolder
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.execchain;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthProtocolState;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthState;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.client.NonRepeatableRequestException;
import org.apache.http.client.UserTokenHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.protocol.RequestClientConnControl;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.ConnectionRequest;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.routing.BasicRouteDirector;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRouteDirector;
import org.apache.http.conn.routing.RouteTracker;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.auth.HttpAuthenticator;
import org.apache.http.impl.conn.ConnectionShutdownException;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestUserAgent;
import org.apache.http.util.Args;
import org.apache.http.util.EntityUtils;

@Immutable
public class MainClientExec
  implements ClientExecChain
{
  private final Log log = LogFactory.getLog(getClass());
  private final HttpRequestExecutor requestExecutor;
  private final HttpClientConnectionManager connManager;
  private final ConnectionReuseStrategy reuseStrategy;
  private final ConnectionKeepAliveStrategy keepAliveStrategy;
  private final HttpProcessor proxyHttpProcessor;
  private final AuthenticationStrategy targetAuthStrategy;
  private final AuthenticationStrategy proxyAuthStrategy;
  private final HttpAuthenticator authenticator;
  private final UserTokenHandler userTokenHandler;
  private final HttpRouteDirector routeDirector;
  
  public MainClientExec(HttpRequestExecutor requestExecutor, HttpClientConnectionManager connManager, ConnectionReuseStrategy reuseStrategy, ConnectionKeepAliveStrategy keepAliveStrategy, AuthenticationStrategy targetAuthStrategy, AuthenticationStrategy proxyAuthStrategy, UserTokenHandler userTokenHandler)
  {
    Args.notNull(requestExecutor, "HTTP request executor");
    Args.notNull(connManager, "Client connection manager");
    Args.notNull(reuseStrategy, "Connection reuse strategy");
    Args.notNull(keepAliveStrategy, "Connection keep alive strategy");
    Args.notNull(targetAuthStrategy, "Target authentication strategy");
    Args.notNull(proxyAuthStrategy, "Proxy authentication strategy");
    Args.notNull(userTokenHandler, "User token handler");
    authenticator = new HttpAuthenticator();
    proxyHttpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] { new RequestClientConnControl(), new RequestUserAgent() });
    
    routeDirector = new BasicRouteDirector();
    this.requestExecutor = requestExecutor;
    this.connManager = connManager;
    this.reuseStrategy = reuseStrategy;
    this.keepAliveStrategy = keepAliveStrategy;
    this.targetAuthStrategy = targetAuthStrategy;
    this.proxyAuthStrategy = proxyAuthStrategy;
    this.userTokenHandler = userTokenHandler;
  }
  
  public CloseableHttpResponse execute(HttpRoute route, HttpRequestWrapper request, HttpClientContext context, HttpExecutionAware execAware)
    throws IOException, HttpException
  {
    Args.notNull(route, "HTTP route");
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");
    
    AuthState targetAuthState = context.getTargetAuthState();
    if (targetAuthState == null)
    {
      targetAuthState = new AuthState();
      context.setAttribute("http.auth.target-scope", targetAuthState);
    }
    AuthState proxyAuthState = context.getProxyAuthState();
    if (proxyAuthState == null)
    {
      proxyAuthState = new AuthState();
      context.setAttribute("http.auth.proxy-scope", proxyAuthState);
    }
    if ((request instanceof HttpEntityEnclosingRequest)) {
      Proxies.enhanceEntity((HttpEntityEnclosingRequest)request);
    }
    Object userToken = context.getUserToken();
    
    ConnectionRequest connRequest = connManager.requestConnection(route, userToken);
    if (execAware != null)
    {
      if (execAware.isAborted())
      {
        connRequest.cancel();
        throw new RequestAbortedException("Request aborted");
      }
      execAware.setCancellable(connRequest);
    }
    RequestConfig config = context.getRequestConfig();
    HttpClientConnection managedConn;
    try
    {
      int timeout = config.getConnectionRequestTimeout();
      managedConn = connRequest.get(timeout > 0 ? timeout : 0L, TimeUnit.MILLISECONDS);
    }
    catch (InterruptedException interrupted)
    {
      Thread.currentThread().interrupt();
      throw new RequestAbortedException("Request aborted", interrupted);
    }
    catch (ExecutionException ex)
    {
      Throwable cause = ex.getCause();
      if (cause == null) {
        cause = ex;
      }
      throw new RequestAbortedException("Request execution failed", cause);
    }
    context.setAttribute("http.connection", managedConn);
    if (config.isStaleConnectionCheckEnabled()) {
      if (managedConn.isOpen())
      {
        log.debug("Stale connection check");
        if (managedConn.isStale())
        {
          log.debug("Stale connection detected");
          managedConn.close();
        }
      }
    }
    ConnectionHolder connHolder = new ConnectionHolder(log, connManager, managedConn);
    try
    {
      if (execAware != null) {
        execAware.setCancellable(connHolder);
      }
      HttpResponse response;
      for (int execCount = 1;; execCount++)
      {
        if ((execCount > 1) && (!Proxies.isRepeatable(request))) {
          throw new NonRepeatableRequestException("Cannot retry request with a non-repeatable request entity.");
        }
        if ((execAware != null) && (execAware.isAborted())) {
          throw new RequestAbortedException("Request aborted");
        }
        if (!managedConn.isOpen())
        {
          log.debug("Opening connection " + route);
          try
          {
            establishRoute(proxyAuthState, managedConn, route, request, context);
          }
          catch (TunnelRefusedException ex)
          {
            if (log.isDebugEnabled()) {
              log.debug(ex.getMessage());
            }
            HttpResponse response = ex.getResponse();
            break;
          }
        }
        int timeout = config.getSocketTimeout();
        if (timeout >= 0) {
          managedConn.setSocketTimeout(timeout);
        }
        if ((execAware != null) && (execAware.isAborted())) {
          throw new RequestAbortedException("Request aborted");
        }
        if (log.isDebugEnabled()) {
          log.debug("Executing request " + request.getRequestLine());
        }
        if (!request.containsHeader("Authorization"))
        {
          if (log.isDebugEnabled()) {
            log.debug("Target auth state: " + targetAuthState.getState());
          }
          authenticator.generateAuthResponse(request, targetAuthState, context);
        }
        if ((!request.containsHeader("Proxy-Authorization")) && (!route.isTunnelled()))
        {
          if (log.isDebugEnabled()) {
            log.debug("Proxy auth state: " + proxyAuthState.getState());
          }
          authenticator.generateAuthResponse(request, proxyAuthState, context);
        }
        response = requestExecutor.execute(request, managedConn, context);
        if (reuseStrategy.keepAlive(response, context))
        {
          long duration = keepAliveStrategy.getKeepAliveDuration(response, context);
          if (log.isDebugEnabled())
          {
            String s;
            String s;
            if (duration > 0L) {
              s = "for " + duration + " " + TimeUnit.MILLISECONDS;
            } else {
              s = "indefinitely";
            }
            log.debug("Connection can be kept alive " + s);
          }
          connHolder.setValidFor(duration, TimeUnit.MILLISECONDS);
          connHolder.markReusable();
        }
        else
        {
          connHolder.markNonReusable();
        }
        if (!needAuthentication(targetAuthState, proxyAuthState, route, response, context)) {
          break;
        }
        HttpEntity entity = response.getEntity();
        if (connHolder.isReusable())
        {
          EntityUtils.consume(entity);
        }
        else
        {
          managedConn.close();
          if ((proxyAuthState.getState() == AuthProtocolState.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd