FileDocCategorySizeDatePackage
DefaultHttpClient.javaAPI DocAndroid 1.5 API12018Wed May 06 22:41:10 BST 2009org.apache.http.impl.client

DefaultHttpClient

public class DefaultHttpClient extends AbstractHttpClient
Default implementation of an HTTP client.
This class replaces HttpClient in HttpClient 3.
author
Roland Weber
author
Oleg Kalnichevski
version
$Revision: 677250 $
since
4.0

Fields Summary
Constructors Summary
public DefaultHttpClient(ClientConnectionManager conman, HttpParams params)
Creates a new HTTP client from parameters and a connection manager.

param
params the parameters
param
conman the connection manager

        super(conman, params);
    
public DefaultHttpClient(HttpParams params)

        super(null, params);
    
public DefaultHttpClient()

        super(null, null);
    
Methods Summary
protected org.apache.http.auth.AuthSchemeRegistrycreateAuthSchemeRegistry()

        AuthSchemeRegistry registry = new AuthSchemeRegistry(); 
        registry.register(
                AuthPolicy.BASIC, 
                new BasicSchemeFactory());
        registry.register(
                AuthPolicy.DIGEST, 
                new DigestSchemeFactory());
        return registry;
    
protected org.apache.http.conn.ClientConnectionManagercreateClientConnectionManager()

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(
                new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(
                new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

        ClientConnectionManager connManager = null;     
        HttpParams params = getParams();
        
        ClientConnectionManagerFactory factory = null;

        // Try first getting the factory directly as an object.
        factory = (ClientConnectionManagerFactory) params
                .getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
        if (factory == null) { // then try getting its class name.
            String className = (String) params.getParameter(
                    ClientPNames.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 SingleClientConnManager(getParams(), registry); 
        }
        
        return connManager;
    
protected org.apache.http.conn.ConnectionKeepAliveStrategycreateConnectionKeepAliveStrategy()

        return new DefaultConnectionKeepAliveStrategy();
    
protected org.apache.http.ConnectionReuseStrategycreateConnectionReuseStrategy()

        return new DefaultConnectionReuseStrategy();
    
protected org.apache.http.cookie.CookieSpecRegistrycreateCookieSpecRegistry()

        CookieSpecRegistry registry = new CookieSpecRegistry();
        registry.register(
                CookiePolicy.BEST_MATCH, 
                new BestMatchSpecFactory());
        registry.register(
                CookiePolicy.BROWSER_COMPATIBILITY, 
                new BrowserCompatSpecFactory());
        registry.register(
                CookiePolicy.NETSCAPE, 
                new NetscapeDraftSpecFactory());
        registry.register(
                CookiePolicy.RFC_2109, 
                new RFC2109SpecFactory());
        registry.register(
                CookiePolicy.RFC_2965, 
                new RFC2965SpecFactory());
        return registry;
    
protected org.apache.http.client.CookieStorecreateCookieStore()

        return new BasicCookieStore();
    
protected org.apache.http.client.CredentialsProvidercreateCredentialsProvider()

        return new BasicCredentialsProvider();
    
protected org.apache.http.protocol.HttpContextcreateHttpContext()

        HttpContext context = new BasicHttpContext();
        context.setAttribute(
                ClientContext.AUTHSCHEME_REGISTRY, 
                getAuthSchemes());
        context.setAttribute(
                ClientContext.COOKIESPEC_REGISTRY, 
                getCookieSpecs());
        context.setAttribute(
                ClientContext.COOKIE_STORE, 
                getCookieStore());
        context.setAttribute(
                ClientContext.CREDS_PROVIDER, 
                getCredentialsProvider());
        return context;
    
protected org.apache.http.params.HttpParamscreateHttpParams()

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, 
                HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, 
                HTTP.DEFAULT_CONTENT_CHARSET);
        HttpProtocolParams.setUseExpectContinue(params, 
                true);

        // determine the release version from packaged version info
        final VersionInfo vi = VersionInfo.loadVersionInfo
            ("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ?
            vi.getRelease() : VersionInfo.UNAVAILABLE;
        HttpProtocolParams.setUserAgent(params, 
                "Apache-HttpClient/" + release + " (java 1.4)");

        return params;
    
protected org.apache.http.protocol.BasicHttpProcessorcreateHttpProcessor()

        BasicHttpProcessor httpproc = new BasicHttpProcessor();
        httpproc.addInterceptor(new RequestDefaultHeaders());
        // Required protocol interceptors
        httpproc.addInterceptor(new RequestContent());
        httpproc.addInterceptor(new RequestTargetHost());
        // Recommended protocol interceptors
        httpproc.addInterceptor(new RequestConnControl());
        httpproc.addInterceptor(new RequestUserAgent());
        httpproc.addInterceptor(new RequestExpectContinue());
        // HTTP state management interceptors
        httpproc.addInterceptor(new RequestAddCookies());
        httpproc.addInterceptor(new ResponseProcessCookies());
        // HTTP authentication interceptors
        httpproc.addInterceptor(new RequestTargetAuthentication());
        httpproc.addInterceptor(new RequestProxyAuthentication());
        return httpproc;
    
protected org.apache.http.client.HttpRequestRetryHandlercreateHttpRequestRetryHandler()

        return new DefaultHttpRequestRetryHandler();
    
protected org.apache.http.conn.routing.HttpRoutePlannercreateHttpRoutePlanner()

        return new DefaultHttpRoutePlanner
            (getConnectionManager().getSchemeRegistry());
    
protected org.apache.http.client.AuthenticationHandlercreateProxyAuthenticationHandler()

        return new DefaultProxyAuthenticationHandler();
    
protected org.apache.http.client.RedirectHandlercreateRedirectHandler()

        return new DefaultRedirectHandler();
    
protected org.apache.http.protocol.HttpRequestExecutorcreateRequestExecutor()

        return new HttpRequestExecutor();
    
protected org.apache.http.client.AuthenticationHandlercreateTargetAuthenticationHandler()

        return new DefaultTargetAuthenticationHandler();
    
protected org.apache.http.client.UserTokenHandlercreateUserTokenHandler()

        return new DefaultUserTokenHandler();