com.crashlytics.tools.android_2.1.0

e());
    }
    String response = null;
    if (state == State.FAILED) {
      throw new AuthenticationException("NTLM authentication failed");
    }
    if (state == State.CHALLENGE_RECEIVED)
    {
      response = engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getWorkstation());
      
      state = State.MSG_TYPE1_GENERATED;
    }
    else if (state == State.MSG_TYPE2_RECEVIED)
    {
      response = engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getWorkstation(), challenge);
      
      state = State.MSG_TYPE3_GENERATED;
    }
    else
    {
      throw new AuthenticationException("Unexpected state: " + state);
    }
    CharArrayBuffer buffer = new CharArrayBuffer(32);
    if (isProxy()) {
      buffer.append("Proxy-Authorization");
    } else {
      buffer.append("Authorization");
    }
    buffer.append(": NTLM ");
    buffer.append(response);
    return new BufferedHeader(buffer);
  }
  
  public boolean isComplete()
  {
    return (state == State.MSG_TYPE3_GENERATED) || (state == State.FAILED);
  }
}

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

import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeFactory;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class NTLMSchemeFactory
  implements AuthSchemeFactory, AuthSchemeProvider
{
  public AuthScheme newInstance(HttpParams params)
  {
    return new NTLMScheme();
  }
  
  public AuthScheme create(HttpContext context)
  {
    return new NTLMScheme();
  }
}

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

import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.Oid;

@Deprecated
public class NegotiateScheme
  extends GGSSchemeBase
{
  private final Log log = LogFactory.getLog(getClass());
  private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
  private static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
  private final SpnegoTokenGenerator spengoGenerator;
  
  public NegotiateScheme(SpnegoTokenGenerator spengoGenerator, boolean stripPort)
  {
    super(stripPort);
    this.spengoGenerator = spengoGenerator;
  }
  
  public NegotiateScheme(SpnegoTokenGenerator spengoGenerator)
  {
    this(spengoGenerator, false);
  }
  
  public NegotiateScheme()
  {
    this(null, false);
  }
  
  public String getSchemeName()
  {
    return "Negotiate";
  }
  
  public Header authenticate(Credentials credentials, HttpRequest request)
    throws AuthenticationException
  {
    return authenticate(credentials, request, null);
  }
  
  public Header authenticate(Credentials credentials, HttpRequest request, HttpContext context)
    throws AuthenticationException
  {
    return super.authenticate(credentials, request, context);
  }
  
  protected byte[] generateToken(byte[] input, String authServer)
    throws GSSException
  {
    Oid negotiationOid = new Oid("1.3.6.1.5.5.2");
    
    byte[] token = input;
    boolean tryKerberos = false;
    try
    {
      token = generateGSSToken(token, negotiationOid, authServer);
    }
    catch (GSSException ex)
    {
      if (ex.getMajor() == 2)
      {
        log.debug("GSSException BAD_MECH, retry with Kerberos MECH");
        tryKerberos = true;
      }
      else
      {
        throw ex;
      }
    }
    if (tryKerberos)
    {
      log.debug("Using Kerberos MECH 1.2.840.113554.1.2.2");
      negotiationOid = new Oid("1.2.840.113554.1.2.2");
      token = generateGSSToken(token, negotiationOid, authServer);
      if ((token != null) && (spengoGenerator != null)) {
        try
        {
          token = spengoGenerator.generateSpnegoDERObject(token);
        }
        catch (IOException ex)
        {
          log.error(ex.getMessage(), ex);
        }
      }
    }
    return token;
  }
  
  public String getParameter(String name)
  {
    Args.notNull(name, "Parameter name");
    return null;
  }
  
  public String getRealm()
  {
    return null;
  }
  
  public boolean isConnectionBased()
  {
    return true;
  }
}

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

import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeFactory;
import org.apache.http.params.HttpParams;

