Package org.apache.http.impl.client

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


     */
    public XCapHttpResponse delete(XCapResourceId resourceId)
            throws XCapException
    {
        assertConnected();
        DefaultHttpClient httpClient = createHttpClient();
        try
        {
            URI resourceUri = getResourceURI(resourceId);
            HttpDelete deleteMethod = new HttpDelete(resourceUri);
            deleteMethod.setHeader("Connection", "close");
            Credentials credentials =
                    new UsernamePasswordCredentials(getUserName(), password);
            httpClient.getCredentialsProvider().
                    setCredentials(AuthScope.ANY, credentials);
            if (logger.isDebugEnabled())
            {
                String logMessage = String.format(
                        "Deleting resource %1s from the server",
                        resourceId.toString()
                );
                logger.debug(logMessage);
            }
            HttpResponse response = httpClient.execute(deleteMethod);
            return createResponse(response);
        }
        catch (IOException e)
        {
            String errorMessage = String.format(
                    "%1s resource cannot be deleted",
                    resourceId.toString());
            throw new XCapException(errorMessage, e);
        }
        finally
        {
            httpClient.getConnectionManager().shutdown();
        }
    }
View Full Code Here


     *
     * @return the HTTP client.
     */
    private DefaultHttpClient createHttpClient()
    {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        try
        {
            // make sure we use Certificate Verification Service if
            // for some reason the certificate needs to be shown to user
            // for approval
            ClientConnectionManager ccm = httpClient.getConnectionManager();
            SchemeRegistry sr = ccm.getSchemeRegistry();
            SSLContext ctx = certificateVerification.getSSLContext(
                uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort());
            org.apache.http.conn.ssl.SSLSocketFactory ssf
                = new org.apache.http.conn.ssl.SSLSocketFactory(
                        ctx, new HostNameResolverImpl());
            ssf.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory
                .ALLOW_ALL_HOSTNAME_VERIFIER);
            sr.register(new Scheme("https", ssf, 443));
        }
        catch(Throwable e)
        {
            logger.error("Cannot add our trust manager to httpClient", e);
        }
        HttpParams httpParams = httpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
        HttpConnectionParams.setSoTimeout(httpParams, timeout);
        return httpClient;
    }
View Full Code Here

    this.tileWidth = tileWidth;
    this.tileHeight = tileHeight;
    this.style = style;
    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
    manager.setDefaultMaxPerRoute(10);
    httpClient = new DefaultHttpClient(manager);
  }
View Full Code Here

      server.deploy(archive);

      try
      {
         // Get an HTTP Client
         final HttpClient client = new DefaultHttpClient();

         // Make an HTTP Request
         final String echoValue = "EmbeddedBiatch";
         final List<NameValuePair> params = new ArrayList<NameValuePair>();
         params.add(new BasicNameValuePair("jsp", PATH_JSP));
         params.add(new BasicNameValuePair("echo", echoValue));
         final URI uri = URIUtils.createURI("http", "localhost", 8080,
               appName + SEPARATOR + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null);
         final HttpGet request = new HttpGet(uri);

         // Execute the request
         log.info("Executing request to: " + request.getURI());
         final HttpResponse response = client.execute(request);
         final HttpEntity entity = response.getEntity();
         if (entity == null)
         {
            TestCase.fail("Request returned no entity");
         }
View Full Code Here

      server.deploy(archive);

      try
      {
         // Get an HTTP Client
         final HttpClient client = new DefaultHttpClient();

         // Make an HTTP Request
         final URI uri = URIUtils.createURI("http", "localhost", 8080,
               appName + SEPARATOR + servletClass.getSimpleName(), null, null);
         final HttpGet request = new HttpGet(uri);

         // Execute the request
         log.info("Executing request to: " + request.getURI());
         final HttpResponse response = client.execute(request);
         final HttpEntity entity = response.getEntity();
         if (entity == null)
         {
            TestCase.fail("Request returned no entity");
         }
View Full Code Here

{
   protected HttpClient httpClient;

   public ApacheHttpClient4Executor()
   {
      this.httpClient = new DefaultHttpClient();
   }
View Full Code Here

    updateProperties("Last action: added accessToken");
  }

  public class SingleClient implements HttpClientPool {
    SingleClient() {
      org.apache.http.client.HttpClient client = new DefaultHttpClient();
      ClientConnectionManager mgr = client.getConnectionManager();
      if (!(mgr instanceof ThreadSafeClientConnManager)) {
        HttpParams params = client.getParams();
        client = new DefaultHttpClient(new ThreadSafeClientConnManager(
            params, mgr.getSchemeRegistry()), params);
      }

      // Use Proxy to access if you are in one of the countries that cannot connects to twitter directly.  
      // HttpHost proxy = new HttpHost("your_proxy_url", your_proxy_port);
View Full Code Here

    for (Status status : statuses.status)
      System.out.println(status);
  }

  private static HttpClient createClient() {
    HttpClient httpClient = new DefaultHttpClient();
       
    // Use Proxy to access if you are in one of the countries that cannot connects to twitter directly.  
//    HttpHost proxy = new HttpHost("your_proxy_url", your_proxy_port);
//    httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
//        proxy);
View Full Code Here

      // Create an HttpClient with the ThreadSafeClientConnManager.
      // This connection manager must be used if more than one thread will
      // be using the HttpClient.
      ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
      HttpClient httpClient = new DefaultHttpClient(cm, params);

      final ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(httpClient);
      return executor;
   }
View Full Code Here

    // conserve bandwidth by minimizing the number of segments that are sent
    HttpConnectionParams.setTcpNoDelay(httpParams, false);
    // Defines whether the socket can be bound even though a previous connection is still in a timeout state.
    HttpConnectionParams.setSoReuseaddr(httpParams, true);

    httpClient = new DefaultHttpClient(clientConnectionManager, httpParams);
    // ask for gzip
    ((AbstractHttpClient) httpClient).addRequestInterceptor(new GzipRequestInterceptor());
    // uncompress gzip
    ((AbstractHttpClient) httpClient).addResponseInterceptor(new GzipResponseInterceptor());
View Full Code Here

TOP

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

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.