Skip to content

Commit

Permalink
Merge pull request hooklift#59 from ronoaldo/include-header-in-message
Browse files Browse the repository at this point in the history
Allow clients to add SOAPHeader in SOAPClient.
  • Loading branch information
c4milo authored Jul 22, 2016
2 parents a65655b + 0ad0dae commit e894ebf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
16 changes: 16 additions & 0 deletions gowsdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,19 @@ func TestVboxGeneratesWithoutSyntaxErrors(t *testing.T) {
}
}
}

func TestSOAPHeaderGeneratesWithoutErrors(t *testing.T) {
g := GoWSDL{
file: "fixtures/ferry.wsdl",
pkg: "myservice",
makePublicFn: makePublic,
}

resp, err := g.Start()
if err != nil {
t.Error(err)
}
if !strings.Contains(string(resp["operations"]), "SetHeader") {
t.Error("SetHeader method should be generated in the service operation")
}
}
4 changes: 4 additions & 0 deletions operations_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var opsTmpl = `
}
}
func (service *{{$portType}}) SetHeader(header interface{}) {
service.client.SetHeader(header)
}
{{range .Operations}}
{{$faults := len .Faults}}
{{$requestType := findType .Input.Message | replaceReservedWords | makePublic}}
Expand Down
13 changes: 10 additions & 3 deletions soap_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func dialTimeout(network, addr string) (net.Conn, error) {
type SOAPEnvelope struct {
XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` + "`" + `
Header *SOAPHeader
Body SOAPBody
}
Expand Down Expand Up @@ -48,6 +48,7 @@ type SOAPClient struct {
url string
tls bool
auth *BasicAuth
header interface{}
}
func (b *SOAPBody) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
Expand Down Expand Up @@ -112,9 +113,15 @@ func NewSOAPClient(url string, tls bool, auth *BasicAuth) *SOAPClient {
}
}
func (s *SOAPClient) SetHeader(header interface{}) {
s.header = header
}
func (s *SOAPClient) Call(soapAction string, request, response interface{}) error {
envelope := SOAPEnvelope{
//Header: SoapHeader{},
envelope := SOAPEnvelope{}
if s.header != nil {
envelope.Header = &SOAPHeader{Header: s.header}
}
envelope.Body.Content = request
Expand Down

0 comments on commit e894ebf

Please sign in to comment.