Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes and rpc support draft #75

Merged
merged 1 commit into from
Dec 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
case "", "-":
w = os.Stdout
default:
f, err := os.OpenFile(opts.Dst, os.O_CREATE|os.O_WRONLY, 0644)
f, err := os.OpenFile(opts.Dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
log.Fatal(err)
}
Expand Down
24 changes: 15 additions & 9 deletions soap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type AuthHeader struct {
type Client struct {
URL string // URL of the server
Namespace string // SOAP Namespace
ThisNamespace string // SOAP This-Namespace (tns)
ExcludeActionNamespace bool // Include Namespace to SOAP Action header
Envelope string // Optional SOAP Envelope
Header Header // Optional SOAP Header
Expand Down Expand Up @@ -93,9 +94,10 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
req := &Envelope{
EnvelopeAttr: c.Envelope,
NSAttr: c.Namespace,
TNSAttr: c.ThisNamespace,
XSIAttr: XSINamespace,
Header: c.Header,
Body: Body{Message: in},
Body: in,
}

if req.EnvelopeAttr == "" {
Expand All @@ -104,6 +106,9 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
if req.NSAttr == "" {
req.NSAttr = c.URL
}
if req.TNSAttr == "" {
req.TNSAttr = req.NSAttr
}
var b bytes.Buffer
err := xml.NewEncoder(&b).Encode(req)
if err != nil {
Expand Down Expand Up @@ -136,7 +141,13 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
Msg: string(body),
}
}
return xml.NewDecoder(resp.Body).Decode(out)

marshalStructure := struct {
XMLName xml.Name `xml:"Envelope"`
Body Message
}{Body: out}

return xml.NewDecoder(resp.Body).Decode(&marshalStructure)
}

// RoundTrip implements the RoundTripper interface.
Expand Down Expand Up @@ -209,13 +220,8 @@ type Envelope struct {
XMLName xml.Name `xml:"SOAP-ENV:Envelope"`
EnvelopeAttr string `xml:"xmlns:SOAP-ENV,attr"`
NSAttr string `xml:"xmlns:ns,attr"`
TNSAttr string `xml:"xmlns:tns,attr"`
XSIAttr string `xml:"xmlns:xsi,attr,omitempty"`
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
Body Message `xml:"SOAP-ENV:Body"`
}
18 changes: 9 additions & 9 deletions soap/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestSetXMLType(t *testing.T) {

func TestRoundTrip(t *testing.T) {
type msgT struct{ A, B string }
type envT struct{ Body struct{ Message msgT } }
type envT struct{ msgT }
echo := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.NotFound(w, r)
Expand Down Expand Up @@ -122,17 +122,17 @@ func TestRoundTrip(t *testing.T) {
t.Errorf("test %d: response to %#v is not an envelope", i, tc.In)
continue
}
if !reflect.DeepEqual(env.Body.Message, *tc.In.(*msgT)) {
if !reflect.DeepEqual(env.msgT, *tc.In.(*msgT)) {
t.Errorf("test %d: message mismatch\nwant: %#v\nhave: %#v",
i, tc.In, &env.Body.Message)
i, tc.In, &env.msgT)
continue
}
}
}

func TestRoundTripWithAction(t *testing.T) {
type msgT struct{ A, B string }
type envT struct{ Body struct{ Message msgT } }
type envT struct{ msgT }
echo := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.NotFound(w, r)
Expand Down Expand Up @@ -186,17 +186,17 @@ func TestRoundTripWithAction(t *testing.T) {
t.Errorf("test %d: response to %#v is not an envelope", i, tc.In)
continue
}
if !reflect.DeepEqual(env.Body.Message, *tc.In.(*msgT)) {
if !reflect.DeepEqual(env.msgT, *tc.In.(*msgT)) {
t.Errorf("test %d: message mismatch\nwant: %#v\nhave: %#v",
i, tc.In, &env.Body.Message)
i, tc.In, &env.msgT)
continue
}
}
}

func TestRoundTripSoap12(t *testing.T) {
type msgT struct{ A, B string }
type envT struct{ Body struct{ Message msgT } }
type envT struct{ msgT }
testAction := "http://foo.bar.com"

echo := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -254,9 +254,9 @@ func TestRoundTripSoap12(t *testing.T) {
t.Errorf("test %d: response to %#v is not an envelope", i, tc.In)
continue
}
if !reflect.DeepEqual(env.Body.Message, *tc.In.(*msgT)) {
if !reflect.DeepEqual(env.msgT, *tc.In.(*msgT)) {
t.Errorf("test %d: message mismatch\nwant: %#v\nhave: %#v",
i, tc.In, &env.Body.Message)
i, tc.In, &env.msgT)
continue
}
}
Expand Down
15 changes: 11 additions & 4 deletions wsdl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,17 @@ type IO struct {

// Binding describes SOAP to WSDL binding.
type Binding struct {
XMLName xml.Name `xml:"binding"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
Operations []*BindingOperation `xml:"operation"`
XMLName xml.Name `xml:"binding"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
BindingType *BindingType `xml:"binding"`
Operations []*BindingOperation `xml:"operation"`
}

// BindingType contains additional meta data on how to implement the binding.
type BindingType struct {
Style string `xml:"style,attr"`
Transport string `xml:"transport,attr"`
}

// BindingOperation describes the requirement for binding SOAP to WSDL
Expand Down
Loading