-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
498 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This is the official list of wsdl2go authors for copyright purposes. | ||
# This file is distinct from the CONTRIBUTORS file. | ||
# | ||
# Names should be added to this file as | ||
# Name or Organization <email address> | ||
# | ||
# The email address is not required for organizations. | ||
# | ||
# Please keep the list sorted. | ||
|
||
Alexandre Fiori <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright 2016 wsdl2go authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* The names of authors or contributors may NOT be used to endorse or | ||
promote products derived from this software without specific prior | ||
written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Package soap provides a SOAP HTTP client. | ||
package soap | ||
|
||
import ( | ||
"bytes" | ||
"encoding/xml" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
// A RoundTripper executes a request passing the given req as the SOAP | ||
// envelope body. The HTTP response is then de-serialized onto the resp | ||
// object. Returns error in case an error occurs serializing req, making | ||
// the HTTP request, or de-serializing the response. | ||
type RoundTripper interface { | ||
RoundTrip(req, resp Message) error | ||
} | ||
|
||
// Message is an opaque type used by the RoundTripper to carry XML | ||
// documents for SOAP. | ||
type Message interface{} | ||
|
||
// Header is an opaque type used as the SOAP Header element in requests. | ||
type Header interface{} | ||
|
||
// AuthHeader is a Header to be encoded as the SOAP Header element in | ||
// requests, to convey credentials for authentication. | ||
type AuthHeader struct { | ||
Namespace string `xml:"xmlns:ns,attr"` | ||
Username string `xml:"ns:username"` | ||
Password string `xml:"ns:password"` | ||
} | ||
|
||
// Client is a SOAP client. | ||
type Client struct { | ||
URL string // URL of the server | ||
Namespace string // SOAP Namespace | ||
Envelope string // Optional SOAP Envelope | ||
Header Header // Optional SOAP Header | ||
ContentType string // Optional Content-Type (default text/xml) | ||
Config *http.Client // Optional HTTP client | ||
} | ||
|
||
// RoundTrip implements the RoundTripper interface. | ||
func (c *Client) RoundTrip(in, out Message) error { | ||
req := &Envelope{ | ||
EnvelopeAttr: c.Envelope, | ||
NSAttr: c.Namespace, | ||
Header: c.Header, | ||
Body: Body{Message: in}, | ||
} | ||
if req.EnvelopeAttr == "" { | ||
req.EnvelopeAttr = "http://schemas.xmlsoap.org/soap/envelope/" | ||
} | ||
if req.NSAttr == "" { | ||
req.NSAttr = c.URL | ||
} | ||
var b bytes.Buffer | ||
err := xml.NewEncoder(&b).Encode(req) | ||
if err != nil { | ||
return err | ||
} | ||
ct := c.ContentType | ||
if ct == "" { | ||
ct = "text/xml" | ||
} | ||
cli := c.Config | ||
if cli == nil { | ||
cli = http.DefaultClient | ||
} | ||
resp, err := cli.Post(c.URL, ct, &b) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
if false { | ||
// to be removed | ||
z, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("%s", z) | ||
} | ||
return xml.NewDecoder(resp.Body).Decode(out) | ||
} | ||
|
||
// Envelope is a SOAP envelope. | ||
type Envelope struct { | ||
XMLName xml.Name `xml:"SOAP-ENV:Envelope"` | ||
EnvelopeAttr string `xml:"xmlns:SOAP-ENV,attr"` | ||
NSAttr string `xml:"xmlns:ns,attr"` | ||
Header Message `xml:"SOAP-ENV:Header"` | ||
Body Body | ||
} | ||
|
||
// Body is the body of a SOAP envelope. | ||
type Body struct { | ||
XMLName xml.Name `xml:"SOAP-ENV:Body"` | ||
Message Message | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.