This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add -main function into paos.core for cli using
- Loading branch information
1 parent
044ecc4
commit 9b01af6
Showing
5 changed files
with
63 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,59 @@ | ||
(ns paos.core | ||
(:require [paos.wsdl :as wsdl] | ||
[clojure.pprint :refer [pprint]] | ||
[clojure.java.io :as io] | ||
[clojure.xml :as xml] | ||
[clojure.zip :as zip] | ||
[cheshire.core :as cheshire] | ||
[clojure.data.zip.xml :as zip-xml])) | ||
[paos.service :as service] | ||
[clojure.tools.cli :refer [parse-opts]] | ||
[clojure.pprint :as pprint])) | ||
|
||
(defn decompose-wsdl [wsdl-path] | ||
(wsdl/parse wsdl-path)) | ||
(def cli-options | ||
[["-w" "--wsdl WSDL" "Url or filesystem path or a content of wsdl. (Required)" | ||
:parse-fn str | ||
:validate [#(string? (not-empty %)) "Must be a non-empty string."]] | ||
["-b" "--binding BINDING" "One of SOAP binding defined in WSDL." | ||
:parse-fn str] | ||
["-o" "--operation OPERATION" "One of SOAP operation defined for given WSDL binding. Can not be used without binding." | ||
:parse-fn str] | ||
["-h" "--help" "Display this help message"]]) | ||
|
||
(defn -main [& args] | ||
(println (cheshire/generate-string (wsdl/parse (first args)) {:pretty true}))) | ||
|
||
(comment | ||
(defn- help | ||
[args] | ||
(println "\nUSAGE:\n") | ||
(println "clj -m" (namespace `help) "<options>\n") | ||
(println (:summary args))) | ||
|
||
(def x | ||
(wsdl/parse "resources/airlinesService.xml")) | ||
(defn- print-table [bindings] | ||
(pprint/print-table | ||
(mapcat (fn [[binding {:keys [operations]}]] | ||
(map (fn [[operation _]] | ||
{:binding binding | ||
:operation operation}) | ||
operations)) | ||
bindings))) | ||
|
||
x) | ||
(defn -main [& args] | ||
(let [args (parse-opts args cli-options)] | ||
(if (:errors args) | ||
(do (doseq [e (:errors args)] | ||
(println e)) | ||
(help args)) | ||
(if (-> args :options :help) | ||
(help args) | ||
(try | ||
(let [wsdl (wsdl/parse (-> args :options :wsdl))] | ||
(if-let [binding (-> args :options :binding)] | ||
(if-let [operation (-> args :options :operation)] | ||
(let [srv (get-in wsdl [binding :operations operation])] | ||
(do | ||
(println "\nService url:\n") | ||
(println (get-in wsdl [binding :url])) | ||
(println "\nSOAP action:\n") | ||
(println (service/soap-action srv)) | ||
(println "\nRequest message:\n") | ||
(println (service/request-xml srv)) | ||
(println "\nResponse message:\n") | ||
(println (service/response-xml srv)))) | ||
(print-table (select-keys wsdl [binding]))) | ||
(print-table wsdl)) | ||
(System/exit 0)) | ||
(finally | ||
;; Only called if `parse` raises an exception | ||
(shutdown-agents))))))) |
File renamed without changes.
File renamed without changes.