Documentation
¶
Overview ¶
Package soap provides SOAP message handling for XML-based web services. It implements the SOAP 1.1 protocol with support for envelopes, headers, bodies, and faults.
Index ¶
Constants ¶
const (
// ActionHeader is the HTTP header name for the SOAP action.
ActionHeader = "SOAPAction"
)
const (
// ContentType is the standard SOAP content type.
ContentType = `text/xml; charset="utf-8"`
)
Variables ¶
This section is empty.
Functions ¶
func DefaultWrapper ¶
func DefaultWrapper(logger log.Logger, logMiddleware endpoint.LogMiddleware, restMiddlewares ...http.Middleware) endpoint.Wrapper
DefaultWrapper creates a pre-configured endpoint.Wrapper for SOAP services. It includes request logging, metrics collection, tracing, error handling, and recovery. The default maximum request body size is 64MB.
func ErrorHandler ¶
func ErrorHandler(logger log.Logger) http2.Middleware
ErrorHandler is a middleware that logs errors and writes SOAP fault responses. It uses the error's WriteError method if available; otherwise, it returns a generic server fault to hide implementation details.
Types ¶
type ActionMux ¶
type ActionMux struct {
// contains filtered or unexported fields
}
ActionMux routes SOAP requests based on the SOAPAction HTTP header. It provides a simple multiplexer for handling multiple SOAP operations.
func NewActionMux ¶
func NewActionMux() *ActionMux
NewActionMux creates a new ActionMux with an empty handler map.
func (*ActionMux) Handle ¶
Handle registers a handler for the specified SOAP action URI. It panics if a handler for the action is already registered. Returns the ActionMux for fluent chaining.
func (*ActionMux) ServeHTTP ¶
func (m *ActionMux) ServeHTTP(writer http.ResponseWriter, request *http.Request)
ServeHTTP implements the http.Handler interface and routes requests based on SOAPAction. It returns a SOAP fault if the SOAPAction header is missing or the action is unknown. The action is added to the request context for logging purposes.
type Body ¶
type Body struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"`
Content any `xml:",omitempty"`
Fault *Fault `xml:",omitempty"`
// contains filtered or unexported fields
}
Body represents a SOAP body containing the message content or fault. It supports both regular content and SOAP faults, with WS-I compliance validation.
func (*Body) UnmarshalXML ¶
UnmarshalXML decodes a SOAP body from XML, handling both content and faults. It enforces WS-I compliance by rejecting multiple elements inside the SOAP body.
type Envelope ¶
type Envelope struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
Header *Header
Body Body
}
Envelope represents a SOAP envelope containing a header and body. It is the root element of a SOAP message.
type Fault ¶
type Fault struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"`
Code string `xml:"faultcode,omitempty"`
String string `xml:"faultstring,omitempty"`
Actor string `xml:"faultactor,omitempty"`
Detail any `xml:"detail,omitempty"`
}
Fault represents a SOAP fault containing error information. It follows the SOAP 1.1 fault structure with code, string, actor, and optional detail. nolint:errname
func (Fault) WriteError ¶
func (f Fault) WriteError(w http.ResponseWriter) error
WriteError writes the fault as a SOAP XML response to the http.ResponseWriter. It sets the Content-Type to text/xml and the HTTP status code to 500.
type Header ¶
type Header struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
Items []any `xml:",omitempty"`
}
Header represents a SOAP header containing optional metadata.
type RequestExtractor ¶
type RequestExtractor struct {
Validator Validator
}
RequestExtractor extracts and validates SOAP request bodies from XML. It decodes the SOAP envelope, extracts the body content, and validates it.
func (RequestExtractor) Extract ¶
func (j RequestExtractor) Extract(_ context.Context, reader io.Reader, reqBodyType reflect.Type) (reflect.Value, error)
Extract decodes the SOAP envelope from the reader and extracts the body content into a reflect.Value of the specified type. It validates the decoded value and returns a SOAP fault if validation fails.
type ResponseMapper ¶
type ResponseMapper struct {
}
ResponseMapper maps response objects to SOAP XML format. It wraps the result in a SOAP envelope and sets the appropriate content type.
func (ResponseMapper) Map ¶
func (j ResponseMapper) Map(ctx context.Context, result any, w http.ResponseWriter) error
Map encodes the result as a SOAP envelope and writes it to the http.ResponseWriter. It sets the Content-Type to text/xml and includes the request ID in response headers if available.