@Deprecated
public class NegotiateSchemeFactory
  implements AuthSchemeFactory
{
  private final SpnegoTokenGenerator spengoGenerator;
  private final boolean stripPort;
  
  public NegotiateSchemeFactory(SpnegoTokenGenerator spengoGenerator, boolean stripPort)
  {
    this.spengoGenerator = spengoGenerator;
    this.stripPort = stripPort;
  }
  
  public NegotiateSchemeFactory(SpnegoTokenGenerator spengoGenerator)
  {
    this(spengoGenerator, false);
  }
  
  public NegotiateSchemeFactory()
  {
    this(null, false);
  }
  
  public AuthScheme newInstance(HttpParams params)
  {
    return new NegotiateScheme(spengoGenerator, stripPort);
  }
  
  public boolean isStripPort()
  {
    return stripPort;
  }
  
  public SpnegoTokenGenerator getSpengoGenerator()
  {
    return spengoGenerator;
  }
}

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

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.http.Consts;
import org.apache.http.HeaderElement;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.ChallengeState;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.message.BasicHeaderValueParser;
import org.apache.http.message.HeaderValueParser;
import org.apache.http.message.ParserCursor;
import org.apache.http.params.HttpParams;
import org.apache.http.util.CharArrayBuffer;

@NotThreadSafe
public abstract class RFC2617Scheme
  extends AuthSchemeBase
{
  private final Map<String, String> params;
  private final Charset credentialsCharset;
  
  @Deprecated
  public RFC2617Scheme(ChallengeState challengeState)
  {
    super(challengeState);
    params = new HashMap();
    credentialsCharset = Consts.ASCII;
  }
  
  public RFC2617Scheme(Charset credentialsCharset)
  {
    params = new HashMap();
    this.credentialsCharset = (credentialsCharset != null ? credentialsCharset : Consts.ASCII);
  }
  
  public RFC2617Scheme()
  {
    this(Consts.ASCII);
  }
  
  public Charset getCredentialsCharset()
  {
    return credentialsCharset;
  }
  
  String getCredentialsCharset(HttpRequest request)
  {
    String charset = (String)request.getParams().getParameter("http.auth.credential-charset");
    if (charset == null) {
      charset = getCredentialsCharset().name();
    }
    return charset;
  }
  
  protected void parseChallenge(CharArrayBuffer buffer, int pos, int len)
    throws MalformedChallengeException
  {
    HeaderValueParser parser = BasicHeaderValueParser.INSTANCE;
    ParserCursor cursor = new ParserCursor(pos, buffer.length());
    HeaderElement[] elements = parser.parseElements(buffer, cursor);
    if (elements.length == 0) {
      throw new MalformedChallengeException("Authentication challenge is empty");
    }
    params.clear();
    for (HeaderElement element : elements) {
      params.put(element.getName(), element.getValue());
    }
  }
  
  protected Map<String, String> getParameters()
  {
    return params;
  }
  
  public String getParameter(String name)
  {
    if (name == null) {
      return null;
    }
    return (String)params.get(name.toLowerCase(Locale.ENGLISH));
  }
  
  public String getRealm()
  {
    return getParameter("realm");
  }
}

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

import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;
import org.ietf.jgss.GSSException;
import org.ietf.jgss.Oid;

@NotThreadSafe
public class SPNegoScheme
  extends GGSSchemeBase
{
  private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
  
  public SPNegoScheme(boolean stripPort)
  {
    super(stripPort);
  }
  
  public SPNegoScheme()
  {
    super(false);
  }
  
  public String getSchemeName()
  {
    return "Negotiate";
  }
  
  public Header authenticate(Credentials credentials, HttpRequest request, HttpContext context)
    throws AuthenticationException
  {
    return super.authenticate(credentials, request, context);
  }
  
  protected byte[] generateToken(byte[] input, String authServer)
    throws GSSException
  {
    return generateGSSToken(input, new Oid("1.3.6.1.5.5.2"), authServer);
  }
  
  public String getParameter(String name)
  {
    Args.notNull(name, "Parameter name");
    return null;
  }
  
  public String getRealm()
  {
    return null;
  }
  
  public boolean isConnectionBased()
  {
    return true;
  }
}

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

import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeFactory;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

@Immutable
public class SPNegoSchemeFactory
  implements AuthSchemeFactory, AuthSchemeProvider
{
  private final boolean stripPort;
  
  public SPNegoSchemeFactory(boolean stripPort)
  {
    this.stripPort = stripPort;
  }
  
  public SPNegoSchemeFactory()
  {
    this(false);
  }
  
  public boolean isStripPort()
  {
    return stripPort;
  }
  
  public AuthScheme newInstance(HttpParams params)
  {
    return new SPNegoScheme(stripPort);
  }
  
  public AuthScheme create(HttpContext context)
  {
    return new SPNegoScheme(stripPort);
  }
}

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

import java.io.IOException;

@Deprecated
public abstract interface SpnegoTokenGenerator
{
  public abstract byte[] generateSpnegoDERObject(byte[] paramArrayOfByte)
    throws IOException;
}

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

