xapix-io / paos

Clojure SOAP client
Eclipse Public License 1.0
93 stars 12 forks source link

WS-Security headers #19

Open eraad opened 5 years ago

eraad commented 5 years ago

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!

DeLaGuardo commented 5 years ago

@eraad All tags that can occurs multiple times within another must be wrapped into an object with a key in plural. E.g.

{"Headers" [{"Header" {"Security" {"UsernameToken" {"Username" {:__value "a"}
                                                    "Password" {:__value "c"}}}}}]} 

Please check your request mapping structure. If my assumption is correct this code should work:

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

It also would be helpful if you will post your mapping here.

eraad commented 5 years ago

Hi @DeLaGuardo

I tried it but did not work. Please, find my mapping below:

=> (def m (service/request-mapping srv))
=> {Envelope {Header {}, Body {sendBill {fileName {:__value {:__type string, :__optional? true}}, contentFile {:__value {:__type nil, :__optional? true}}, partyType {:__value {:__type string, :__optional? 
true}}}}}}
=> (assoc-in m ["Envelope" "Headers"] [{"Header" {"Security" {"UsernameToken" {"Username" {:__value "a"} "Password" {:__value "c"}}}}}])
=> {Envelope {Header {}, Body {sendBill {fileName {:__value 1234-01-123F-1.XML}, contentFile {:__value #object[[B 0x5279f71 [B@5279f71]}}}, Headers [{Header {Security {UsernameToken {Username {:__value a}, Password {:__value c}}}}}]}}
=> <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:ser="http://service.sunat.gob.pe"><soapenv:Header/><soapenv:Body><ser:sendBill><fileName>1234-01-123F-1.XML</fileName><contentFile>[B@5279f71</contentFile></ser:sendBill></soapenv:Body></soapenv:Envelope>

Please note that the mapping produced by request-mapping includes a Header tag (not in plural). Thanks! I appreciate your help.

DeLaGuardo commented 5 years ago

Is it possible also to send your WSDL file as well?

eraad commented 5 years ago

For sure, please find it attached (zipped). I just added two more files that are included (ns and XSD). Archive.zip

DeLaGuardo commented 5 years ago

So, I can confirm that this is a bug caused by wsdl with no information about headers. I will try to add ability to inject custom handlers to fix that. Probably will solve it during upcoming weekend.

eraad commented 5 years ago

Thanks! I suspected that. I will keep an eye on the project! Shall I close this issue?

DeLaGuardo commented 5 years ago

Let's leave it open until resolved

lwiechec commented 2 years ago

I have a similar issue. Would there be a chance to fix it?... if not - could you point me where to look for? maybe I can help fixing it somehow