diff --git a/project.clj b/project.clj index 224abc3..a892403 100644 --- a/project.clj +++ b/project.clj @@ -1,14 +1,15 @@ (defproject diamondap/clj-apache-https "1.0.15-SNAPSHOT" :description "Clojure HTTP library using the Apache HttpClient. Based on clj-apache-http, but includes support for SSL client certificates and HttpAsyncClient." - :dependencies [[org.clojure/clojure "1.2.0"] - [org.clojure/clojure-contrib "1.2.0"] + :dependencies [[org.clojure/clojure "1.2.1"] + [org.clojure/data.json "0.1.1"] [org.apache.httpcomponents/httpcore "4.1.1"] [org.apache.httpcomponents/httpmime "4.1.1"] [commons-logging/commons-logging "1.1.1"] [org.apache.httpcomponents/httpclient "4.1.1"] - [org.apache.httpcomponents/httpasyncclient "4.0-alpha2"]] - :dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]] + [org.apache.httpcomponents/httpasyncclient "4.0-alpha2"] + [commons-codec "1.5"]] + :dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]] :repositories {"releases" ~(str "file://" user/local-maven-clone "/releases") "snapshots" ~(str "file://" diff --git a/src/com/twinql/clojure/async_client.clj b/src/com/twinql/clojure/async_client.clj index a56d030..2d4ae60 100644 --- a/src/com/twinql/clojure/async_client.clj +++ b/src/com/twinql/clojure/async_client.clj @@ -45,9 +45,9 @@ StrictHostnameVerifier)) (:import (org.apache.http.impl.nio.reactor DefaultConnectingIOReactor)) - (:require [clojure.contrib.io :as io]) - (:require [clojure.contrib.base64 :as base64]) - (:require [clojure.contrib.string :as string]) + (:import (org.apache.commons.codec.binary + Base64)) + (:require [clojure.string :as string]) (:require [com.twinql.clojure.http :as http]) (:require [com.twinql.clojure.sync-libs :as sync]) @@ -335,7 +335,7 @@ (defn response-body [response] "Returns the body of the response." - (io/slurp* (.. response getEntity getContent))) + (slurp (.. response getEntity getContent))) (defn create-request "Returns a new instance of a request of the specified method. Param method @@ -374,12 +374,16 @@ (interpose "&") (apply str)))) +(def UTF8 (java.nio.charset.Charset/forName "UTF-8")) + +(defn- encode-str [^String s] + (String. (Base64/encodeBase64 (.getBytes s "UTF-8") false) UTF8)) (defn get-basic-auth-value "Returns the value of the basic auth header." [user pwd] (str "Basic " - (string/chomp (base64/encode-str (str user ":" pwd))))) + (string/trim-newline (encode-str (str user ":" pwd))))) (defn add-basic-auth-header! diff --git a/src/com/twinql/clojure/http.clj b/src/com/twinql/clojure/http.clj index fe93845..79bbc9a 100644 --- a/src/com/twinql/clojure/http.clj +++ b/src/com/twinql/clojure/http.clj @@ -2,8 +2,8 @@ (:refer-clojure :exclude [get]) (:use clojure.set) (:require - [clojure.contrib.io :as io] - [clojure.contrib.json :as json]) + [clojure.java.io :as io] + [clojure.data.json :as json]) (:import (java.lang Exception) (java.net URI) @@ -205,17 +205,17 @@ (defmethod entity-as :string [#^HttpEntity entity as status] (with-open [#^InputStream stream (.getContent entity)] - (io/slurp* stream))) + (slurp stream))) ;;; JSON handling. ;;; We prefer keywordizing. (defmethod entity-as :json [#^HttpEntity entity as status] (with-open [#^InputStream stream (.getContent entity)] - (clojure.contrib.json/read-json (io/reader stream) true))) + (json/read-json (io/reader stream) true))) (defmethod entity-as :json-string-keys [#^HttpEntity entity as status] (with-open [#^InputStream stream (.getContent entity)] - (clojure.contrib.json/read-json (io/reader stream) false))) + (json/read-json (io/reader stream) false))) ;;; To avoid overhead in shutting down a ClientConnectionManager, diff --git a/src/com/twinql/clojure/x509_connection_manager.clj b/src/com/twinql/clojure/x509_connection_manager.clj index 2da6ba8..63cbb9e 100644 --- a/src/com/twinql/clojure/x509_connection_manager.clj +++ b/src/com/twinql/clojure/x509_connection_manager.clj @@ -1,7 +1,7 @@ (ns com.twinql.clojure.x509-connection-manager (:require [com.twinql.clojure.http :as http]) (:require [com.twinql.clojure.NaiveTrustManager :as trust-mgr]) - (:require [clojure.contrib.java-utils :as jutil]) + (:require [clojure.java.io :as io]) (:require [com.twinql.clojure.sync-libs :as sync]) (:require [com.twinql.clojure.async-libs :as async]) (:import @@ -59,7 +59,7 @@ within the jar at the specified path." [#^String path] (try - (if (. (jutil/file path) exists) + (if (. (io/file path) exists) (FileInputStream. path) (load-embedded-resource path)) (catch Exception _ (throw (new FileNotFoundException diff --git a/tests/async_client.clj b/tests/async_client.clj index 1b3965f..3a6b8ff 100644 --- a/tests/async_client.clj +++ b/tests/async_client.clj @@ -3,7 +3,6 @@ (:require [com.twinql.clojure.async-client :as async]) (:require [com.twinql.clojure.async-libs :as async-libs]) (:require [com.twinql.clojure.http :as http]) - (:require [clojure.contrib.io :as io]) (:use clojure.test) (:import (java.net URI))) @@ -113,7 +112,7 @@ ;; This post has no body, but it does have query params, ;; so query params go in the body. - (io/slurp* (.. req2 getEntity getContent)) + (slurp (.. req2 getEntity getContent)) "name=Edgar&age=89&weight=166&city=Boston" ;; When query params go in the body, Content-Type header @@ -128,7 +127,7 @@ "Spongebob" ;; Be sure body was set from :body option. - (io/slurp* (.. req3 getEntity getContent)) + (slurp (.. req3 getEntity getContent)) sample-body ))) ;; These are some default options for the HTTP connections we want to set up.