Skip to content

Commit

Permalink
Fix character-set issues (#108)
Browse files Browse the repository at this point in the history
* Fix character-set issues

* Add decoder charset compliance to soap client

* Update travis ci file to force env var for build and path to golint
  • Loading branch information
digitalsparky authored and fiorix committed Jan 8, 2019
1 parent 69b96af commit 19735c0
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ sudo: false
language: go

install:
- go get -u github.com/golang/lint/golint
- go get -u github.com/golang/dep/cmd/dep
- go get -u golang.org/x/lint/golint

before_script:
- dep ensure
- go vet ./...
- golint ./...

go:
- 1.7
- 1.8
- 1.9
- tip

Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
# Please keep the list sorted.

Alexandre Fiori <[email protected]>
Matt Spurrier <[email protected]>
47 changes: 47 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
branch = "master"
name = "golang.org/x/net"

[prune]
go-tests = true
unused-packages = true
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# wsdl2go
[![Build Status](https://travis-ci.org/fiorix/wsdl2go.svg)](https://travis-ci.org/fiorix/wsdl2go)

[![Build Status](https://travis-ci.org/digitalsparky/wsdl2go.svg)](https://travis-ci.org/digitalsparky/wsdl2go)
[![Go Report Card](https://goreportcard.com/badge/github.com/fiorix/wsdl2go)](https://goreportcard.com/report/github.com/fiorix/wsdl2go)
[![GoDoc](https://godoc.org/github.com/fiorix/wsdl2go?status.svg)](https://godoc.org/github.com/fiorix/wsdl2go)

Expand Down Expand Up @@ -32,10 +33,10 @@ Here's how to use the generated code: let's say you have a WSDL that defines the

The process is this:

* Import the generated code
* Create a soap.Client (and here you can configure SOAP authentication, for example)
* Instantiate the service using your soap.Client
* Call the service methods
- Import the generated code
- Create a soap.Client (and here you can configure SOAP authentication, for example)
- Instantiate the service using your soap.Client
- Call the service methods

Example:

Expand All @@ -59,8 +60,8 @@ func main() {

The soap.Client supports two forms of authentication:

* Setting the "Pre" hook to a function that is run on all outbound HTTP requests, which can set HTTP headers and Basic Auth
* Setting the Header attribute to an AuthHeader, to have it as a SOAP header (with username and password) in every request
- Setting the "Pre" hook to a function that is run on all outbound HTTP requests, which can set HTTP headers and Basic Auth
- Setting the Header attribute to an AuthHeader, to have it as a SOAP header (with username and password) in every request

Note that only the **Document** style of SOAP is supported. The RPC style is currently not supported.

Expand Down
6 changes: 5 additions & 1 deletion soap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"io/ioutil"
"net/http"
"reflect"

"golang.org/x/net/html/charset"
)

// XSINamespace is a link to the XML Schema instance namespace.
Expand Down Expand Up @@ -154,7 +156,9 @@ func doRoundTrip(c *Client, setHeaders func(*http.Request), in, out Message) err
Body Message
}{Body: out}

return xml.NewDecoder(resp.Body).Decode(&marshalStructure)
decoder := xml.NewDecoder(resp.Body)
decoder.CharsetReader = charset.NewReaderLabel
return decoder.Decode(&marshalStructure)
}

// RoundTrip implements the RoundTripper interface.
Expand Down
6 changes: 5 additions & 1 deletion wsdl/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package wsdl
import (
"encoding/xml"
"io"

"golang.org/x/net/html/charset"
)

// Unmarshal unmarshals WSDL documents starting from the <definitions> tag.
Expand All @@ -14,7 +16,9 @@ import (
// WSDL XML that can be introspected to generate the Web Services API.
func Unmarshal(r io.Reader) (*Definitions, error) {
var d Definitions
err := xml.NewDecoder(r).Decode(&d)
decoder := xml.NewDecoder(r)
decoder.CharsetReader = charset.NewReaderLabel
err := decoder.Decode(&d)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion wsdlgo/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"text/template"

"github.com/fiorix/wsdl2go/wsdl"
"golang.org/x/net/html/charset"
)

// An Encoder generates Go code from WSDL definitions.
Expand Down Expand Up @@ -339,7 +340,9 @@ func (ge *goEncoder) importRemote(loc string, v interface{}) error {

r = bufio.NewReader(file)
}
return xml.NewDecoder(r).Decode(v)
decoder := xml.NewDecoder(r)
decoder.CharsetReader = charset.NewReaderLabel
return decoder.Decode(&v)

}

Expand Down

0 comments on commit 19735c0

Please sign in to comment.