Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.SystemDefaultHttpClient


    /**
     * Create an HttpClient that performs connection pooling. This can be used
     * with {@link #setDefaultHttpClient} or provided in the HttpOp calls.
     */
    public static HttpClient createCachingHttpClient() {
        return new SystemDefaultHttpClient() {
            /**
             * See SystemDefaultHttpClient (4.2). This version always sets the
             * connection cache
             */
            @Override
View Full Code Here


        // configured to use it with authentication
        if (defaultHttpClient != null && (auth == null || useDefaultClientWithAuthentication))
            return defaultHttpClient;

        // Otherwise use a fresh client each time
        return new SystemDefaultHttpClient();
    }
View Full Code Here

        // May use configured default client where appropriate
        this.client = HttpOp.getDefaultHttpClient();
        if (this.client == null || (this.authenticator != null && !HttpOp.getUseDefaultClientWithAuthentication())) {
            // If no configured default or authentication is in-use and the user has not configured
            // to use authentication with the default client use a fresh SystemDefaultHttpClient instance
            this.client = new SystemDefaultHttpClient();
        } else {
            // When using the configured default client we don't want to shut it down at the end of a request
            this.requireClientShutdown = false;
        }
    }
View Full Code Here

        }
        log.trace("GET " + target.toExternalForm());

        try {
            try {
                this.client = new SystemDefaultHttpClient();
               
                // Always apply a 10 second timeout to obtaining a connection lease from HTTP Client
                // This prevents a potential lock up
                this.client.getParams().setLongParameter(ConnManagerPNames.TIMEOUT, TimeUnit.SECONDS.toMillis(10));
               
View Full Code Here

        log.trace("POST " + target.toExternalForm());

        ARQ.getHttpRequestLogger().trace(target.toExternalForm());

        try {
            this.client = new SystemDefaultHttpClient();
           
            // Always apply a 10 second timeout to obtaining a connection lease from HTTP Client
            // This prevents a potential lock up
            this.client.getParams().setLongParameter(ConnManagerPNames.TIMEOUT, TimeUnit.SECONDS.toMillis(10));
           
View Full Code Here

   
    /** Create an HttpClient that performs connection pooling.  This can be used
     * with {@link #setDefaultHttpClient} or provided in the HttpOp calls.
     */
    public static HttpClient createCachingHttpClient() {
        return new SystemDefaultHttpClient() {
          /** See SystemDefaultHttpClient (4.2).  This version always sets the connection cache */ 
          @Override
          protected ClientConnectionManager createClientConnectionManager() {
              PoolingClientConnectionManager connmgr = new PoolingClientConnectionManager(
                      SchemeRegistryFactory.createSystemDefault());
View Full Code Here

    private static HttpClient ensureClient(HttpClient client, HttpAuthenticator auth) {
        if ( client != null )
            return client ;
        if ( defaultHttpClient != null && auth == null )
            return defaultHttpClient ;
        return new SystemDefaultHttpClient() ;
    }
View Full Code Here

        return h.getValue() ;
    }

    private Graph exec(String targetStr, Graph graphToSend, HttpUriRequest httpRequest, boolean processBody)
    {
        HttpClient httpclient = new SystemDefaultHttpClient(httpParams) ;
       
        if ( graphToSend != null )
        {
            // ??? httpRequest isa Post
            // Impedence mismatch - is there a better way?
            ByteArrayOutputStream out = new ByteArrayOutputStream() ;
            Model model = ModelFactory.createModelForGraph(graphToSend) ;
            model.write(out, "RDF/XML") ;
            byte[] bytes = out.toByteArray() ;
            ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ;
            InputStreamEntity reqEntity = new InputStreamEntity(in, bytes.length) ;
            reqEntity.setContentType(WebContent.contentTypeRDFXML) ;
            reqEntity.setContentEncoding(WebContent.charsetUTF8) ;
            HttpEntity entity = reqEntity ;
            ((HttpEntityEnclosingRequestBase)httpRequest).setEntity(entity) ;
        }
        TypedInputStream ts = null ;
        // httpclient.getParams().setXXX
        try {
            HttpResponse response = httpclient.execute(httpRequest) ;

            int responseCode = response.getStatusLine().getStatusCode() ;
            String responseMessage = response.getStatusLine().getReasonPhrase() ;
           
            if ( HttpSC.isRedirection(responseCode) )
View Full Code Here

            // Accept
            if ( acceptHeader != null )
                httpget.addHeader(HttpNames.hAccept, acceptHeader) ;
           
            // Execute
            DefaultHttpClient httpclient = new SystemDefaultHttpClient();
            applyAuthentication(httpclient, url, httpContext);
            HttpResponse response = httpclient.execute(httpget) ;
            // Handle response
            httpResponse(id, response, baseIRI, handlers) ;
            httpclient.getConnectionManager().shutdown();
        } catch (IOException ex) { IO.exception(ex) ; }
    }
View Full Code Here

            // Accept
            if ( acceptHeader != null )
                httpget.addHeader(HttpNames.hAccept, acceptHeader) ;
           
            // Execute
            DefaultHttpClient httpclient = new SystemDefaultHttpClient();        // Pool?
            applyAuthentication(httpclient, url, httpContext);
            HttpResponse response = httpclient.execute(httpget) ;
           
            // Response
            StatusLine statusLine = response.getStatusLine() ;
            if ( statusLine.getStatusCode() == 404 )
            {
                log.debug(format("[%d] %s %s",id, statusLine.getStatusCode(), statusLine.getReasonPhrase())) ;
                return null ;
            }
            if ( statusLine.getStatusCode() >= 400 )
            {
                log.debug(format("[%d] %s %s",id, statusLine.getStatusCode(), statusLine.getReasonPhrase())) ;
                throw new HttpException(statusLine.getStatusCode()+" "+statusLine.getReasonPhrase()) ;
            }
   
            HttpEntity entity = response.getEntity() ;
            if ( entity == null )
            {
                // No content in the return.  Probably a mistake, but not guaranteed.
                if ( log.isDebugEnabled() )
                    log.debug(format("[%d] %d %s :: (empty)",id, statusLine.getStatusCode(), statusLine.getReasonPhrase())) ;
                return null ;
            }
               
            MediaType mt = MediaType.create(entity.getContentType().getValue()) ;
            if ( log.isDebugEnabled() )
                log.debug(format("[%d] %d %s :: %s",id, statusLine.getStatusCode(), statusLine.getReasonPhrase() , mt)) ;
               
            return new TypedInputStreamHttp(entity.getContent(), mt,
                                       httpclient.getConnectionManager()) ;
        }
        catch (IOException ex) { IO.exception(ex) ; return null ; }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.SystemDefaultHttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.