Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix reflection warning on javax.xml.parsers.SAXParser #650

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/clj_http/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
(:import [java.io BufferedReader ByteArrayInputStream ByteArrayOutputStream EOFException File InputStream]
[java.net UnknownHostException URL]
[org.apache.http.entity BufferedHttpEntity ByteArrayEntity FileEntity InputStreamEntity StringEntity]
[javax.xml.parsers SAXParserFactory]
[javax.xml.parsers SAXParser SAXParserFactory]
org.xml.sax.helpers.DefaultHandler
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager))

Expand Down Expand Up @@ -474,18 +475,25 @@
(util/force-string body charset))]
(assoc resp :body body)))

(defn- sax-parser ^SAXParser []
(..
(doto
(SAXParserFactory/newInstance)
(.setFeature
"http://apache.org/xml/features/nonvalidating/load-external-dtd" false))
(newSAXParser)))

(defn- non-validating [s ^DefaultHandler ch]
(let [parser (sax-parser)]
(cond
(instance? String s) (.parse parser ^String s ch)
(instance? InputStream s) (.parse parser ^InputStream s ch)
:else (throw (ex-info "Unsupported input" {:s s})))))

(defn- decode-xml-body [body]
(let [non-validating (fn [s ch]
(..
(doto
(SAXParserFactory/newInstance)
(.setFeature
"http://apache.org/xml/features/nonvalidating/load-external-dtd" false))
(newSAXParser)
(parse s ch)))]
(-> body
(util/force-stream)
(xml/parse non-validating))))
(-> body
(util/force-stream)
(xml/parse non-validating)))

(defn coerce-xml-body
[request {:keys [body] :as resp} & [charset]]
Expand Down Expand Up @@ -892,7 +900,6 @@
([req respond raise]
(client (oauth-request req) respond raise))))


(defn parse-user-info [user-info]
(when user-info
(str/split user-info #":")))
Expand Down
Loading