Skip to content

Commit

Permalink
Have includes download from same namespace where they were included
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Lebel committed Aug 22, 2017
1 parent 9fa7b7b commit 21aec6c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func downloadFile(url string, ignoreTLS bool) ([]byte, error) {
}

defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("Received response code %d", resp.StatusCode)
}

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
Expand Down Expand Up @@ -185,7 +189,7 @@ func (g *GoWSDL) unmarshal() error {
}

func (g *GoWSDL) resolveXSDExternals(schema *XSDSchema, u *url.URL) error {
download := func(u1 *url.URL, loc string) error{
download := func(u1 *url.URL, loc string) error {
location, err := u1.Parse(loc)
if err != nil {
return err
Expand All @@ -206,6 +210,10 @@ func (g *GoWSDL) resolveXSDExternals(schema *XSDSchema, u *url.URL) error {
log.Println("Downloading external schema", "location", schemaLocation)

data, err := downloadFile(schemaLocation, g.ignoreTLS)
if err != nil {
return err
}

newschema := new(XSDSchema)

err = xml.Unmarshal(data, newschema)
Expand All @@ -215,11 +223,13 @@ func (g *GoWSDL) resolveXSDExternals(schema *XSDSchema, u *url.URL) error {

if len(newschema.Includes) > 0 &&
maxRecursion > g.currentRecursionLevel {

g.currentRecursionLevel++

//log.Printf("Entering recursion %d\n", g.currentRecursionLevel)
g.resolveXSDExternals(newschema, u1)
// log.Printf("Entering recursion %d\n", g.currentRecursionLevel)
err = g.resolveXSDExternals(newschema, u1)
if err != nil {
return err
}
}

g.wsdl.Types.Schemas = append(g.wsdl.Types.Schemas, newschema)
Expand All @@ -232,15 +242,14 @@ func (g *GoWSDL) resolveXSDExternals(schema *XSDSchema, u *url.URL) error {
return nil
}


for _, impts := range schema.Imports {
if e := download(u, impts.SchemaLocation); e!= nil {
if e := download(u, impts.SchemaLocation); e != nil {
return e
}
}

for _, incl := range schema.Includes {
if e := download(u, incl.SchemaLocation); e!= nil {
if e := download(u, schema.TargetNamespace+"/"+incl.SchemaLocation); e != nil {
return e
}
}
Expand Down

0 comments on commit 21aec6c

Please sign in to comment.