Giter Club home page Giter Club logo

paos's Introduction

PAOS

Lightweight and easy-to-use library to build SOAP clients from WSDL files.

Intro

Welcome to PAOS! This is a lightweight clojure library that enables developers to build rich SOAP interfaces from WSDL files without bringing in extra complexity with Java interop and autogenerated Java classes. PAOS is a wrapper for the awesome soap-ws.

Rationale

The main goal for PAOS is to provide developers with a flexible and easy-to-use means of communicating with web services accessible via SOAP protocol. Typically, these services provide a WSDL document that describes all available sub-services with a list of possible answers in the form of a structured description of data types. If you have ever worked with such documents, you most likely know how complex and convoluted they can get. For Clojure, almost all currently available approaches are dependent on the generation of Java classes with the help of tools such as wsdl2java or axis2. With PAOS, you no longer have to bother with fine-tuning super flexible professional tools every time a random letter has changed in your WSDL.

When should you use PAOS?

  • Your project works with dynamically changing services
  • Your project needs to be able to establish communication with new services on the fly
  • You do not want to dive into the abyss of Java interop with often suboptimally generated classes
  • You need to somehow customize the messages sent to the service

What does PAOS support?

All that soap-ws supports. If not โ€“ please let me know.

Installation

Because soap-ws depends on a list of external dependencies that are not published in clojars or maven, you need to add them to the project's repository list yourself.

leiningen

{...
 :repositories [["enonic" "https://repo.enonic.com/public/"]
                ...]
 :dependencies [[io.xapix/paos "0.2.5"]
                ...]
}

boot

(set-env! :repositories #(conj % ["enonic" {:url "https://repo.enonic.com/public/"}])
          :dependencies #(conj % [io.xapix/paos "0.2.5"])

deps.edn

{...
 :mvn/repos {"enonic" {:url "https://repo.enonic.com/public/"}}}}
 :deps {io.xapix/paos {:mvn/version "0.2.5"}
        ...}
...
}

Command line interface

You can examine any WSDL with simple command line interface. If you already have all required repos in your deps.edn just execute clj -Sdeps '{:deps {io.xapix/paos {:mvn/version "0.2.5"}}}' -m paos.core -h and check available options.

Or you can use standalone script with everything inplace:

#!/usr/bin/env bash
set -e

MVN_REPOS='{"enonic" {:url "https://repo.enonic.com/public/"}}'
DEPS='{io.xapix/paos {:mvn/version "0.2.5"}}'

clojure -Srepro -Sdeps "{:deps $DEPS :mvn/repos $MVN_REPOS}" -m paos.core $@

TL;DR

;; clj-http not included, add it yourself
(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)))

Quick start guide

Require the paos.wsdl namespace:

