7

我需要使用 WSDL Web 服务,而到目前为止我看到的 Java 客户端代码看起来臃肿而复杂。我想知道 Clojure 中是否存在更简洁的解决方案,以便我可以在 Clojure 中实现该部分并向 Java 代码公开一个更简单的 API。

4

2 回答 2

10
cd your_project_dir/src
wsimport -p some.import.ns http://.../service?wsdl

它会创建./some.import.ns/*.class. 所以你可以use在你的clojure项目中只使用它们

(ns your.ns ...
  (:import [some.import.ns some_WS_Service ...]))

(let [port (-> (some_WS_Service.) 
               .getSome_WS_ServicePort]
  (... (.someMethod port) ...))
于 2013-01-19T01:23:27.680 回答
1

查看 paos:https ://github.com/xapix-io/paos

轻量级且易于使用的库,用于从 WSDL 文件构建 SOAP 客户端。

(require '[clj-http.client :as client])
(require '[paos.service :as service])
(require '[paos.wsdl :as wsdl])

(defn parse-response [{:keys [status body] :as response} body-parser fail-parser]
  (assoc response
         :body
         (case status
           200 (body-parser body)
           500 (fail-parser body))))

(let [soap-service   (wsdl/parse "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl")
      srv            (get-in soap-service ["BLZServiceSOAP11Binding" :operations "getBank"])
      soap-url       (get-in soap-service ["BLZServiceSOAP11Binding" :url])
      soap-headers   (service/soap-headers srv)
      content-type   (service/content-type srv)
      mapping        (service/request-mapping srv)
      context        (assoc-in mapping ["Envelope" "Body" "getBank" "blz" :__value] "28350000")
      body           (service/wrap-body srv context)
      resp-parser    (partial service/parse-response srv)
      fault-parser   (partial service/parse-fault srv)]
  (-> soap-url
      (client/post {:content-type content-type
                    :body         body
                    :headers      (merge {} soap-headers)
                    :do-not-throw true})
      (parse-response resp-parser fault-parser)))
于 2018-11-07T10:29:34.947 回答