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

add support soap 12 #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 32 additions & 11 deletions server_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ var serverTmpl = `
var WSDLUndefinedError = errors.New("Server was unable to process request. --> Object reference not set to an instance of an object.")

type SOAPEnvelopeRequest struct {
XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` + "`" + `
XMLName xml.Name ` + "`" + `xml:"Envelope"` + "`" + `
Body SOAPBodyRequest
}

type SOAPBodyRequest struct {
XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` + "`" + `
XMLName xml.Name ` + "`" + `xml:"Body"` + "`" + `
{{range .}}
{{range .Operations}}
{{$requestType := findType .Input.Message | replaceReservedWords | makePublic}} ` + `
Expand All @@ -36,6 +36,14 @@ func NewSOAPEnvelopResponse() *SOAPEnvelopeResponse {
}
}

func NewSOAP12EnvelopResponse() *SOAPEnvelopeResponse {
return &SOAPEnvelopeResponse{
PrefixSoap: "http://www.w3.org/2003/05/soap-envelope",
PrefixXsd: "http://www.w3.org/2001/XMLSchema",
PrefixXsi: "http://www.w3.org/2001/XMLSchema-instance",
}
}

type Fault struct { ` + `
XMLName xml.Name ` + "`" + `xml:"SOAP-ENV:Fault"` + "`" + `
Space string ` + "`" + `xml:"xmlns:SOAP-ENV,omitempty,attr"` + "`" + `
Expand Down Expand Up @@ -73,7 +81,14 @@ func (service *SOAPBodyRequest) {{$requestType}}Func(request *{{$requestType}})


func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "text/xml; charset=utf-8")
var isSOAP12 bool
if strings.Index(r.Header.Get("Content-Type"), "application/soap+xml") >= 0 {
w.Header().Add("Content-Type", "application/soap+xml; charset=utf-8")
isSOAP12 = true
} else {
w.Header().Add("Content-Type", "text/xml; charset=utf-8")
}

val := reflect.ValueOf(&service.Body).Elem()
n := val.NumField()
var field reflect.Value
Expand All @@ -85,23 +100,25 @@ func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request)
return
}

resp := NewSOAPEnvelopResponse()
var resp *SOAPEnvelopeResponse

if isSOAP12 {
resp = NewSOAP12EnvelopResponse()
} else {
resp = NewSOAPEnvelopResponse()
}

defer func() {
if r := recover(); r != nil {
resp.Body.Fault = &Fault{}
resp.Body.Fault.Space = "http://schemas.xmlsoap.org/soap/envelope/"
resp.Body.Fault.Space = resp.PrefixSoap
resp.Body.Fault.Code = "soap:Server"
resp.Body.Fault.Detail = fmt.Sprintf("%v", r)
resp.Body.Fault.String = fmt.Sprintf("%v", r)
}
xml.NewEncoder(w).Encode(resp)
}()

header := r.Header.Get("Content-Type")
if strings.Index(header, "application/soap+xml") >= 0 {
panic("Could not find an appropriate Transport Binding to invoke.")
}

err := xml.NewDecoder(r.Body).Decode(service)
if err != nil {
panic(err)
Expand All @@ -125,6 +142,11 @@ func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request)
if !find {
panic(WSDLUndefinedError)
} else {
if isSOAP12 {
defer func() {
r.Header.Set("Soapaction", fmt.Sprintf("SOAP12: %s", name))
}()
}
m := val.Addr().MethodByName(name + "Func")
if !m.IsValid() {
panic(WSDLUndefinedError)
Expand All @@ -137,7 +159,6 @@ func (service *SOAPEnvelopeRequest) call(w http.ResponseWriter, r *http.Request)
panic(vals[1].Interface())
}
}

}

func Endpoint(w http.ResponseWriter, r *http.Request) {
Expand Down