Mercurial > gemma
annotate pkg/soap/soap.go @ 674:120a82bd9953 octree
octree: Added loading frame for contour generation.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 19 Sep 2018 13:26:30 +0200 |
parents | 5e45f441aed6 |
children | a244b18cb916 |
rev | line source |
---|---|
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package soap |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 "bytes" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 "crypto/tls" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 "encoding/xml" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 "io/ioutil" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 "log" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 "math/rand" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 "net" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 "net/http" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 "time" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 const timeout = time.Duration(30 * time.Second) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 func dialTimeout(network, addr string) (net.Conn, error) { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 return net.DialTimeout(network, addr, timeout) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 type SOAPEnvelope struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 Header *SOAPHeader |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 Body SOAPBody |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 type SOAPHeader struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 Items []interface{} `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 type SOAPBody struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 Fault *SOAPFault `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 Content interface{} `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 type SOAPFault struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 Code string `xml:"faultcode,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 String string `xml:"faultstring,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 Actor string `xml:"faultactor,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 Detail string `xml:"detail,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 const ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 // Predefined WSS namespaces to be used in |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 WssNsWSSE string = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 WssNsWSU string = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 WssNsType string = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 type WSSSecurityHeader struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ wsse:Security"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 XmlNSWsse string `xml:"xmlns:wsse,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 MustUnderstand string `xml:"mustUnderstand,attr,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 Token *WSSUsernameToken `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 type WSSUsernameToken struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 XMLName xml.Name `xml:"wsse:UsernameToken"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 XmlNSWsu string `xml:"xmlns:wsu,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 XmlNSWsse string `xml:"xmlns:wsse,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 Id string `xml:"wsu:Id,attr,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 Username *WSSUsername `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 Password *WSSPassword `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 type WSSUsername struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 XMLName xml.Name `xml:"wsse:Username"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 XmlNSWsse string `xml:"xmlns:wsse,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 Data string `xml:",chardata"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 type WSSPassword struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 XMLName xml.Name `xml:"wsse:Password"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 XmlNSWsse string `xml:"xmlns:wsse,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 XmlNSType string `xml:"Type,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 Data string `xml:",chardata"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 type BasicAuth struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 Login string |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 Password string |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 type SOAPClient struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 url string |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 tlsCfg *tls.Config |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 auth *BasicAuth |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 headers []interface{} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 // ********** |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 // Accepted solution from http://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 // Author: Icza - http://stackoverflow.com/users/1705598/icza |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 const ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 letterIdxBits = 6 // 6 bits to represent a letter index |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 func randStringBytesMaskImprSrc(n int) string { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 src := rand.NewSource(time.Now().UnixNano()) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 b := make([]byte, n) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 // A src.Int63() generates 63 random bits, enough for letterIdxMax characters! |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 if remain == 0 { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 cache, remain = src.Int63(), letterIdxMax |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 if idx := int(cache & letterIdxMask); idx < len(letterBytes) { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 b[i] = letterBytes[idx] |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 i-- |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 cache >>= letterIdxBits |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 remain-- |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 return string(b) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 // ********** |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 func NewWSSSecurityHeader(user, pass, mustUnderstand string) *WSSSecurityHeader { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 hdr := &WSSSecurityHeader{XmlNSWsse: WssNsWSSE, MustUnderstand: mustUnderstand} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 hdr.Token = &WSSUsernameToken{XmlNSWsu: WssNsWSU, XmlNSWsse: WssNsWSSE, Id: "UsernameToken-" + randStringBytesMaskImprSrc(9)} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 hdr.Token.Username = &WSSUsername{XmlNSWsse: WssNsWSSE, Data: user} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 hdr.Token.Password = &WSSPassword{XmlNSWsse: WssNsWSSE, XmlNSType: WssNsType, Data: pass} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 return hdr |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 func (b *SOAPBody) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 if b.Content == nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 return xml.UnmarshalError("Content must be a pointer to a struct") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 var ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 token xml.Token |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 err error |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 consumed bool |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 Loop: |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 for { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 if token, err = d.Token(); err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 if token == nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 break |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 switch se := token.(type) { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 case xml.StartElement: |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 if consumed { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 return xml.UnmarshalError("Found multiple elements inside SOAP body; not wrapped-document/literal WS-I compliant") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 } else if se.Name.Space == "http://schemas.xmlsoap.org/soap/envelope/" && se.Name.Local == "Fault" { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 b.Fault = &SOAPFault{} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 b.Content = nil |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 err = d.DecodeElement(b.Fault, &se) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 consumed = true |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 } else { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 if err = d.DecodeElement(b.Content, &se); err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 consumed = true |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 case xml.EndElement: |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 break Loop |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 return nil |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 func (f *SOAPFault) Error() string { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 return f.String |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 func NewSOAPClient(url string, insecureSkipVerify bool, auth *BasicAuth) *SOAPClient { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 tlsCfg := &tls.Config{ |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 InsecureSkipVerify: insecureSkipVerify, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 return NewSOAPClientWithTLSConfig(url, tlsCfg, auth) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 func NewSOAPClientWithTLSConfig(url string, tlsCfg *tls.Config, auth *BasicAuth) *SOAPClient { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 return &SOAPClient{ |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 url: url, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 tlsCfg: tlsCfg, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 auth: auth, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 func (s *SOAPClient) AddHeader(header interface{}) { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 s.headers = append(s.headers, header) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 func (s *SOAPClient) Call(soapAction string, request, response interface{}) error { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 envelope := SOAPEnvelope{} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 if s.headers != nil && len(s.headers) > 0 { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 soapHeader := &SOAPHeader{Items: make([]interface{}, len(s.headers))} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 copy(soapHeader.Items, s.headers) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 envelope.Header = soapHeader |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 envelope.Body.Content = request |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 buffer := new(bytes.Buffer) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 encoder := xml.NewEncoder(buffer) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 //encoder.Indent("", " ") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 if err := encoder.Encode(envelope); err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 if err := encoder.Flush(); err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 //log.Println(buffer.String()) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 req, err := http.NewRequest("POST", s.url, buffer) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 if s.auth != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 req.SetBasicAuth(s.auth.Login, s.auth.Password) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 req.Header.Add("SOAPAction", soapAction) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 req.Header.Set("User-Agent", "gowsdl/0.1") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 req.Close = true |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 tr := &http.Transport{ |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 TLSClientConfig: s.tlsCfg, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 Dial: dialTimeout, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 client := &http.Client{Transport: tr} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 res, err := client.Do(req) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 defer res.Body.Close() |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 rawbody, err := ioutil.ReadAll(res.Body) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 if len(rawbody) == 0 { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 log.Println("empty response") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 return nil |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 //log.Println(string(rawbody)) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 respEnvelope := new(SOAPEnvelope) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 respEnvelope.Body = SOAPBody{Content: response} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 err = xml.Unmarshal(rawbody, respEnvelope) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 fault := respEnvelope.Body.Fault |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 if fault != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 return fault |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 return nil |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 } |