          use-ssl?             (true? (:use-ssl options))
          http-client-settings (get-http-client-settings
                                (select-keys options [:ssl-protocols :cipher-suites]))
-         scripting-container (-> (ScriptingContainer. LocalContextScope/SINGLETHREAD
-                                                      LocalVariableBehavior/PERSISTENT)
-                                 (jruby-internal/init-jruby jruby-config))]
-     (doto scripting-container
-       (.setEnvironment (jruby-core/managed-environment (jruby-core/get-system-env) jruby-config))
-       (.setLoadPaths (jruby-puppet-core/managed-load-path jruby-puppet-testutils/ruby-load-path))
-       (.runScriptlet "require 'jar-dependencies'")
-       (.runScriptlet "require 'puppet/server/http_client'"))
-
+         scripting-container (-> (jruby-impl-core/create-pool jruby-config)
+                                 (jruby-core/borrow-from-pool :http-client-test [])
+                                 :scripting-container)]
+     (.runScriptlet scripting-container "require 'puppet/server/http_client'")
      (let [http-client-class (.runScriptlet scripting-container "Puppet::Server::HttpClient")]
        (.callMethod scripting-container http-client-class "initialize_settings" http-client-settings Object))
      (.runScriptlet scripting-container (str "require 'puppet/server/http_client';"
-                                             (format "c = Puppet::Server::HttpClient.new('localhost', %d, {:use_ssl => %s});"
+                                             (format "$c = Puppet::Server::HttpClient.new('localhost', %d, {:use_ssl => %s});"
                                                      port use-ssl?)))
      (doto scripting-container
        (.runScriptlet (format "Puppet[:hostcert] = '%s'" cert-pem))

                   :cipher-suites ["SSL_RSA_WITH_RC4_128_MD5"]
                   :use-ssl true})]
          (try
            (.runScriptlet sc (raise-caught-http-error "c.get('/', {})"))
            (is false "Expected HTTP connection to HTTPS port to fail")
            (catch EvalFailedException e
              (is (ssl-connection-exception? (.. e getCause)))))

  (jetty9/with-test-webserver ring-app-with-auth port
    (let [scripting-container (create-scripting-container port)]
      (testing "no credentials"
        (.runScriptlet scripting-container "$response = $c.post('/', 'foo', {})")
        (is (= "401" (.runScriptlet scripting-container "$response.code")))
        (is (= "access denied" (.runScriptlet scripting-container "$response.body"))))

      (testing "valid credentials"
        (let [auth "{ :basic_auth => { :user => 'foo', :password => 'bar' }}"]
          (.runScriptlet scripting-container (format "$response = $c.post('/', 'foo', {}, %s)" auth)))
        (is (= "200" (.runScriptlet scripting-container "$response.code")))
        (is (= "hi" (.runScriptlet scripting-container "$response.body"))))

      (testing "invalid credentials"
        (let [auth "{ :basic_auth => { :user => 'foo', :password => 'baz' }}"]
          (.runScriptlet scripting-container (format "$response = $c.post('/', 'foo', {}, %s)" auth)))
        (is (= "401" (.runScriptlet scripting-container "$response.code")))
        (is (= "access denied" (.runScriptlet scripting-container "$response.body"))))

      (terminate-scripting-container scripting-container))))