import org.apache.http.annotation.Immutable;

@Immutable
public class UnsupportedDigestAlgorithmException
  extends RuntimeException
{
  private static final long serialVersionUID = 319558534317118022L;
  
  public UnsupportedDigestAlgorithmException() {}
  
  public UnsupportedDigestAlgorithmException(String message)
  {
    super(message);
  }
  
  public UnsupportedDigestAlgorithmException(String message, Throwable cause)
  {
    super(message, cause);
  }
}

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

import java.util.HashMap;
import java.util.Map;
import org.apache.http.client.BackoffManager;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.pool.ConnPoolControl;
import org.apache.http.util.Args;

public class AIMDBackoffManager
  implements BackoffManager
{
  private final ConnPoolControl<HttpRoute> connPerRoute;
  private final Clock clock;
  private final Map<HttpRoute, Long> lastRouteProbes;
  private final Map<HttpRoute, Long> lastRouteBackoffs;
  private long coolDown = 5000L;
  private double backoffFactor = 0.5D;
  private int cap = 2;
  
  public AIMDBackoffManager(ConnPoolControl<HttpRoute> connPerRoute)
  {
    this(connPerRoute, new SystemClock());
  }
  
  AIMDBackoffManager(ConnPoolControl<HttpRoute> connPerRoute, Clock clock)
  {
    this.clock = clock;
    this.connPerRoute = connPerRoute;
    lastRouteProbes = new HashMap();
    lastRouteBackoffs = new HashMap();
  }
  
  public void backOff(HttpRoute route)
  {
    synchronized (connPerRoute)
    {
      int curr = connPerRoute.getMaxPerRoute(route);
      Long lastUpdate = getLastUpdate(lastRouteBackoffs, route);
      long now = clock.getCurrentTime();
      if (now - lastUpdate.longValue() < coolDown) {
        return;
      }
      connPerRoute.setMaxPerRoute(route, getBackedOffPoolSize(curr));
      lastRouteBackoffs.put(route, Long.valueOf(now));
    }
  }
  
  private int getBackedOffPoolSize(int curr)
  {
    if (curr <= 1) {
      return 1;
    }
    return (int)Math.floor(backoffFactor * curr);
  }
  
  public void probe(HttpRoute route)
  {
    synchronized (connPerRoute)
    {
      int curr = connPerRoute.getMaxPerRoute(route);
      int max = curr >= cap ? cap : curr + 1;
      Long lastProbe = getLastUpdate(lastRouteProbes, route);
      Long lastBackoff = getLastUpdate(lastRouteBackoffs, route);
      long now = clock.getCurrentTime();
      if ((now - lastProbe.longValue() < coolDown) || (now - lastBackoff.longValue() < coolDown)) {
        return;
      }
      connPerRoute.setMaxPerRoute(route, max);
      lastRouteProbes.put(route, Long.valueOf(now));
    }
  }
  
  private Long getLastUpdate(Map<HttpRoute, Long> updates, HttpRoute route)
  {
    Long lastUpdate = (Long)updates.get(route);
    if (lastUpdate == null) {
      lastUpdate = Long.valueOf(0L);
    }
    return lastUpdate;
  }
  
  public void setBackoffFactor(double d)
  {
    Args.check((d > 0.0D) && (d < 1.0D), "Backoff factor must be 0.0 < f < 1.0");
    backoffFactor = d;
  }
  
  public void setCooldownMillis(long l)
  {
    Args.positive(coolDown, "Cool down");
    coolDown = l;
  }
  
  public void setPerHostConnectionCap(int cap)
  {
    Args.positive(cap, "Per host connection cap");
    this.cap = cap;
  }
}

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

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.FormattedHeader;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeRegistry;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.client.AuthenticationHandler;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Asserts;
import org.apache.http.util.CharArrayBuffer;

