Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-619

ApacheHttpClient4Executor should be configurable with an HttpContext

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Major Major
    • 2.3-RC1
    • 2.3-beta-1
    • None
    • None

      A particular use case that arose in the course of RESTEASY-516 (upgrading to HttpClient (4.x)) is the need to configure BASIC authentication. Here is an example:

         static private ClientExecutor createAuthenticatingExecutor(DefaultHttpClient client)
         {
            // Create AuthCache instance
            AuthCache authCache = new BasicAuthCache();
            
            // Generate BASIC scheme object and add it to the local auth cache
            BasicScheme basicAuth = new BasicScheme();
            HttpHost targetHost = new HttpHost("localhost", 8081);
            authCache.put(targetHost, basicAuth);
      
            // Add AuthCache to the execution context
            BasicHttpContext localContext = new BasicHttpContext();
            localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
            
            // Create ClientExecutor.
            ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(client, localContext);
            return executor;
         }
      

      ApacheHttpClient4Executor gets a new constructor, a getter, and a setter.

              rsigal@redhat.com Ronald Sigal
              rsigal@redhat.com Ronald Sigal
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: