Mercurial > gemma
annotate pkg/soap/soap.go @ 3678:8f58851927c0
client: make layer factory only return new layer config for individual maps
instead of each time it is invoked. The purpose of the factory was to support multiple maps with individual layers.
But returning a new config each time it is invoked leads to bugs that rely on the layer's state. Now this factory
reuses the same objects it created before, per map.
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Mon, 17 Jun 2019 17:31:35 +0200 |
parents | f8e684108425 |
children | 5f47eeea988d |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
566
diff
changeset
|
13 |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package soap |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bytes" |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
18 "context" |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "crypto/tls" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "encoding/xml" |
1810
7ee9bdaac336
Waterway gauge import: Added support for username/password.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
21 "fmt" |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "io/ioutil" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "log" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "math/rand" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "net" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 "net/http" |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
27 "sync" |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 "time" |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
29 |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/config" |
566
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 SOAPEnvelope 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/ Envelope"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 Header *SOAPHeader |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 Body SOAPBody |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
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 type SOAPHeader struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 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
|
41 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 Items []interface{} `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 type SOAPBody struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 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
|
47 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 Fault *SOAPFault `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 Content interface{} `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 type SOAPFault struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 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
|
54 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 Code string `xml:"faultcode,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 String string `xml:"faultstring,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 Actor string `xml:"faultactor,omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 Detail string `xml:"detail,omitempty"` |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 const ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 // 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
|
63 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
|
64 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
|
65 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
|
66 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 type WSSSecurityHeader struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 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
|
70 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
|
71 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 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
|
73 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 Token *WSSUsernameToken `xml:",omitempty"` |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 type WSSUsernameToken struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 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
|
83 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 Username *WSSUsername `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 Password *WSSPassword `xml:",omitempty"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
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 type WSSUsername struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 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
|
90 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
|
91 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 Data string `xml:",chardata"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
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 type WSSPassword struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 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
|
97 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
|
98 XmlNSType string `xml:"Type,attr"` |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 Data string `xml:",chardata"` |
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 type BasicAuth struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 Login string |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 Password string |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 type SOAPClient struct { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 url string |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 tlsCfg *tls.Config |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 auth *BasicAuth |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 headers []interface{} |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 // ********** |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 // 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
|
117 // 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
|
118 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 const ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 ) |
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 func randStringBytesMaskImprSrc(n int) string { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 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
|
128 b := make([]byte, n) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 // 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
|
130 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
|
131 if remain == 0 { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 cache, remain = src.Int63(), letterIdxMax |
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 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
|
135 b[i] = letterBytes[idx] |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 i-- |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 cache >>= letterIdxBits |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 remain-- |
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 return string(b) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 // ********** |
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 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 return hdr |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 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
|
155 if b.Content == nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 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
|
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 var ( |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 token xml.Token |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 err error |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 consumed bool |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 ) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 Loop: |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 for { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 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
|
168 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
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 if token == nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 break |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
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 switch se := token.(type) { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 case xml.StartElement: |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 if consumed { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 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
|
179 } 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
|
180 b.Fault = &SOAPFault{} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 b.Content = nil |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 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
|
184 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 return err |
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 consumed = true |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 } else { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 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
|
191 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 consumed = true |
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 case xml.EndElement: |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 break Loop |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 } |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 return nil |
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 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 func (f *SOAPFault) Error() string { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 return f.String |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 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
|
209 tlsCfg := &tls.Config{ |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 InsecureSkipVerify: insecureSkipVerify, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 return NewSOAPClientWithTLSConfig(url, tlsCfg, auth) |
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 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
|
216 return &SOAPClient{ |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 url: url, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 tlsCfg: tlsCfg, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 auth: auth, |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 } |
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 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
|
224 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
|
225 } |
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 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
|
228 envelope := SOAPEnvelope{} |
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 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
|
231 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
|
232 copy(soapHeader.Items, s.headers) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 envelope.Header = soapHeader |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 envelope.Body.Content = request |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 buffer := new(bytes.Buffer) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 encoder := xml.NewEncoder(buffer) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 //encoder.Indent("", " ") |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 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
|
243 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 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
|
247 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 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
|
251 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 return err |
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 if s.auth != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 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
|
256 } |
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 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
|
259 req.Header.Add("SOAPAction", soapAction) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 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
|
262 req.Close = true |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 |
3580
d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
264 timeout := config.SOAPTimeout() |
d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
265 |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 tr := &http.Transport{ |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 TLSClientConfig: s.tlsCfg, |
3580
d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
268 Dial: func(network, addr string) (net.Conn, error) { |
d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
269 return net.DialTimeout(network, addr, timeout) |
d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
270 }, |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 client := &http.Client{Transport: tr} |
1810
7ee9bdaac336
Waterway gauge import: Added support for username/password.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
274 |
3161
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
275 ctx, cancel := context.WithTimeout(context.Background(), timeout) |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
276 |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
277 var once sync.Once |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
278 |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
279 defer once.Do(cancel) |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
280 |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
281 req = req.WithContext(ctx) |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
282 |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
283 go func() { |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
284 defer once.Do(cancel) |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
285 <-ctx.Done() |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
286 }() |
6a44a89ffb51
SOAP: Added a globally configurable timeout (default 1min) till a SOAP request is canceled.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1810
diff
changeset
|
287 |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 res, err := client.Do(req) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
291 } |
3663
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
292 |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
293 defer res.Body.Close() |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
294 |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
295 if res.StatusCode < http.StatusOK || res.StatusCode > 299 { |
3663
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
296 rawbody, err := ioutil.ReadAll(res.Body) |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
297 var body string |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
298 if err == nil { |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
299 if len(rawbody) > 1024 { |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
300 body = fmt.Sprintf("\nbody: %.1024q...", rawbody) |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
301 } else { |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
302 body = fmt.Sprintf("\nbody: %q", rawbody) |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
303 } |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
304 } |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
305 return fmt.Errorf( |
3663
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
306 "HTTP error: %d (%s)%s", |
f8e684108425
Be more verbose if a SOAP call fails.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3580
diff
changeset
|
307 res.StatusCode, http.StatusText(res.StatusCode), body) |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
308 } |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
309 |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
310 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
|
311 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
312 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
313 } |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
314 if len(rawbody) == 0 { |
3580
d38b20ccb6f9
GM import: Be more graceful when accepting measure/issue dates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3324
diff
changeset
|
315 log.Println("warn: empty response") |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
316 return nil |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
317 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
318 |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
319 //log.Println(string(rawbody)) |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
320 respEnvelope := new(SOAPEnvelope) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
321 respEnvelope.Body = SOAPBody{Content: response} |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
322 err = xml.Unmarshal(rawbody, respEnvelope) |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 if err != nil { |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
324 return err |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
325 } |
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
326 |
3324
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
327 fault := respEnvelope.Body.Fault |
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
328 if fault != nil { |
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
329 return fault |
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
330 } |
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
331 |
96dbfcc614be
Backed out changeset bd1385c00b59
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3321
diff
changeset
|
332 return nil |
566
5e45f441aed6
Added SOAP client for the IFBN bottleneck service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
333 } |