-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsoap.txt
86 lines (71 loc) · 2.58 KB
/
soap.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import (
"./esb" // the full ESBCredentials type is defined elsewhere
...
)
// Sample data
var ESBUsername = "user@esb"
var ESBPassword = "changeme"
var ClientGUID = "CA55E77E-1962-0000-2014-DEC1A551F1ED"
type Envelope struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
EncodingStyle string `xml:"http://schemas.xmlsoap.org/soap/envelope/ encodingStyle,attr"`
Header EnvelopeHeader `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
Body EnvelopeBody `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
}
// This is fixed independently of whatever port we call
type EnvelopeHeader struct {
Credentials *esb.ESBCredentials `xml:"http://esb/definitions ESBCredentials"`
}
// This has to change depending on which service we invoke
type EnvelopeBody struct {
Payload interface{} // the empty interface lets us assign any other type
}
type QueryEntity struct {
// having an XMLName field lets you re-tag (and rename) the Payload
XMLName xml.Name `xml:"http://esb/queryservice QueryEntity"`
ClientGUID *string
QueryString *string
}
func CreateQuery(query string) *Envelope {
// Build the envelope (this could be farmed out to another func)
retval := &Envelope{}
retval.EncodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
retval.Header = EnvelopeHeader{}
retval.Header.Credentials = &esb.ESBCredentials{}
retval.Header.Credentials.ESBUsername = &ESBUsername
retval.Header.Credentials.ESBPassword = &ESBPassword
// Build the payload that matches our desired SOAP port
payload := QueryEntity{}
payload.ClientGUID = &HouseholdId
payload.QueryString = query
// ...and in the darkness bind it
retval.Body.Payload = payload
return retval
}
func InvokePitsOfDarkness() {
...
buffer := &bytes.Buffer{}
encoder := xml.NewEncoder(buffer)
envelope := CreateQuery("wally")
err := encoder.Encode(envelope)
// this is just a test, so let's panic freely
if err != nil {
log.Panic("Could not encode request")
}
client := http.Client{}
req, err := http.NewRequest("POST", "https://esb/service", buffer)
if err != nil {
log.Panic(err.Error())
}
req.Header.Add("SOAPAction", "\"http://esb/service/QueryEntity\"")
req.Header.Add("Content-Type", "text/xml")
resp, err := client.Do(req)
if err != nil {
log.Panic(err.Error())
}
if resp.StatusCode != 200 {
log.Panic(resp.Status)
}
result, err := GoElsewhereToDecode(resp.Body)
...
}