|
16 | 16 | (:import [java.io BufferedReader ByteArrayInputStream ByteArrayOutputStream EOFException File InputStream]
|
17 | 17 | [java.net UnknownHostException URL]
|
18 | 18 | [org.apache.http.entity BufferedHttpEntity ByteArrayEntity FileEntity InputStreamEntity StringEntity]
|
19 |
| - [javax.xml.parsers SAXParserFactory] |
| 19 | + [javax.xml.parsers SAXParser SAXParserFactory] |
| 20 | + org.xml.sax.helpers.DefaultHandler |
20 | 21 | org.apache.http.impl.conn.PoolingHttpClientConnectionManager
|
21 | 22 | org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager))
|
22 | 23 |
|
|
474 | 475 | (util/force-string body charset))]
|
475 | 476 | (assoc resp :body body)))
|
476 | 477 |
|
| 478 | +(defn- sax-parser ^SAXParser [] |
| 479 | + (.. |
| 480 | + (doto |
| 481 | + (SAXParserFactory/newInstance) |
| 482 | + (.setFeature |
| 483 | + "http://apache.org/xml/features/nonvalidating/load-external-dtd" false)) |
| 484 | + (newSAXParser))) |
| 485 | + |
| 486 | +(defn- non-validating [s ^DefaultHandler ch] |
| 487 | + (let [parser (sax-parser)] |
| 488 | + (cond |
| 489 | + (instance? String s) (.parse parser ^String s ch) |
| 490 | + (instance? InputStream s) (.parse parser ^InputStream s ch) |
| 491 | + :else (throw (ex-info "Unsupported input" {:s s}))))) |
| 492 | + |
477 | 493 | (defn- decode-xml-body [body]
|
478 |
| - (let [non-validating (fn [s ch] |
479 |
| - (.. |
480 |
| - (doto |
481 |
| - (SAXParserFactory/newInstance) |
482 |
| - (.setFeature |
483 |
| - "http://apache.org/xml/features/nonvalidating/load-external-dtd" false)) |
484 |
| - (newSAXParser) |
485 |
| - (parse s ch)))] |
486 |
| - (-> body |
487 |
| - (util/force-stream) |
488 |
| - (xml/parse non-validating)))) |
| 494 | + (-> body |
| 495 | + (util/force-stream) |
| 496 | + (xml/parse non-validating))) |
489 | 497 |
|
490 | 498 | (defn coerce-xml-body
|
491 | 499 | [request {:keys [body] :as resp} & [charset]]
|
|
892 | 900 | ([req respond raise]
|
893 | 901 | (client (oauth-request req) respond raise))))
|
894 | 902 |
|
895 |
| - |
896 | 903 | (defn parse-user-info [user-info]
|
897 | 904 | (when user-info
|
898 | 905 | (str/split user-info #":")))
|
|
0 commit comments