Skip to content

Commit 21aec6c

Browse files
author
Tim Lebel
committed
Have includes download from same namespace where they were included
1 parent 9fa7b7b commit 21aec6c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

gowsdl.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func downloadFile(url string, ignoreTLS bool) ([]byte, error) {
6767
}
6868

6969
defer resp.Body.Close()
70+
if resp.StatusCode != 200 {
71+
return nil, fmt.Errorf("Received response code %d", resp.StatusCode)
72+
}
73+
7074
data, err := ioutil.ReadAll(resp.Body)
7175
if err != nil {
7276
return nil, err
@@ -185,7 +189,7 @@ func (g *GoWSDL) unmarshal() error {
185189
}
186190

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

208212
data, err := downloadFile(schemaLocation, g.ignoreTLS)
213+
if err != nil {
214+
return err
215+
}
216+
209217
newschema := new(XSDSchema)
210218

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

216224
if len(newschema.Includes) > 0 &&
217225
maxRecursion > g.currentRecursionLevel {
218-
219226
g.currentRecursionLevel++
220227

221-
//log.Printf("Entering recursion %d\n", g.currentRecursionLevel)
222-
g.resolveXSDExternals(newschema, u1)
228+
// log.Printf("Entering recursion %d\n", g.currentRecursionLevel)
229+
err = g.resolveXSDExternals(newschema, u1)
230+
if err != nil {
231+
return err
232+
}
223233
}
224234

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

235-
236245
for _, impts := range schema.Imports {
237-
if e := download(u, impts.SchemaLocation); e!= nil {
246+
if e := download(u, impts.SchemaLocation); e != nil {
238247
return e
239248
}
240249
}
241250

242251
for _, incl := range schema.Includes {
243-
if e := download(u, incl.SchemaLocation); e!= nil {
252+
if e := download(u, schema.TargetNamespace+"/"+incl.SchemaLocation); e != nil {
244253
return e
245254
}
246255
}

0 commit comments

Comments
 (0)