org.apache.commons.httpclient_3.1.0.v201012070820

16:41:00.546 INFO  jd.cli.Main - Decompiling org.apache.commons.httpclient_3.1.0.v201012070820.jar
package org.apache.commons.httpclient;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

class AutoCloseInputStream
  extends FilterInputStream
{
  private boolean streamOpen = true;
  private boolean selfClosed = false;
  private ResponseConsumedWatcher watcher = null;
  
  public AutoCloseInputStream(InputStream in, ResponseConsumedWatcher watcher)
  {
    super(in);
    this.watcher = watcher;
  }
  
  public int read()
    throws IOException
  {
    int l = -1;
    if (isReadAllowed())
    {
      l = super.read();
      checkClose(l);
    }
    return l;
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    int l = -1;
    if (isReadAllowed())
    {
      l = super.read(b, off, len);
      checkClose(l);
    }
    return l;
  }
  
  public int read(byte[] b)
    throws IOException
  {
    int l = -1;
    if (isReadAllowed())
    {
      l = super.read(b);
      checkClose(l);
    }
    return l;
  }
  
  public int available()
    throws IOException
  {
    int a = 0;
    if (isReadAllowed()) {
      a = super.available();
    }
    return a;
  }
  
  public void close()
    throws IOException
  {
    if (!selfClosed)
    {
      selfClosed = true;
      notifyWatcher();
    }
  }
  
  private void checkClose(int readResult)
    throws IOException
  {
    if (readResult == -1) {
      notifyWatcher();
    }
  }
  
  private boolean isReadAllowed()
    throws IOException
  {
    if ((!streamOpen) && (selfClosed)) {
      throw new IOException("Attempted read on closed stream.");
    }
    return streamOpen;
  }
  
  private void notifyWatcher()
    throws IOException
  {
    if (streamOpen)
    {
      super.close();
      streamOpen = false;
      if (watcher != null) {
        watcher.responseConsumed();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.AutoCloseInputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.util.EncodingUtil;
import org.apache.commons.httpclient.util.ExceptionUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ChunkedInputStream
  extends InputStream
{
  private InputStream in;
  private int chunkSize;
  private int pos;
  private boolean bof = true;
  private boolean eof = false;
  private boolean closed = false;
  private HttpMethod method = null;
  private static final Log LOG = LogFactory.getLog(ChunkedInputStream.class);
  
  public ChunkedInputStream(InputStream in, HttpMethod method)
    throws IOException
  {
    if (in == null) {
      throw new IllegalArgumentException("InputStream parameter may not be null");
    }
    this.in = in;
    this.method = method;
    pos = 0;
  }
  
  public ChunkedInputStream(InputStream in)
    throws IOException
  {
    this(in, null);
  }
  
  public int read()
    throws IOException
  {
    if (closed) {
      throw new IOException("Attempted read from closed stream.");
    }
    if (eof) {
      return -1;
    }
    if (pos >= chunkSize)
    {
      nextChunk();
      if (eof) {
        return -1;
      }
    }
    pos += 1;
    return in.read();
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    if (closed) {
      throw new IOException("Attempted read from closed stream.");
    }
    if (eof) {
      return -1;
    }
    if (pos >= chunkSize)
    {
      nextChunk();
      if (eof) {
        return -1;
      }
    }
    len = Math.min(len, chunkSize - pos);
    int count = in.read(b, off, len);
    pos += count;
    return count;
  }
  
  public int read(byte[] b)
    throws IOException
  {
    return read(b, 0, b.length);
  }
  
  private void readCRLF()
    throws IOException
  {
    int cr = in.read();
    int lf = in.read();
    if ((cr != 13) || (lf != 10)) {
      throw new IOException("CRLF expected at end of chunk: " + cr + "/" + lf);
    }
  }
  
  private void nextChunk()
    throws IOException
  {
    if (!bof) {
      readCRLF();
    }
    chunkSize = getChunkSizeFromInputStream(in);
    bof = false;
    pos = 0;
    if (chunkSize == 0)
    {
      eof = true;
      parseTrailerHeaders();
    }
  }
  
  private static int getChunkSizeFromInputStream(InputStream in)
    throws IOException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
    int state = 0;
    while (state != -1)
    {
      int b = in.read();
      if (b == -1) {
        throw new IOException("chunked stream ended unexpectedly");
      }
      switch (state)
      {
      case 0: 
        switch (b)
        {
        case 13: 
          state = 1;
          break;
        case 34: 
          state = 2;
        default: 
          baos.write(b);
        }
        break;
      case 1: 
        if (b == 10) {
          state = -1;
        } else {
          throw new IOException("Protocol violation: Unexpected single newline character in chunk size");
        }
        break;
      case 2: 
        switch (b)
        {
        case 92: 
          b = in.read();
          baos.write(b);
          break;
        case 34: 
          state = 0;
        default: 
          baos.write(b);
        }
        break;
      default: 
        throw new RuntimeException("assertion failed");
      }
    }
    String dataString = EncodingUtil.getAsciiString(baos.toByteArray());
    int separator = dataString.indexOf(';');
    dataString = separator > 0 ? dataString.substring(0, separator).trim() : dataString.trim();
    int result;
    try
    {
      result = Integer.parseInt(dataString.trim(), 16);
    }
    catch (NumberFormatException e)
    {
      throw new IOException("Bad chunk size: " + dataString);
    }
    return result;
  }
  
  private void parseTrailerHeaders()
    throws IOException
  {
    Header[] footers = null;
    try
    {
      String charset = "US-ASCII";
      if (method != null) {
        charset = method.getParams().getHttpElementCharset();
      }
      footers = HttpParser.parseHeaders(in, charset);
    }
    catch (HttpException e)
    {
      LOG.error("Error parsing trailer headers", e);
      IOException ioe = new IOException(e.getMessage());
      ExceptionUtil.initCause(ioe, e);
      throw ioe;
    }
    if (method != null) {
      for (int i = 0; i < footers.length; i++) {
        method.addResponseFooter(footers[i]);
      }
    }
  }
  
  public void close()
    throws IOException
  {
    if (!closed) {
      try
      {
        if (!eof) {
          exhaustInputStream(this);
        }
      }
      finally
      {
        eof = true;
        closed = true;
      }
    }
  }
  
  static void exhaustInputStream(InputStream inStream)
    throws IOException
  {
    byte[] buffer = new byte['?'];
    while (inStream.read(buffer) >= 0) {}
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.ChunkedInputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.httpclient.util.EncodingUtil;

public class ChunkedOutputStream
  extends OutputStream
{
  private static final byte[] CRLF = { 13, 10 };
  private static final byte[] ENDCHUNK = CRLF;
  private static final byte[] ZERO = { 48 };
  private OutputStream stream = null;
  private byte[] cache;
  private int cachePosition = 0;
  private boolean wroteLastChunk = false;
  
  public ChunkedOutputStream(OutputStream stream, int bufferSize)
    throws IOException
  {
    cache = new byte[bufferSize];
    this.stream = stream;
  }
  
  public ChunkedOutputStream(OutputStream stream)
    throws IOException
  {
    this(stream, 2048);
  }
  
  protected void flushCache()
    throws IOException
  {
    if (cachePosition > 0)
    {
      byte[] chunkHeader = EncodingUtil.getAsciiBytes(Integer.toHexString(cachePosition) + "\r\n");
      
      stream.write(chunkHeader, 0, chunkHeader.length);
      stream.write(cache, 0, cachePosition);
      stream.write(ENDCHUNK, 0, ENDCHUNK.length);
      cachePosition = 0;
    }
  }
  
  protected void flushCacheWithAppend(byte[] bufferToAppend, int off, int len)
    throws IOException
  {
    byte[] chunkHeader = EncodingUtil.getAsciiBytes(Integer.toHexString(cachePosition + len) + "\r\n");
    
    stream.write(chunkHeader, 0, chunkHeader.length);
    stream.write(cache, 0, cachePosition);
    stream.write(bufferToAppend, off, len);
    stream.write(ENDCHUNK, 0, ENDCHUNK.length);
    cachePosition = 0;
  }
  
  protected void writeClosingChunk()
    throws IOException
  {
    stream.write(ZERO, 0, ZERO.length);
    stream.write(CRLF, 0, CRLF.length);
    stream.write(ENDCHUNK, 0, ENDCHUNK.length);
  }
  
  public void finish()
    throws IOException
  {
    if (!wroteLastChunk)
    {
      flushCache();
      writeClosingChunk();
      wroteLastChunk = true;
    }
  }
  
  public void write(int b)
    throws IOException
  {
    cache[cachePosition] = ((byte)b);
    cachePosition += 1;
    if (cachePosition == cache.length) {
      flushCache();
    }
  }
  
  public void write(byte[] b)
    throws IOException
  {
    write(b, 0, b.length);
  }
  
  public void write(byte[] src, int off, int len)
    throws IOException
  {
    if (len >= cache.length - cachePosition)
    {
      flushCacheWithAppend(src, off, len);
    }
    else
    {
      System.arraycopy(src, off, cache, cachePosition, len);
      cachePosition += len;
    }
  }
  
  public void flush()
    throws IOException
  {
    stream.flush();
  }
  
  public void close()
    throws IOException
  {
    finish();
    super.close();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.ChunkedOutputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

public class CircularRedirectException
  extends RedirectException
{
  public CircularRedirectException() {}
  
  public CircularRedirectException(String message)
  {
    super(message);
  }
  
  public CircularRedirectException(String message, Throwable cause)
  {
    super(message, cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.CircularRedirectException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.IOException;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ConnectMethod
  extends HttpMethodBase
{
  public static final String NAME = "CONNECT";
  private final HostConfiguration targethost;
  
  /**
   * @deprecated
   */
  public ConnectMethod()
  {
    targethost = null;
  }
  
  /**
   * @deprecated
   */
  public ConnectMethod(HttpMethod method)
  {
    targethost = null;
  }
  
  public ConnectMethod(HostConfiguration targethost)
  {
    if (targethost == null) {
      throw new IllegalArgumentException("Target host may not be null");
    }
    this.targethost = targethost;
  }
  
  public String getName()
  {
    return "CONNECT";
  }
  
  public String getPath()
  {
    if (targethost != null)
    {
      StringBuffer buffer = new StringBuffer();
      buffer.append(targethost.getHost());
      int port = targethost.getPort();
      if (port == -1) {
        port = targethost.getProtocol().getDefaultPort();
      }
      buffer.append(':');
      buffer.append(port);
      return buffer.toString();
    }
    return "/";
  }
  
  public URI getURI()
    throws URIException
  {
    String charset = getParams().getUriCharset();
    return new URI(getPath(), true, charset);
  }
  
  protected void addCookieRequestHeader(HttpState state, HttpConnection conn)
    throws IOException, HttpException
  {}
  
  protected void addRequestHeaders(HttpState state, HttpConnection conn)
    throws IOException, HttpException
  {
    LOG.trace("enter ConnectMethod.addRequestHeaders(HttpState, HttpConnection)");
    
    addUserAgentRequestHeader(state, conn);
    addHostRequestHeader(state, conn);
    addProxyConnectionHeader(state, conn);
  }
  
  public int execute(HttpState state, HttpConnection conn)
    throws IOException, HttpException
  {
    LOG.trace("enter ConnectMethod.execute(HttpState, HttpConnection)");
    int code = super.execute(state, conn);
    if (LOG.isDebugEnabled()) {
      LOG.debug("CONNECT status code " + code);
    }
    return code;
  }
  
  protected void writeRequestLine(HttpState state, HttpConnection conn)
    throws IOException, HttpException
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append(getName());
    buffer.append(' ');
    if (targethost != null)
    {
      buffer.append(getPath());
    }
    else
    {
      int port = conn.getPort();
      if (port == -1) {
        port = conn.getProtocol().getDefaultPort();
      }
      buffer.append(conn.getHost());
      buffer.append(':');
      buffer.append(port);
    }
    buffer.append(" ");
    buffer.append(getEffectiveVersion());
    String line = buffer.toString();
    conn.printLine(line, getParams().getHttpElementCharset());
    if (Wire.HEADER_WIRE.enabled()) {
      Wire.HEADER_WIRE.output(line);
    }
  }
  
  protected boolean shouldCloseConnection(HttpConnection conn)
  {
    if (getStatusCode() == 200)
    {
      Header connectionHeader = null;
      if (!conn.isTransparent()) {
        connectionHeader = getResponseHeader("proxy-connection");
      }
      if (connectionHeader == null) {
        connectionHeader = getResponseHeader("connection");
      }
      if ((connectionHeader != null) && 
        (connectionHeader.getValue().equalsIgnoreCase("close")) && 
        (LOG.isWarnEnabled())) {
        LOG.warn("Invalid header encountered '" + connectionHeader.toExternalForm() + "' in response " + getStatusLine().toString());
      }
      return false;
    }
    return super.shouldCloseConnection(conn);
  }
  
  private static final Log LOG = LogFactory.getLog(ConnectMethod.class);
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.ConnectMethod
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.InterruptedIOException;
import org.apache.commons.httpclient.util.ExceptionUtil;

public class ConnectTimeoutException
  extends InterruptedIOException
{
  public ConnectTimeoutException() {}
  
  public ConnectTimeoutException(String message)
  {
    super(message);
  }
  
  public ConnectTimeoutException(String message, Throwable cause)
  {
    super(message);
    
    ExceptionUtil.initCause(this, cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.ConnectTimeoutException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

public class ConnectionPoolTimeoutException
  extends ConnectTimeoutException
{
  public ConnectionPoolTimeoutException() {}
  
  public ConnectionPoolTimeoutException(String message)
  {
    super(message);
  }
  
  public ConnectionPoolTimeoutException(String message, Throwable cause)
  {
    super(message, cause);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.ConnectionPoolTimeoutException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.IOException;
import java.io.InputStream;

public class ContentLengthInputStream
  extends InputStream
{
  private long contentLength;
  private long pos = 0L;
  private boolean closed = false;
  private InputStream wrappedStream = null;
  
  /**
   * @deprecated
   */
  public ContentLengthInputStream(InputStream in, int contentLength)
  {
    this(in, contentLength);
  }
  
  public ContentLengthInputStream(InputStream in, long contentLength)
  {
    wrappedStream = in;
    this.contentLength = contentLength;
  }
  
  public void close()
    throws IOException
  {
    if (!closed) {
      try
      {
        ChunkedInputStream.exhaustInputStream(this);
      }
      finally
      {
        closed = true;
      }
    }
  }
  
  public int read()
    throws IOException
  {
    if (closed) {
      throw new IOException("Attempted read from closed stream.");
    }
    if (pos >= contentLength) {
      return -1;
    }
    pos += 1L;
    return wrappedStream.read();
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    if (closed) {
      throw new IOException("Attempted read from closed stream.");
    }
    if (pos >= contentLength) {
      return -1;
    }
    if (pos + len > contentLength) {
      len = (int)(contentLength - pos);
    }
    int count = wrappedStream.read(b, off, len);
    pos += count;
    return count;
  }
  
  public int read(byte[] b)
    throws IOException
  {
    return read(b, 0, b.length);
  }
  
  public long skip(long n)
    throws IOException
  {
    long length = Math.min(n, contentLength - pos);
    
    length = wrappedStream.skip(length);
    if (length > 0L) {
      pos += length;
    }
    return length;
  }
  
  public int available()
    throws IOException
  {
    if (closed) {
      return 0;
    }
    int avail = wrappedStream.available();
    if (pos + avail > contentLength) {
      avail = (int)(contentLength - pos);
    }
    return avail;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.ContentLengthInputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.util.LangUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Cookie
  extends NameValuePair
  implements Serializable, Comparator
{
  private String cookieComment;
  private String cookieDomain;
  private Date cookieExpiryDate;
  private String cookiePath;
  private boolean isSecure;
  
  public Cookie()
  {
    this(null, "noname", null, null, null, false);
  }
  
  public Cookie(String domain, String name, String value)
  {
    this(domain, name, value, null, null, false);
  }
  
  public Cookie(String domain, String name, String value, String path, Date expires, boolean secure)
  {
    super(name, value);
    LOG.trace("enter Cookie(String, String, String, String, Date, boolean)");
    if (name == null) {
      throw new IllegalArgumentException("Cookie name may not be null");
    }
    if (name.trim().equals("")) {
      throw new IllegalArgumentException("Cookie name may not be blank");
    }
    setPath(path);
    setDomain(domain);
    setExpiryDate(expires);
    setSecure(secure);
  }
  
  public Cookie(String domain, String name, String value, String path, int maxAge, boolean secure)
  {
    this(domain, name, value, path, null, secure);
    if (maxAge < -1) {
      throw new IllegalArgumentException("Invalid max age:  " + Integer.toString(maxAge));
    }
    if (maxAge >= 0) {
      setExpiryDate(new Date(System.currentTimeMillis() + maxAge * 1000L));
    }
  }
  
  public String getComment()
  {
    return cookieComment;
  }
  
  public void setComment(String comment)
  {
    cookieComment = comment;
  }
  
  public Date getExpiryDate()
  {
    return cookieExpiryDate;
  }
  
  public void setExpiryDate(Date expiryDate)
  {
    cookieExpiryDate = expiryDate;
  }
  
  public boolean isPersistent()
  {
    return null != cookieExpiryDate;
  }
  
  public String getDomain()
  {
    return cookieDomain;
  }
  
  public void setDomain(String domain)
  {
    if (domain != null)
    {
      int ndx = domain.indexOf(":");
      if (ndx != -1) {
        domain = domain.substring(0, ndx);
      }
      cookieDomain = domain.toLowerCase();
    }
  }
  
  public String getPath()
  {
    return cookiePath;
  }
  
  public void setPath(String path)
  {
    cookiePath = path;
  }
  
  public boolean getSecure()
  {
    return isSecure;
  }
  
  public void setSecure(boolean secure)
  {
    isSecure = secure;
  }
  
  public int getVersion()
  {
    return cookieVersion;
  }
  
  public void setVersion(int version)
  {
    cookieVersion = version;
  }
  
  public boolean isExpired()
  {
    return (cookieExpiryDate != null) && (cookieExpiryDate.getTime() <= System.currentTimeMillis());
  }
  
  public boolean isExpired(Date now)
  {
    return (cookieExpiryDate != null) && (cookieExpiryDate.getTime() <= now.getTime());
  }
  
  public void setPathAttributeSpecified(boolean value)
  {
    hasPathAttribute = value;
  }
  
  public boolean isPathAttributeSpecified()
  {
    return hasPathAttribute;
  }
  
  public void setDomainAttributeSpecified(boolean value)
  {
    hasDomainAttribute = value;
  }
  
  public boolean isDomainAttributeSpecified()
  {
    return hasDomainAttribute;
  }
  
  public int hashCode()
  {
    int hash = 17;
    hash = LangUtils.hashCode(hash, getName());
    hash = LangUtils.hashCode(hash, cookieDomain);
    hash = LangUtils.hashCode(hash, cookiePath);
    return hash;
  }
  
  public boolean equals(Object obj)
  {
    if (obj == null) {
      return false;
    }
    if (this == obj) {
      return true;
    }
    if ((obj instanceof Cookie))
    {
      Cookie that = (Cookie)obj;
      return (LangUtils.equals(getName(), that.getName())) && (LangUtils.equals(cookieDomain, cookieDomain)) && (LangUtils.equals(cookiePath, cookiePath));
    }
    return false;
  }
  
  public String toExternalForm()
  {
    CookieSpec spec = null;
    if (getVersion() > 0) {
      spec = CookiePolicy.getDefaultSpec();
    } else {
      spec = CookiePolicy.getCookieSpec("netscape");
    }
    return spec.formatCookie(this);
  }
  
  public int compare(Object o1, Object o2)
  {
    LOG.trace("enter Cookie.compare(Object, Object)");
    if (!(o1 instanceof Cookie)) {
      throw new ClassCastException(o1.getClass().getName());
    }
    if (!(o2 instanceof Cookie)) {
      throw new ClassCastException(o2.getClass().getName());
    }
    Cookie c1 = (Cookie)o1;
    Cookie c2 = (Cookie)o2;
    if ((c1.getPath() == null) && (c2.getPath() == null)) {
      return 0;
    }
    if (c1.getPath() == null)
    {
      if (c2.getPath().equals("/")) {
        return 0;
      }
      return -1;
    }
    if (c2.getPath() == null)
    {
      if (c1.getPath().equals("/")) {
        return 0;
      }
      return 1;
    }
    return c1.getPath().compareTo(c2.getPath());
  }
  
  public String toString()
  {
    return toExternalForm();
  }
  
  private boolean hasPathAttribute = false;
  private boolean hasDomainAttribute = false;
  private int cookieVersion = 0;
  private static final Log LOG = LogFactory.getLog(Cookie.class);
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.Cookie
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

public abstract interface Credentials {}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.Credentials
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.NoRouteToHostException;
import java.net.UnknownHostException;

public class DefaultHttpMethodRetryHandler
  implements HttpMethodRetryHandler
{
  private static Class SSL_HANDSHAKE_EXCEPTION = null;
  private int retryCount;
  private boolean requestSentRetryEnabled;
  
  static
  {
    try
    {
      SSL_HANDSHAKE_EXCEPTION = Class.forName("javax.net.ssl.SSLHandshakeException");
    }
    catch (ClassNotFoundException ignore) {}
  }
  
  public DefaultHttpMethodRetryHandler(int retryCount, boolean requestSentRetryEnabled)
  {
    this.retryCount = retryCount;
    this.requestSentRetryEnabled = requestSentRetryEnabled;
  }
  
  public DefaultHttpMethodRetryHandler()
  {
    this(3, false);
  }
  
  public boolean retryMethod(HttpMethod method, IOException exception, int executionCount)
  {
    if (method == null) {
      throw new IllegalArgumentException("HTTP method may not be null");
    }
    if (exception == null) {
      throw new IllegalArgumentException("Exception parameter may not be null");
    }
    if (((method instanceof HttpMethodBase)) && 
      (((HttpMethodBase)method).isAborted())) {
      return false;
    }
    if (executionCount > retryCount) {
      return false;
    }
    if ((exception instanceof NoHttpResponseException)) {
      return true;
    }
    if ((exception instanceof InterruptedIOException)) {
      return false;
    }
    if ((exception instanceof UnknownHostException)) {
      return false;
    }
    if ((exception instanceof NoRouteToHostException)) {
      return false;
    }
    if ((SSL_HANDSHAKE_EXCEPTION != null) && (SSL_HANDSHAKE_EXCEPTION.isInstance(exception))) {
      return false;
    }
    if ((!method.isRequestSent()) || (requestSentRetryEnabled)) {
      return true;
    }
    return false;
  }
  
  public boolean isRequestSentRetryEnabled()
  {
    return requestSentRetryEnabled;
  }
  
  public int getRetryCount()
  {
    return retryCount;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.DefaultHttpMethodRetryHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

/**
 * @deprecated
 */
public class DefaultMethodRetryHandler
  implements MethodRetryHandler
{
  private int retryCount;
  private boolean requestSentRetryEnabled;
  
  public DefaultMethodRetryHandler()
  {
    retryCount = 3;
    requestSentRetryEnabled = false;
  }
  
  public boolean retryMethod(HttpMethod method, HttpConnection connection, HttpRecoverableException recoverableException, int executionCount, boolean requestSent)
  {
    return ((!requestSent) || (requestSentRetryEnabled)) && (executionCount <= retryCount);
  }
  
  public boolean isRequestSentRetryEnabled()
  {
    return requestSentRetryEnabled;
  }
  
  public int getRetryCount()
  {
    return retryCount;
  }
  
  public void setRequestSentRetryEnabled(boolean requestSentRetryEnabled)
  {
    this.requestSentRetryEnabled = requestSentRetryEnabled;
  }
  
  public void setRetryCount(int retryCount)
  {
    this.retryCount = retryCount;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.DefaultMethodRetryHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

public class Header
  extends NameValuePair
{
  private boolean isAutogenerated = false;
  
  public Header()
  {
    this(null, null);
  }
  
  public Header(String name, String value)
  {
    super(name, value);
  }
  
  public Header(String name, String value, boolean isAutogenerated)
  {
    super(name, value);
    this.isAutogenerated = isAutogenerated;
  }
  
  public String toExternalForm()
  {
    return (null == getName() ? "" : getName()) + ": " + (null == getValue() ? "" : getValue()) + "\r\n";
  }
  
  public String toString()
  {
    return toExternalForm();
  }
  
  /**
   * @deprecated
   */
  public HeaderElement[] getValues()
    throws HttpException
  {
    return HeaderElement.parse(getValue());
  }
  
  public HeaderElement[] getElements()
  {
    return HeaderElement.parseElements(getValue());
  }
  
  public boolean isAutogenerated()
  {
    return isAutogenerated;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.Header
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.util.ParameterParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HeaderElement
  extends NameValuePair
{
  public HeaderElement()
  {
    this(null, null, null);
  }
  
  public HeaderElement(String name, String value)
  {
    this(name, value, null);
  }
  
  public HeaderElement(String name, String value, NameValuePair[] parameters)
  {
    super(name, value);
    this.parameters = parameters;
  }
  
  public HeaderElement(char[] chars, int offset, int length)
  {
    this();
    if (chars == null) {
      return;
    }
    ParameterParser parser = new ParameterParser();
    List params = parser.parse(chars, offset, length, ';');
    if (params.size() > 0)
    {
      NameValuePair element = (NameValuePair)params.remove(0);
      setName(element.getName());
      setValue(element.getValue());
      if (params.size() > 0) {
        parameters = ((NameValuePair[])params.toArray(new NameValuePair[params.size()]));
      }
    }
  }
  
  public HeaderElement(char[] chars)
  {
    this(chars, 0, chars.length);
  }
  
  private static final Log LOG = LogFactory.getLog(HeaderElement.class);
  private NameValuePair[] parameters = null;
  
  public NameValuePair[] getParameters()
  {
    return parameters;
  }
  
  public static final HeaderElement[] parseElements(char[] headerValue)
  {
    LOG.trace("enter HeaderElement.parseElements(char[])");
    if (headerValue == null) {
      return new HeaderElement[0];
    }
    List elements = new ArrayList();
    
    int i = 0;
    int from = 0;
    int len = headerValue.length;
    boolean qouted = false;
    while (i < len)
    {
      char ch = headerValue[i];
      if (ch == '"') {
        qouted = !qouted;
      }
      HeaderElement element = null;
      if ((!qouted) && (ch == ','))
      {
        element = new HeaderElement(headerValue, from, i);
        from = i + 1;
      }
      else if (i == len - 1)
      {
        element = new HeaderElement(headerValue, from, len);
      }
      if ((element != null) && (element.getName() != null)) {
        elements.add(element);
      }
      i++;
    }
    return (HeaderElement[])elements.toArray(new HeaderElement[elements.size()]);
  }
  
  public static final HeaderElement[] parseElements(String headerValue)
  {
    LOG.trace("enter HeaderElement.parseElements(String)");
    if (headerValue == null) {
      return new HeaderElement[0];
    }
    return parseElements(headerValue.toCharArray());
  }
  
  /**
   * @deprecated
   */
  public static final HeaderElement[] parse(String headerValue)
    throws HttpException
  {
    LOG.trace("enter HeaderElement.parse(String)");
    if (headerValue == null) {
      return new HeaderElement[0];
    }
    return parseElements(headerValue.toCharArray());
  }
  
  public NameValuePair getParameterByName(String name)
  {
    LOG.trace("enter HeaderElement.getParameterByName(String)");
    if (name == null) {
      throw new IllegalArgumentException("Name may not be null");
    }
    NameValuePair found = null;
    NameValuePair[] parameters = getParameters();
    if (parameters != null) {
      for (int i = 0; i < parameters.length; i++)
      {
        NameValuePair current = parameters[i];
        if (current.getName().equalsIgnoreCase(name))
        {
          found = current;
          break;
        }
      }
    }
    return found;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.HeaderElement
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class HeaderGroup
{
  private List headers;
  
  public HeaderGroup()
  {
    headers = new ArrayList();
  }
  
  public void clear()
  {
    headers.clear();
  }
  
  public void addHeader(Header header)
  {
    headers.add(header);
  }
  
  public void removeHeader(Header header)
  {
    headers.remove(header);
  }
  
  public void setHeaders(Header[] headers)
  {
    clear();
    for (int i = 0; i < headers.length; i++) {
      addHeader(headers[i]);
    }
  }
  
  public Header getCondensedHeader(String name)
  {
    Header[] headers = getHeaders(name);
    if (headers.length == 0) {
      return null;
    }
    if (headers.length == 1) {
      return new Header(headers[0].getName(), headers[0].getValue());
    }
    StringBuffer valueBuffer = new StringBuffer(headers[0].getValue());
    for (int i = 1; i < headers.length; i++)
    {
      valueBuffer.append(", ");
      valueBuffer.append(headers[i].getValue());
    }
    return new Header(name.toLowerCase(), valueBuffer.toString());
  }
  
  public Header[] getHeaders(String name)
  {
    ArrayList headersFound = new ArrayList();
    for (Iterator headerIter = headers.iterator(); headerIter.hasNext();)
    {
      Header header = (Header)headerIter.next();
      if (header.getName().equalsIgnoreCase(name)) {
        headersFound.add(header);
      }
    }
    return (Header[])headersFound.toArray(new Header[headersFound.size()]);
  }
  
  public Header getFirstHeader(String name)
  {
    for (Iterator headerIter = headers.iterator(); headerIter.hasNext();)
    {
      Header header = (Header)headerIter.next();
      if (header.getName().equalsIgnoreCase(name)) {
        return header;
      }
    }
    return null;
  }
  
  public Header getLastHeader(String name)
  {
    for (int i = headers.size() - 1; i >= 0; i--)
    {
      Header header = (Header)headers.get(i);
      if (header.getName().equalsIgnoreCase(name)) {
        return header;
      }
    }
    return null;
  }
  
  public Header[] getAllHeaders()
  {
    return (Header[])headers.toArray(new Header[headers.size()]);
  }
  
  public boolean containsHeader(String name)
  {
    for (Iterator headerIter = headers.iterator(); headerIter.hasNext();)
    {
      Header header = (Header)headerIter.next();
      if (header.getName().equalsIgnoreCase(name)) {
        return true;
      }
    }
    return false;
  }
  
  public Iterator getIterator()
  {
    return headers.iterator();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.httpclient.HeaderGroup
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.httpclient;

import java.net.InetAddress;
import org.apache.commons.httpclient.params.HostParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.util.LangUtils;

public class HostConfiguration
  implements Cloneable
{
  public static final HostConfiguration ANY_HOST_CONFIGURATION = new HostConfiguration();
  private HttpHost host = null;
  private ProxyHost proxyHost = null;
  private InetAddress localAddress = null;
  private HostParams params = new HostParams();
  
  public HostConfiguration() {}
  
  public HostConfiguration(HostConfiguration hostConfiguration)
  {
    init(hostConfiguration);
  }
  
  private void init(HostConfiguration hostConfiguration)
  {
    synchronized (hostConfiguration)
    {
      try
      {
        if (host != null) {
          host = ((HttpHost)host.clone());
        } else {
          host = null;
        }
        if (proxyHost != null) {
          proxyHost = ((ProxyHost)proxyHost.clone());
        } else {
          proxyHost = null;
        }
        localAddress = hostConfiguration.getLocalAddress();
        params = ((HostParams)hostConfiguration.getParams().clone());
      }
      catch (CloneNotSupportedException e)
      {
        throw new IllegalArgumentException("Host configuration could not be cloned");
      }
    }
  }
  
  public Object clone()
  {
    HostConfiguration copy;
    try
    {
      copy = (HostConfiguration)super.clone();
    }
    catch (CloneNotSupportedException e)
    {
      throw new IllegalArgumentException("Host configuration could not be cloned");
    }
    copy.init(this);
    return copy;
  }
  
  public synchronized String toString()
  {
    boolean appendComma = false;
    StringBuffer b = new StringBuffer(50);
    b.append("HostConfiguration[");
    if (host != null)
    {
      appendComma = true;
      b.append("host=").append(host);
    }
    if (proxyHost != null)
    {
      if (appendComma) {
        b.append(", ");
      } else {
        appendComma = true;
      }
      b.append("proxyHost=").append(proxyHost);
    }
    if (localAddress != null)
    {
      if (appendComma) {
        b.append(", ");
      } else {
        appendComma = true;
      }
      b.append("localAddress=").append(localAddress);
      if (appendComma) {
        b.append(", ");
      } else {
        appendComma = true;
      }
      b.append("params=").append(params);
    }
    b.append("]");
    return b.toString();
  }
  
  public synchronized boolean hostEquals(HttpConnection connection)
  {
    if (connection == null) {
      throw new IllegalArgumentException("Connection may not be null");
    }
    if (host != null)
    {
      if (!host.getHostName().equalsIgnoreCase(connection.getHost())) {
        return false;
      }
      if (host.getPort() != connection.getPort()) {
        return false;
      }
      if (!host.getProtocol().equals(connection.getProtocol())) {
        return false;
      }
      if (localAddress != null)
      {
        if (!localAddress.equals(connection.getLocalAddress())) {
          return false;
        }
      }
      else if (connection.getLocalAddress() != null) {
        return false;
      }
      return true;
    }
    return false;
  }
  
  public synchronized boolean proxyEquals(HttpConnection connection)
  {
    if (connection == null) {
      throw new IllegalArgumentException("Connection may not be null");
    }
    if (proxyHost != null) {
      return (proxyHost.getHostName().equalsIgnoreCase(connection.getProxyHost())) && (proxyHost.getPort() == connection.getProxyPort());
    }
    return connection.getProxyHost() == null;
  }
  
  /**
   * @deprecated
   */
  public synchronized boolean isHostSet()
  {
    return host != null;
  }
  
  public synchronized void setHost(HttpHost host)
  {
    this.host = host;
  }
  
  public synchronized void setHost(String host, int port, String protocol)
  {
    this.host = new HttpHost(host, port, Protocol.getProtocol(protocol));
  }
  
  /**
   * @deprecated
   */
  public synchronized void setHost(String host, String virtualHost, int port, Protocol protocol)
  {
    setHost(host, port, protocol);
    params.setVirtualHost(virtualHost);
  }
  
  public synchronized void setHost(String host, int port, Protocol protocol)
  {
    if (host == null) {
      throw new IllegalArgumentException("host must not be null");
    }
    if (protocol == null) {
      throw new IllegalArgumentException("protocol must not be null");
    }
    this.host = new HttpHost(host, port, protocol);
  }
  
  public synchronized void setHost(String host, int port)
  {
    setHost(host, port, Protocol.getProtocol("http"));
  }
  
  public synchronized void setHost(String host)
  {
    Protocol defaultProtocol = Protocol.getProtocol("http");
    setHost(host, defaultProtocol.getDefaultPort(), defaultProtocol);
  }
  
  public synchronized void setHost(URI uri)
  {
    try
    {
      setHost(uri.getHost(), uri.getPort(), uri.getScheme());
    }
    catch (URIException e)
    {
      throw new IllegalArgumentException(e.toString());
    }
  }
  
  public synchronized String getHostURL()
  {
    if (host == null) {
      throw new IllegalStateException("Host must be set to create a host URL");
    }
    return host.toURI();
  }
  
  public synchronized String getHost()
  {
    if (host != null) {
      return host.getHostName();
    }
    return null;
  }
  
  /**
   * @deprecated
   */
  public synchronized String getVirtualHost()
  {
    return params.getVirtualHost();
  }
  
  public synchronized int getPort(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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-2017. Infinite Loop Ltd