(require '[paos.wsdl :as wsdl])

And process your WSDL using the function wsdl/parse

;; You can use external urls
(def soap-service (wsdl/parse "http://example.com/some/wsdl/file?wsdl"))

;; Or absolute file path
(def soap-service (wsdl/parse "/some/place/service.wsdl"))

;; Or just pass the content of WSDL file as a string
(def soap-service (wsdl/parse "<SomeServise>"))

All service bindings should be visible as top-level keywords with all operations inside.

soap-service
;; => {"SomeServiceBinding" {:operations {"operation1" ...
;;                                        "operation2" ...}
;;                           :url "service url"}
;;     "AnotherServiceBinding" {:operations {"operation3" ...
;;                                           "operation4" ...}
;;                              :url "another service url"}}

Each operation is an object implemented with paos.service/Service methods which you can use to get the data necessary for that service:

(require '[paos.service :as service])

(let [srv (get-in soap-service ["SomeServiceBinding" :operations "operation1"]]
      (service/request-mapping srv))
  ;; => {"Envelope" {"Headers" []
  ;;                 "Body" {"SomeWrapper" {"Value" {:__value {:__type "string"}}}}}}

service/request-mapping should give you an example how a request should look like to be converted into payload xml. Places where you have to add some real values are marked as {:__value {:__type "string"}} with the data type expected by the service in {:__type "string"}

Some data types can have arrays of complex objects:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="msgBody">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" ref="Contato"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="Contato">
        <xs:complexType>
          <xs:sequence>
            <xs:element ref="cdEndereco"/>
            <xs:element ref="cdBairro"/>
            <xs:element ref="email"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="cdEndereco" type="xs:integer"/>
      <xs:element name="cdBairro" type="xs:integer"/>
      <xs:element name="email" type="xs:string"/>
    </xs:schema>

This type definition should be converted into a Clojure data structure like the following:

{"msgBody"
 {"Contatos"
  [{"Contato"
    {"cdEndereco"
     {:__value {:__type "string"}}
     "cdBairro"
     {:__value {:__type "string"}}
     "email"
     {:__value {:__type "integer"}}}}]}}

Here in "msgBody" you can find the "Contatos" keyword with an array of one element. That means that the payload's "msgBody" might contain zero or more occurrences of "Contato" object. Just attach as many as you want into it and all of them will be injected correctly into the request payload.

To build the actual XML payload you have to use wrap-body function from the service namespace:

(require '[paos.service :as service])

(let [srv (get-in soap-service ["SomeServiceBinding" :operations "operation1"])
      mapping (service/request-mapping srv)
      context (do-something-with-mapping mapping)]
  (service/wrap-body srv context))
  ;; => "<xml>...</xml>"

The result is just a string with all your data inside.

Now you can use your favorite http library to make the request to the service:

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

(let [soap-url (:url soap-service)
      srv (get-in soap-service ["SomeServiceBinding" :operations "operation1"])
      soap-headers (service/soap-headers srv)
      content-type (service/content-type srv)
      mapping (service/request-mapping srv)
      context (do-something-with-mapping mapping)
      body (service/wrap-body srv context)]
  (client/post soap-url
     {:content-type content-type
      :headers soap-headers
      :body body}))
  ;; => {:status 200
  ;;     :body "<xml>...</xml>"
  ;;     ...}

To convert the XML from the response you can use parse function from your service:

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

(let [soap-service (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])
      content-type (service/content-type srv)
      headers      (service/soap-headers srv)
      mapping      (service/request-mapping srv)
      context      (assoc-in mapping ["Envelope" "Body" "getBank" "blz" :__value] "28350000")
      body         (service/wrap-body srv context)
      parse-fn     (partial service/parse-response srv)]
  (-> soap-url
      (client/post {:content-type content-type
                    :body         body
                    :headers      headers})
      :body
      parse-fn))

Copyright and License

Copyright ยฉ 2018 Xapix GmbH, and contributors

Distributed under the Eclipse Public License, the same as Clojure.

paos's People

Contributors

daemianmack avatar delaguardo avatar dg4227 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paos's Issues

Error to download (java 11.0.7)

I'm having trouble when I try to install the library, below my deps and the problem I've been having.

deps:

{:aliases {:deps {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.8.599"}}}
           :depstar {:extra-deps {seancorfield/depstar {:mvn/version "0.3.4"}}}
           :test {:extra-paths ["test"]}}
 :deps {com.novemberain/langohr {:mvn/version "5.1.0"}
        commons-codec/commons-codec {:mvn/version "1.13"}
        commons-validator/commons-validator {:mvn/version "1.6"}
        cheshire/cheshire {:mvn/version "5.9.0"}
        clj-http/clj-http {:mvn/version "3.10.0"}
        clj-time/clj-time {:mvn/version "0.15.2"}
        io.xapix/paos {:mvn/version "0.2.4"}
        org.clojure/clojure {:mvn/version "1.10.1"}
        org.clojure/data.generators {:mvn/version "0.1.2"}
        org.clojure/tools.logging {:mvn/version "0.5.0"}}
 :mvn/repos {"enonic" {:url "https://repo.enonic.com/public/"}
             "central" {:url "https://repo1.maven.org/maven2/"}
             "clojars" {:url "https://clojars.org/repo"}}
 :paths ["resources" "src/main/clojure"]}

error:

clj -A:depstar -m hf.depstar.uberjar target/"clj-zzk"-"0.0.1".jar
Downloading: net/sf/saxon/saxon/9.1.0.8/saxon-9.1.0.8.jar from enonic
Downloading: org/apache/xmlbeans/xmlbeans/2.6.0/xmlbeans-2.6.0.jar from central
Downloading: inflections/inflections/0.13.0/inflections-0.13.0.jar from clojars
Error building classpath. Could not transfer artifact org.clojure:google-closure-library:jar:0.0-20130212-95c19e7f0f5f from/to central (https://repo1.maven.org/maven2/): Range Not Satisfiable (416)
Makefile:17: recipe for target 'uberjar' failed
make[1]: *** [uberjar] Error 1
make[1]: Leaving directory '/home/rafael/Projects/zzk/clj-zzk'
Makefile:10: recipe for target 'install' failed
make: *** [install] Error 2

service/wrap-body ignores array of scalar types

I have a complex type like:

<s:complexType name="ArrayOfString">
        <s:sequence>
          <s:element maxOccurs="unbounded" minOccurs="0" name="string" nillable="true" type="s:string"/>
        </s:sequence>
      </s:complexType>

Another complex type refers to it like so:

...
<s:element maxOccurs="1" minOccurs="0" name="ValidationGroupList" type="tns:ArrayOfString"/>
...

I have tried multiple options to set this attribute in the 'context' object

"ValidationGroupList" ({"string" {:__value "BO_GeneralInfoModule"}})

or

"ValidationGroupList" ({:__value "BO_GeneralInfoModule"}),

(service/wrap-body srv context) converts the deeply nested object into proper namespaced xml, but ValidationGroupList is empty, given either of the above context objects.

Here, 'context' is the merged mapping and data (similar to your example in README). Note that every other attribute in the nested complex object is converted fine, except for the "array of strings" complex type.

There is no error and I can't debug this since it's using selma's template internally.

Suggestion?

Could not resolve dependencies

I having this error when trying to launch my REPL or deploying to Heroku. 3 days ago I had no problems using paos.

Could not transfer artifact net.sf.saxon:saxon:pom:9 from/to jboss (https://repository.jboss.org/nexus/content/repositories/deprecated/): Connection reset
This could be due to a typo in :dependencies, file system permissions, or network issues.
If you are behind a proxy, try setting the 'http_proxy' environment variable.

This is part of my project.clj

  :repositories [["enonic" "https://repo.enonic.com/public/"]]
  :dependencies 
               [[camel-snake-kebab "0.4.2"]
                 [clj-http "3.10.1"]
                 [environ "1.2.0"]
                 [integrant "0.8.0"]
                 [integrant/repl "0.3.1"]
                 [io.xapix/paos "0.2.4"]
                 [metosin/reitit "0.5.10"]
                 [org.clojure/clojure "1.10.1"]
                 [org.postgresql/postgresql "42.2.14"]
                 [ovotech/ring-jwt "1.3.0"]
                 [ring "1.8.2"]
                 [seancorfield/next.jdbc "1.1.613"]
                 [buddy "2.0.0"]
                 [clojure.java-time "0.3.2"]
                 [ring/ring-mock "0.4.0"]
                 [ring-cors "0.1.13"]]

No success searching for a solution and now I'm stuck. Will appreciate your help.

WS-Security headers

Hi!

I'm trying to build a request for a SOAP service that requires WS-Security headers. It expects a call like this:

Screen Shot 2019-04-05 at 06 14 50

I tried associating a map with the expected headers into the mapping like so:

(assoc-in mapping ["Envelope" "Header"] {"wsse:Security" {"wsse:UsernameToken" {"wsse:Username" "a" "wsse:Password" "c"}}})

The problem is that the wrap-body fn seems to ignore this. Can you shed a light on how to add this type of headers into the SOAP envelope? Thanks!

soap-ws parts are served from insecure repo

Leiningen and boot complains about dependencies coming from non-https repositories.

  • Discuss with soap-ws author about possibilities to move dependencies to secure storage.
  • Reimplement features from soap-ws with the only clojure
    • Collect all the schema files from given WSDL
    • Parse data type definitions from schema files
    • Build empty messages same way as soap-ws

add protocol or interface for SOAPClient

Something like that

(defprotocol PSOAPClient
    (soap-action [this])
    (send [this context])
    (parse [this])
    (-request-body [this context])
    (-response-body [this context]))

Object initializer how will implement that protocol should get as an arguments result of WSDL parsing for specific soap-action.

Tried to use insecure HTTP repository without TLS.

i'm getting this when using lein deps on a new project with the only deps being clojure and paos.

this is from lein help faq

**Q:** I got `Tried to use insecure HTTP repository without TLS`, what is that about?  
**A:** This means your project was configured to download dependencies
from a repository that does not use TLS encryption. This is very
insecure and exposes you to trivially-executed man-in-the-middle attacks.

add function builder for making response parsers based on output-mapping from parsed wsdl

Incomming data:

{:soapenv:Envelope ;; Top level xml tag
   {:soapenv:Header nil,
    :soapenv:Body
    {:v1:airlineByIcaoResponse
     {:return|attrs ;; set of attributes for :return tag
      {:offset nil}
      :return ;; this xml tag can be found multiple times in parent tag (:v1:airlineByIcaoResponse)
      [{:category nil,
        :iata nil,
        :name nil,
        :icao nil,
        :dateFrom nil,
        :dateTo nil,
        :active nil,
        :phoneNumber nil,
        :fs nil}]}}}}

Output:

fn xml_string => map

This function should use clojure.zip for lazy xml parsing without growing heap.

Add Testing documentation to readme

i tried lein test which gave me a response telling me that i don't have a project.clj
i'm not sure how to run the tests outside of a repl or using clj/clojure commands

Error with <![CDATA[]]> present in output template

Hello,

I've been happily running version 0.2.4 of this library for awhile now. Recently, things stopped working altogether in the production Docker container. I'm seeing some strange behavior and I'm not sure how to track down the root cause.

I load a WSDL file as a classpath resource and pass it to paos.wsdl/parse. This passes.
I grab my reified service instance from the wsdl service object without issue.
I call (paos.service/request-template service). Locally, the template looks normal and has blocks like this:
{% with ctx=Envelope %}{% with ctx=ctx.Header %}. But in the Docker container, it looks something like this: <![CDATA[{% with ctx=Envelope %}]><![CDATA[{% with ctx=ctx.Header %}]>.

Locally, when I try to substitute my parameters into the template using (service/wrap-body service body), the substitution happens properly. But when this call is performed inside of the Docker container, the parameter values are not substituted, and the <![CDATA[]]> blocks remain, so it looks something like this: <![CDATA[]]><![CDATA[]]>

As best as I can tell, both environments are using JDK17, the same JARs (lein is being used to pull the JARs for both environments), and Clojure 1.11.1.

Any ideas on what's going on here or what I can do to troubleshoot this?

EDIT: I've narrowed this down a bit. Something is happening with the artifact produced by the lein uberjar task that causes it to produce different output for the aforementioned task than what happens via thelein repl. Neither Docker nor the JDK appear to be at fault here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.