@Deprecated
@Immutable
public abstract class AbstractAuthenticationHandler
  implements AuthenticationHandler
{
  private final Log log = LogFactory.getLog(getClass());
  private static final List<String> DEFAULT_SCHEME_PRIORITY = Collections.unmodifiableList(Arrays.asList(new String[] { "negotiate", "NTLM", "Digest", "Basic" }));
  
  protected Map<String, Header> parseChallenges(Header[] headers)
    throws MalformedChallengeException
  {
    Map<String, Header> map = new HashMap(headers.length);
    for (Header header : headers)
    {
      int pos;
      CharArrayBuffer buffer;
      int pos;
      if ((header instanceof FormattedHeader))
      {
        CharArrayBuffer buffer = ((FormattedHeader)header).getBuffer();
        pos = ((FormattedHeader)header).getValuePos();
      }
      else
      {
        String s = header.getValue();
        if (s == null) {
          throw new MalformedChallengeException("Header value is null");
        }
        buffer = new CharArrayBuffer(s.length());
        buffer.append(s);
        pos = 0;
      }
      while ((pos < buffer.length()) && (HTTP.isWhitespace(buffer.charAt(pos)))) {
        pos++;
      }
      int beginIndex = pos;
      while ((pos < buffer.length()) && (!HTTP.isWhitespace(buffer.charAt(pos)))) {
        pos++;
      }
      int endIndex = pos;
      String s = buffer.substring(beginIndex, endIndex);
      map.put(s.toLowerCase(Locale.US), header);
    }
    return map;
  }
  
  protected List<String> getAuthPreferences()
  {
    return DEFAULT_SCHEME_PRIORITY;
  }
  
  protected List<String> getAuthPreferences(HttpResponse response, HttpContext context)
  {
    return getAuthPreferences();
  }
  
  public AuthScheme selectScheme(Map<String, Header> challenges, HttpResponse response, HttpContext context)
    throws AuthenticationException
  {
    AuthSchemeRegistry registry = (AuthSchemeRegistry)context.getAttribute("http.authscheme-registry");
    
    Asserts.notNull(registry, "AuthScheme registry");
    Collection<String> authPrefs = getAuthPreferences(response, context);
    if (authPrefs == null) {
      authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (log.isDebugEnabled()) {
      log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }
    AuthScheme authScheme = null;
    for (String id : authPrefs)
    {
      Header challenge = (Header)challenges.get(id.toLowerCase(Locale.ENGLISH));
      if (challenge != null)
      {
        if (log.isDebugEnabled()) {
          log.debug(id + " authentication scheme selected");
        }
        try
        {
          authScheme = registry.getAuthScheme(id, response.getParams());
        }
        catch (IllegalStateException e)
        {
          if (log.isWarnEnabled()) {
            log.warn("Authentication scheme " + id + " not supported");
          }
          break label293;
        }
      }
      else if (log.isDebugEnabled())
      {
        log.debug("Challenge for " + id + " authentication scheme not available");
      }
    }
    label293:
    if (authScheme == null) {
      throw new AuthenticationException("Unable to respond to any of these challenges: " + challenges);
    }
    return authScheme;
  }
}

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

import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.annotation.GuardedBy;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.auth.AuthSchemeRegistry;
import org.apache.http.client.AuthenticationHandler;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.client.BackoffManager;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ConnectionBackoffStrategy;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.RedirectHandler;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.RequestDirector;
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.params.HttpClientParamConfig;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionManagerFactory;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.cookie.CookieSpecRegistry;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.auth.BasicSchemeFactory;
import org.apache.http.impl.auth.DigestSchemeFactory;
import org.apache.http.impl.auth.KerberosSchemeFactory;
import org.apache.http.impl.auth.NTLMSchemeFactory;
import org.apache.http.impl.auth.SPNegoSchemeFactory;
import org.apache.http.impl.conn.BasicClientConnectionManager;
import org.apache.http.impl.conn.DefaultHttpRoutePlanner;
import org.apache.http.impl.conn.SchemeRegistryFactory;
import org.apache.http.impl.cookie.BestMatchSpecFactory;
import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
import org.apache.http.impl.cookie.IgnoreSpecFactory;
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2109SpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.DefaultedHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.util.Args;

@Deprecated
@ThreadSafe
public abstract class AbstractHttpClient
  extends CloseableHttpClient
{
  private final Log log = LogFactory.getLog(getClass());
  @GuardedBy("this")
  private HttpParams defaultParams;
  @GuardedBy("this")
  private HttpRequestExecutor requestExec;
  @GuardedBy("this")
  private ClientConnectionManager connManager;
  @GuardedBy("this")
  private ConnectionReuseStrategy reuseStrategy;
  @GuardedBy("this")
  private ConnectionKeepAliveStrategy keepAliveStrategy;
  @GuardedBy("this")
  private CookieSpecRegistry supportedCookieSpecs;
  @GuardedBy("this")
  private AuthSchemeRegistry supportedAuthSchemes;
  @GuardedBy("this")
  private BasicHttpProcessor mutableProcessor;
  @GuardedBy("this")
  private ImmutableHttpProcessor protocolProcessor;
  @GuardedBy("this")
  private HttpRequestRetryHandler retryHandler;
  @GuardedBy("this")
  private RedirectStrategy redirectStrategy;
  @GuardedBy("this")
  private AuthenticationStrategy targetAuthStrategy;
  @GuardedBy("this")
  private AuthenticationStrategy proxyAuthStrategy;
  @GuardedBy("this")
  private CookieStore cookieStore;
  @GuardedBy("this")
  private CredentialsProvider credsProvider;
  @GuardedBy("this")
  private HttpRoutePlanner routePlanner;
  @GuardedBy("this")
  private UserTokenHandler userTokenHandler;
  @GuardedBy("this")
  private ConnectionBackoffStrategy connectionBackoffStrategy;
  @GuardedBy("this")
  private BackoffManager backoffManager;
  
  protected AbstractHttpClient(ClientConnectionManager conman, HttpParams params)
  {
    defaultParams = params;
    connManager = conman;
  }
  
  protected abstract HttpParams createHttpParams();
  
  protected abstract BasicHttpProcessor createHttpProcessor();
  
  protected HttpContext createHttpContext()
  {
    HttpContext context = new BasicHttpContext();
    context.setAttribute("http.scheme-registry", getConnectionManager().getSchemeRegistry());
    
    context.setAttribute("http.authscheme-registry", getAuthSchemes());
    
    context.setAttribute("http.cookiespec-registry", getCookieSpecs());
    
    context.setAttribute("http.cookie-store", getCookieStore());
    
    context.setAttribute("http.auth.credentials-provider", getCredentialsProvider());
    
    return context;
  }
  
  protected ClientConnectionManager createClientConnectionManager()
  {
    SchemeRegistry registry = SchemeRegistryFactory.createDefault();
    
    ClientConnectionManager connManager = null;
    HttpParams params = getParams();
    
    ClientConnectionManagerFactory factory = null;
    
    String className = (String)params.getParameter("http.connection-manager.factory-class-name");
    if (className != null) {
      try
      {
        Class<?> clazz = Class.forName(className);
        factory = (ClientConnectionManagerFactory)clazz.newInstance();
      }
      catch (ClassNotFoundException ex)
      {
        throw new IllegalStateException("Invalid class name: " + className);
      }
      catch (IllegalAccessException ex)
      {
        throw new IllegalAccessError(ex.getMessage());
      }
      catch (InstantiationException ex)
      {
        throw new InstantiationError(ex.getMessage());
      }
    }
    if (factory != null) {
      connManager = factory.newInstance(params, registry);
    } else {
      connManager = new BasicClientConnectionManager(registry);
    }
    return connManager;
  }
  
  protected AuthSchemeRegistry createAuthSchemeRegistry()
  {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register("Basic", new BasicSchemeFactory());
    
    registry.register("Digest", new DigestSchemeFactory());
    
    registry.register("NTLM", new NTLMSchemeFactory());
    
    registry.register("negotiate", new SPNegoSchemeFactory());
    
    registry.register("Kerberos", new KerberosSchemeFactory());
    
    return registry;
  }
  
  protected CookieSpecRegistry createCookieSpecRegistry()
  {
    CookieSpecRegistry registry = new CookieSpecRegistry();
    registry.register("best-match", new BestMatchSpecFactory());
    
    registry.register("compatibility", new BrowserCompatSpecFactory());
    
    registry.register("netscape", new NetscapeDraftSpecFactory());
    
    registry.register("rfc2109", new RFC2109SpecFactory());
    
    registry.register("rfc2965", new RFC2965SpecFactory());
    
    registry.register("ignoreCookies", new IgnoreSpecFactory());
    
    return registry;
  }
  
  protected HttpRequestExecutor createRequestExecutor()
  {
    return new HttpRequestExecutor();
  }
  
  protected ConnectionReuseStrategy createConnectionReuseStrategy()
  {
    return new DefaultConnectionReuseStrategy();
  }
  
  protected ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
  {
    return new DefaultConnectionKeepAliveStrategy();
  }
  
  protected HttpRequestRetryHandler createHttpRequestRetryHandler()
  {
    return new DefaultHttpRequestRetryHandler();
  }
  
  @Deprecated
  protected RedirectHandler createRedirectHandler()
  {
    return new DefaultRedirectHandler();
  }
  
  protected AuthenticationStrategy createTargetAuthenticationStrategy()
  {
    return new TargetAuthenticationStrategy();
  }
  
  @Deprecated
  protected AuthenticationHandler createTargetAuthenticationHandler()
  {
    return new DefaultTargetAuthenticationHandler();
  }
  
  protected AuthenticationStrategy createProxyAuthenticationStrategy()
  {
    return new ProxyAuthenticationStrategy();
  }
  
  @Deprecated
  protected AuthenticationHandler createProxyAuthenticationHandler()
  {
    return new DefaultProxyAuthenticationHandler();
  }
  
  protected CookieStore createCookieStore()
  {
    return new BasicCookieStore();
  }
  
  protected CredentialsProvider createCredentialsProvider()
  {
    return new BasicCredentialsProvider();
  }
  
  protected HttpRoutePlanner createHttpRoutePlanner()
  {
    return new DefaultHttpRoutePlanner(getConnectionManager().getSchemeRegistry());
  }
  
  protected UserTokenHandler createUserTokenHandler()
  {
    return new DefaultUserTokenHandler();
  }
  
  public final synchronized HttpParams getParams()
  {
    if (defaultParams == null) {
      defaultParams = createHttpParams();
    }
    return defaultParams;
  }
  
  public synchronized void setParams(HttpParams params)
  {
    defaultParams = params;
  }
  
  public final synchronized ClientConnectionManager getConnectionManager()
  {
    if (connManager == null) {
      connManager = createClientConnectionManager();
    }
    return connManager;
  }
  
  public final synchronized HttpRequestExecutor getRequestExecutor()
  {
    if (requestExec == null) {
      requestExec = createRequestExecutor();
    }
    return requestExec;
  }
  
  public final synchronized AuthSchemeRegistry getAuthSchemes()
  {
    if (supportedAuthSchemes == null) {
      supportedAuthSchemes = createAuthSchemeRegistry();
    }
    return supportedAuthSchemes;
  }
  
  public synchronized void setAuthSchemes(AuthSchemeRegistry registry)
  {
    supportedAuthSchemes = registry;
  }
  
  public final synchronized ConnectionBackoffStrategy getConnectionBackoffStrategy()
  {
    return connectionBackoffStrategy;
  }
  
  public synchronized void setConnectionBackoffStrategy(ConnectionBackoffStrategy strategy)
  {
    connectionBackoffStrategy = strategy;
  }
  
  public final synchronized CookieSpecRegistry getCookieSpecs()
  {
    if (supportedCookieSpecs == null) {
      supportedCookieSpecs = createCookieSpecRegistry();
    }
    return supportedCookieSpecs;
  }
  
  public final synchronized BackoffManager getBackoffManager()
  {
    return backoffManager;
  }
  
  public synchronized void setBackoffManager(BackoffManager manager)
  {
    backoffManager = manager;
  }
  
  public synchronized void setCookieSpecs(CookieSpecRegistry registry)
  {
    supportedCookieSpecs = registry;
  }
  
  public final synchronized ConnectionReuseStrategy getConnectionReuseStrategy()
  {
    if (reuseStrategy == null) {
      reuseStrategy = createConnectionReuseStrategy();
    }
    return reuseStrategy;
  }
  
  public synchronized void setReuseStrategy(ConnectionReuseStrategy strategy)
  {
    reuseStrategy = strategy;
  }
  
  public final synchronized ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy()
  {
    if (keepAliveStrategy == null) {
      keepAliveStrategy = createConnectionKeepAliveStrategy();
    }
    return keepAliveStrategy;
  }
  
  public synchronized void setKeepAliveStrategy(ConnectionKeepAliveStrategy strategy)
  {
    keepAliveStrategy = strategy;
  }
  
  public final synchronized HttpRequestRetryHandler getHttpRequestRetryHandler()
  {
    if (retryHandler == null) {
      retryHandler = createHttpRequestRetryHandler();
    }
    return retryHandler;
  }
  
  public synchronized void setHttpRequestRetryHandler(HttpRequestRetryHandler handler)
  {
    retryHandler = handler;
  }
  
  @Deprecated
  public final synchronized RedirectHandler getRedirectHandler()
  {
    return createRedirectHandler();
  }
  
  @Deprecated
  public synchronized void setRedirectHandler(RedirectHandler handler)
  {
    redirectStrategy = new DefaultRedirectStrategyAdaptor(handler);
  }
  
  public final synchronized RedirectStrategy getRedirectStrategy()
  {
    if (redirectStrategy == null) {
      redirectStrategy = new DefaultRedirectStrategy();
    }
    return redirectStrategy;
  }
  
  public synchronized void setRedirectStrategy(RedirectStrategy strategy)
  {
    redirectStrategy = strategy;
  }
  
  @Deprecated
  public final synchronized AuthenticationHandler getTargetAuthenticationHandler()
  {
    return createTargetAuthenticationHandler();
  }
  
  @Deprecated
  public synchronized void setTargetAuthenticationHandler(AuthenticationHandler handler)
  {
    targetAuthStrategy = new AuthenticationStrategyAdaptor(handler);
  }
  
  public final synchronized AuthenticationStrategy getTargetAuthenticationStrategy()
  {
    if (targetAuthStrategy == null) {
      targetAuthStrategy = createTargetAuthenticationStrategy();
    }
    return targetAuthStrategy;
  }
  
  public synchronized void setTargetAuthenticationStrategy(AuthenticationStrategy strategy)
  {
    targetAuthStrategy = strategy;
  }
  
  @Deprecated
  public final synchronized AuthenticationHandler getProxyAuthenticationHandler()
  {
    return createProxyAuthenticationHandler();
  }
  
  @Deprecated
  public synchronized void setProxyAuthenticationHandler(AuthenticationHandler handler)
  {
    proxyAuthStrategy = new AuthenticationStrategyAdaptor(handler);
  }
  
  public final synchronized AuthenticationStrategy getProxyAuthenticationStrategy()
  {
    if (proxyAuthStrategy == null) {
      proxyAuthStrategy = createProxyAuthenticationStrategy();
    }
    return proxyAuthStrategy;
  }
  
  public synchronized void setProxyAuthenticationStrategy(AuthenticationStrategy strategy)
  {
    proxyAuthStrategy = strategy;
  }
  
  public final synchronized CookieStore getCookieStore()
  {
    if (cookieStore == null) {
      cookieStore = createCookieStore();
    }
    return cookieStore;
  }
  
  public synchronized void setCookieStore(CookieStore cookieStore)
  {
    this.cookieStore = cookieStore;
  }
  
  public final synchronized CredentialsProvider getCredentialsProvider()
  {
    if (credsProvider == null) {
      credsProvider = createCredentialsProvider();
    }
    return credsProvider;
  }
  
  public synchronized void setCredentialsProvider(CredentialsProvider credsProvider)
  {
    this.credsProvider = credsProvider;
  }
  
  public final synchronized HttpRoutePlanner getRoutePlanner()
  {
    if (routePlanner == null) {
      routePlanner = createHttpRoutePlanner();
    }
    return routePlanner;
  }
  
  public synchronized void setRoutePlanner(HttpRoutePlanner routePlanner)
  {
    this.routePlanner = routePlanner;
  }
  
  public final synchronized UserTokenHandler getUserTokenHandler()
  {
    if (userTokenHandler == null) {
      userTokenHandler = createUserTokenHandler();
    }
    return userTokenHandler;
  }
  
  public synchronized void setUserTokenHandler(UserTokenHandler handler)
  {
    userTokenHandler = handler;
  }
  
  protected final synchronized BasicHttpProcessor getHttpProcessor()
  {
    if (mutableProcessor == null) {
      mutableProcessor = createHttpProcessor();
    }
    return mutableProcessor;
  }
  
  private synchronized HttpProcessor getProtocolProcessor()
  {
    if (protocolProcessor == null)
    {
      BasicHttpProcessor proc = getHttpProcessor();
      
      int reqc = proc.getRequestInterceptorCount();
      HttpRequestInterceptor[] reqinterceptors = new HttpRequestInterceptor[reqc];
      for (int i = 0; i < reqc; i++) {
        reqinterceptors[i] = proc.getRequestInterceptor(i);
      }
      int resc = proc.getResponseInterceptorCount();
      HttpResponseInterceptor[] resinterceptors = new HttpResponseInterceptor[resc];
      for (int i = 0; i < resc; i++) {
        resinterceptors[i] = proc.getResponseInterceptor(i);
      }
      protocolProcessor = new ImmutableHttpProcessor(reqinterceptors, resinterceptors);
    }
    return protocolProcessor;
  }
  
  public synchronized int getResponseInterceptorCount()
  {
    return getHttpProcessor().getResponseInterceptorCount();
  }
  
  public synchronized HttpResponseInterceptor getResponseInterceptor(int index)
  {
    return getHttpProcessor().getResponseInterceptor(index);
  }
  
  public synchronized HttpRequestInterceptor getRequestInterceptor(int index)
  {
    return getHttpProcessor().getRequestInterceptor(index);
  }
  
  public synchronized int getRequestInterceptorCount()
  {
    return getHttpProcessor().getRequestInterceptorCount();
  }
  
  public synchronized void addResponseInterceptor(HttpResponseInterceptor itcp)
  {
    getHttpProcessor().addInterceptor(itcp);
    protocolProcessor = null;
  }
  
  public synchronized void addResponseInterceptor(HttpResponseInterceptor itcp, int index)
  {
    getHttpProcessor().addInterceptor(itcp, index);
    protocolProcessor = null;
  }
  
  public synchronized void clearResponseInterceptors()
  {
    getHttpProcessor().clearResponseInterceptors();
    protocolProcessor = null;
  }
  
  public synchronized void removeResponseInterceptorByClass(Class<? extends HttpResponseInterceptor> clazz)
  {
    getHttpProcessor().removeResponseInterceptorByClass(clazz);
    protocolProcessor = null;
  }
  
  public synchronized void addRequestInterceptor(HttpRequestInterceptor itcp)
  {
    getHttpProcessor().addInterceptor(itcp);
    protocolProcessor = null;
  }
  
  public synchronized void addRequestInterceptor(HttpRequestInterceptor itcp, int index)
  {
    getHttpProcessor().addInterceptor(itcp, index);
    protocolProcessor = null;
  }
  
  public synchronized void clearRequestInterceptors()
  {
    getHttpProcessor().clearRequestInterceptors();
    protocolProcessor = null;
  }
  
  public synchronized void removeRequestInterceptorByClass(Class<? extends HttpRequestInterceptor> clazz)
  {
    getHttpProcessor().removeRequestInterceptorByClass(clazz);
    protocolProcessor = null;
  }
  
  protected final CloseableHttpResponse doExecute(HttpHost target, HttpRequest request, HttpContext context)
    throws IOException, ClientProtocolException
  {
    Args.notNull(request, "HTTP request");
    
    HttpContext execContext = null;
    RequestDirector director = null;
    HttpRoutePlanner routePlanner = null;
    ConnectionBackoffStrategy connectionBackoffStrategy = null;
    BackoffManager backoffManager = null;
    synchronized (this)
    {
      HttpContext defaultContext = createHttpContext();
      if (context == null) {
        execContext = defaultContext;
      } else {
        execContext = new DefaultedHttpContext(context, defaultContext);
      }
      HttpParams params = determineParams(request);
      RequestConfig config = HttpClientParamConfig.getRequestConfig(params);
      execContext.setAttribute("http.request-config", config);
      
      director = createClientRequestDirector(getRequestExecutor(), getConnectionManager(), getConnectionReuseStrategy(), getConnectionKeepAliveStrategy(), getRoutePlanner(), getProtocolProcessor(), getHttpRequestRetryHandler(), getRedirectStrategy(), getTargetAuthenticationStrategy(), getProxyAuthenticationStrategy(), getUserTokenHandler(), params);
      
      routePlanner = getRoutePlanner();
      connectionBackoffStrategy = getConnectionBackoffStrategy();
      backoffManager = getBackoffManager();
    }
    try
    {
      if ((connectionBackoffStrategy != null) && (backoffManager != null))
      {
        HttpHost targetForRoute = target != null ? target : (HttpHost)determineParams(request).getParameter("http.default-host");
        
        HttpRoute route = routePlanner.determineRoute(targetForRoute, request, execContext);
        CloseableHttpResponse out;
        try
        {
          out = CloseableHttpResponseProxy.newProxy(director.execute(target, request, execContext));
        }
        catch (RuntimeException re)
        {
          if (connectionBackoffStrategy.shouldBackoff(re)) {
            backoffManager.backOff(route);
          }
          throw re;
        }
        catch (Exception e)
        {
          if (connectionBackoffStrategy.shouldBackoff(e)) {
            backoffManager.backOff(route);
          }
          if ((e instanceof HttpException)) {
            throw ((HttpException)e);
          }
          if ((e instanceof IOException)) {
            throw ((IOException)e);
          }
          throw new UndeclaredThrowableException(e);
        }
        if (connectionBackoffStrategy.shoul
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