-
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
0 parents
commit c3cec21
Showing
27 changed files
with
1,877 additions
and
0 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,9 @@ | ||
sudo: false | ||
|
||
language: go | ||
|
||
go: | ||
- 1.6 | ||
|
||
script: | ||
- go test -v ./wsdl ./wsdlgo |
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,31 @@ | ||
# wsdl2go | ||
|
||
wsdl2go is a command line tool to generate [Go](https://golang.org) code | ||
from [WSDL](https://en.wikipedia.org/wiki/Web_Services_Description_Language). | ||
|
||
### Status | ||
|
||
Not fully compliant with SOAP or WSDL. Works for my needs and has been | ||
tested with a few SOAP enterprise systems. | ||
|
||
There are limitations related to XML namespaces in Go, which might impact | ||
how this program works. Details: https://github.com/golang/go/issues/14407. | ||
|
||
WSDL types supported: | ||
|
||
- [x] int | ||
- [x] long (int64) | ||
- [x] float (float64) | ||
- [x] boolean (bool) | ||
- [x] string | ||
- [x] date | ||
- [x] time | ||
- [x] dateTime | ||
- [x] complexType (struct) | ||
|
||
Date types are currently defined as strings, need to implement XML | ||
Marshaler and Unmarshaler interfaces. | ||
|
||
The Go code generator (package wsdlgo) is capable of importing remote | ||
parts of the WSDL via HTTP. You can configure its http.Client to support | ||
authentication and self-signed certificates. |
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,9 @@ | ||
#!/bin/bash | ||
|
||
VERSION=${VERSION:-`git describe --tags`} | ||
|
||
for OS in linux freebsd windows darwin | ||
do | ||
GOOS=$OS GOARCH=amd64 go build -ldflags "-w -X main.version=${VERSION}" | ||
tar czf wsdl2go-$VERSION-$OS-amd64.tar.gz wsdl2go* | ||
done |
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,87 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"flag" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
|
||
"github.com/fiorix/wsdl2go/wsdl" | ||
"github.com/fiorix/wsdl2go/wsdlgo" | ||
) | ||
|
||
var version = "tip" | ||
|
||
func main() { | ||
opts := struct { | ||
Src string | ||
Dst string | ||
Insecure bool | ||
Version bool | ||
}{} | ||
flag.StringVar(&opts.Src, "i", opts.Src, "input file, url, or '-' for stdin") | ||
flag.StringVar(&opts.Dst, "o", opts.Dst, "output file, or '-' for stdout") | ||
flag.BoolVar(&opts.Insecure, "yolo", opts.Insecure, "accept invalid https certificates") | ||
flag.BoolVar(&opts.Version, "version", opts.Version, "show version and exit") | ||
flag.Parse() | ||
if opts.Version { | ||
fmt.Printf("wsdl2go %s\n", version) | ||
return | ||
} | ||
var w io.Writer | ||
switch opts.Dst { | ||
case "", "-": | ||
w = os.Stdout | ||
default: | ||
f, err := os.OpenFile(opts.Dst, os.O_WRONLY, 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
w = f | ||
} | ||
cli := http.DefaultClient | ||
if opts.Insecure { | ||
cli.Transport = &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
} | ||
err := decode(w, opts.Src, cli) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func decode(w io.Writer, src string, cli *http.Client) error { | ||
var err error | ||
var f io.ReadCloser | ||
if src == "" || src == "-" { | ||
f = os.Stdin | ||
} else if f, err = open(src, cli); err != nil { | ||
return err | ||
} | ||
d, err := wsdl.Unmarshal(f) | ||
if err != nil { | ||
return err | ||
} | ||
f.Close() | ||
enc := wsdlgo.NewEncoder(w) | ||
enc.SetClient(cli) | ||
return enc.Encode(d) | ||
} | ||
|
||
func open(name string, cli *http.Client) (io.ReadCloser, error) { | ||
_, err := url.Parse(name) | ||
if err != nil { | ||
return os.Open(name) | ||
} | ||
resp, err := cli.Get(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return resp.Body, err | ||
} |
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,22 @@ | ||
// Package wsdl provides Web Services Description Language (WSDL) decoder. | ||
// | ||
// http://www.w3schools.com/xml/xml_wsdl.asp | ||
package wsdl | ||
|
||
import ( | ||
"encoding/xml" | ||
"io" | ||
) | ||
|
||
// Unmarshal unmarshals WSDL documents starting from the <definitions> tag. | ||
// | ||
// The Definitions object it returns is an unmarshalled version of the | ||
// 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) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &d, nil | ||
} |
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,43 @@ | ||
package wsdl | ||
|
||
import ( | ||
"encoding/xml" | ||
"os" | ||
"path/filepath" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestUnmarshal(t *testing.T) { | ||
cases := []struct { | ||
F string | ||
E error | ||
}{ | ||
{ | ||
F: "golden1.wsdl", | ||
E: nil, | ||
}, { | ||
F: "golden2.wsdl", | ||
E: xml.UnmarshalError("..."), | ||
}, | ||
} | ||
for i, tc := range cases { | ||
f, err := os.Open(filepath.Join("testdata", tc.F)) | ||
if err != nil { | ||
t.Errorf("test %d failed: %v", i, err) | ||
} | ||
defer f.Close() | ||
_, err = Unmarshal(f) | ||
if tc.E == nil { | ||
if err != nil { | ||
t.Errorf("test %d failed: want %v, have %v", i, tc.E, err) | ||
} | ||
continue | ||
} | ||
want := reflect.ValueOf(tc.E).Type().Name() | ||
have := reflect.ValueOf(err).Type().Name() | ||
if want != have { | ||
t.Errorf("test %d failed: want %q, have %q", i, want, have) | ||
} | ||
} | ||
} |
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,18 @@ | ||
<definitions> | ||
|
||
<message name="getTermRequest"> | ||
<part name="term" type="xs:string"/> | ||
</message> | ||
|
||
<message name="getTermResponse"> | ||
<part name="value" type="xs:string"/> | ||
</message> | ||
|
||
<portType name="glossaryTerms"> | ||
<operation name="getTerm"> | ||
<input message="getTermRequest"/> | ||
<output message="getTermResponse"/> | ||
</operation> | ||
</portType> | ||
|
||
</definitions> |
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 @@ | ||
<fail-me> |
Oops, something went wrong.