soap

package
v0.0.0-...-131e1ae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2024 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Predefined WSS namespaces to be used in
	WssNsWSSE string = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
	WssNsWSU  string = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
	WssNsType string = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"

	XmlNsSoapEnv string = "http://www.w3.org/2003/05/soap-envelope"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Binary

type Binary struct {
	// contains filtered or unexported fields
}

Binary enables binary data to be enchanged in MTOM mode with XOP encoding When MTOM is not used, the field is encoded in Base64

func NewBinary

func NewBinary(v []byte) *Binary

NewBinary allocate a new Binary backed by the given byte slice, an auto-generated packageID and no MTOM-usage

func (*Binary) Bytes

func (b *Binary) Bytes() []byte

Bytes returns a slice backed by the content of the field

func (*Binary) ContentType

func (b *Binary) ContentType() string

ContentType returns the content type

func (*Binary) MarshalXML

func (b *Binary) MarshalXML(enc *xml.Encoder, start xml.StartElement) error

MarshalXML implements the xml.Marshaler interface to encode a Binary to XML

func (*Binary) SetContentType

func (b *Binary) SetContentType(contentType string) *Binary

SetContentType sets the content type the content will be transmitted as multipart

func (*Binary) SetPackageID

func (b *Binary) SetPackageID(packageID string) *Binary

SetPackageID sets and overrides the default auto-generated package ID to be used for the multipart binary

func (*Binary) SetUseMTOM

func (b *Binary) SetUseMTOM(useMTOM bool) *Binary

SetUseMTOM activates the XOP transformation of binaries in MTOM requests

func (*Binary) UnmarshalXML

func (b *Binary) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the xml.Unmarshaler interface to decode a Binary form XML

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is soap client

func NewClient

func NewClient(url string, opt ...Option) *Client

NewClient creates new SOAP client instance

func (*Client) AddHeader

func (s *Client) AddHeader(header interface{})

AddHeader adds envelope header For correct behavior, every header must contain a `XMLName` field. Refer to #121 for details

func (*Client) AddMIMEMultipartAttachment

func (s *Client) AddMIMEMultipartAttachment(attachment MIMEMultipartAttachment)

AddMIMEMultipartAttachment adds an attachment to the client that will be sent only if the WithMIMEMultipartAttachments option is used

func (*Client) Call

func (s *Client) Call(soapAction string, request, response interface{}) error

Call performs HTTP POST request. Note that if the server returns a status code >= 400, a HTTPError will be returned

func (*Client) CallContext

func (s *Client) CallContext(ctx context.Context, soapAction string, request, response interface{}) error

CallContext performs HTTP POST request with a context

func (*Client) CallContextWithAttachmentsAndFaultDetail

func (s *Client) CallContextWithAttachmentsAndFaultDetail(ctx context.Context, soapAction string, request,
	response interface{}, faultDetail FaultError, attachments *[]MIMEMultipartAttachment) error

CallContextWithAttachmentsAndFaultDetail performs HTTP POST request. Note that if SOAP fault is returned, it will be stored in the error. On top the attachments array will be filled with attachments returned from the SOAP request.

func (*Client) CallContextWithFaultDetail

func (s *Client) CallContextWithFaultDetail(ctx context.Context, soapAction string, request, response interface{}, faultDetail FaultError) error

CallContextWithFault performs HTTP POST request. Note that if SOAP fault is returned, it will be stored in the error.

func (*Client) CallWithFaultDetail

func (s *Client) CallWithFaultDetail(soapAction string, request, response interface{}, faultDetail FaultError) error

CallWithFaultDetail performs HTTP POST request. Note that if SOAP fault is returned, it will be stored in the error. the passed in fault detail is expected to implement FaultError interface, which allows to condense the detail into a short error message.

func (*Client) GetHttpClientHeaders

func (s *Client) GetHttpClientHeaders() map[string]string

Get all currently available http headers from client Use case: For setting authentication header

func (*Client) SetHeaders

func (s *Client) SetHeaders(headers ...interface{})

SetHeaders sets envelope headers, overwriting any existing headers. For correct behavior, every header must contain a `XMLName` field. Refer to #121 for details

func (*Client) SetHttpClientHeaders

func (s *Client) SetHttpClientHeaders(headers map[string]string)

Update Http headers with latest header information

type DetailContainer

type DetailContainer struct {
	Detail interface{}
}

type FaultError

type FaultError interface {
	// ErrorString should return a short version of the detail as a string,
	// which will be used in place of <faultstring> for the error message.
	// Set "HasData()" to always return false if <faultstring> error
	// message is preferred.
	ErrorString() string
	// HasData indicates whether the composite fault contains any data.
	HasData() bool
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is a client which can make HTTP requests An example implementation is net/http.Client

type HTTPError

type HTTPError struct {
	//StatusCode is the status code returned in the HTTP response
	StatusCode int
	//ResponseBody contains the body returned in the HTTP response
	ResponseBody []byte
}

HTTPError is returned whenever the HTTP request to the server fails

func (*HTTPError) Error

func (e *HTTPError) Error() string

type MIMEMultipartAttachment

type MIMEMultipartAttachment struct {
	Name string
	Data []byte
}

type Option

type Option func(*options)

A Option sets options such as credentials, tls, etc.

func WithBasicAuth

func WithBasicAuth(login, password string) Option

WithBasicAuth is an Option to set BasicAuth

func WithHTTPClient

func WithHTTPClient(c HTTPClient) Option

WithHTTPClient is an Option to set the HTTP client to use This cannot be used with WithTLSHandshakeTimeout, WithTLS, WithTimeout options

func WithHTTPHeaders

func WithHTTPHeaders(headers map[string]string) Option

WithHTTPHeaders is an Option to set global HTTP headers for all requests

func WithMIMEMultipartAttachments

func WithMIMEMultipartAttachments() Option

WithMIMEMultipartAttachments is an Option to set SOAP MIME Multipart attachment support. Use Client.AddMIMEMultipartAttachment to add attachments of type MIMEMultipartAttachment to your SOAP request.

func WithMTOM

func WithMTOM() Option

WithMTOM is an Option to set Message Transmission Optimization Mechanism MTOM encodes fields of type Binary using XOP.

func WithRequestTimeout

func WithRequestTimeout(t time.Duration) Option

WithRequestTimeout is an Option to set default end-end connection timeout This option cannot be used with WithHTTPClient

func WithTLS

func WithTLS(tls *tls.Config) Option

WithTLS is an Option to set tls config This option cannot be used with WithHTTPClient

func WithTLSHandshakeTimeout

func WithTLSHandshakeTimeout(t time.Duration) Option

WithTLSHandshakeTimeout is an Option to set default tls handshake timeout This option cannot be used with WithHTTPClient

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout is an Option to set default HTTP dial timeout

type SOAPBody

type SOAPBody struct {
	XMLName xml.Name `xml:"soap:Body"`

	Content interface{} `xml:",omitempty"`

	Fault *SOAPFault `xml:",omitempty"`
	// contains filtered or unexported fields
}

func (*SOAPBody) ErrorFromFault

func (b *SOAPBody) ErrorFromFault() error

type SOAPBodyResponse

type SOAPBodyResponse struct {
	XMLName xml.Name `xml:"Body"`

	Content interface{} `xml:",omitempty"`

	Fault *SOAPFault `xml:",omitempty"`
	// contains filtered or unexported fields
}

func (*SOAPBodyResponse) ErrorFromFault

func (b *SOAPBodyResponse) ErrorFromFault() error

func (*SOAPBodyResponse) UnmarshalXML

func (b *SOAPBodyResponse) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error

UnmarshalXML unmarshals SOAPBody xml

type SOAPDecoder

type SOAPDecoder interface {
	Decode(v interface{}) error
}

type SOAPEncoder

type SOAPEncoder interface {
	Encode(v interface{}) error
	Flush() error
}

type SOAPEnvelope

type SOAPEnvelope struct {
	XMLName xml.Name      `xml:"soap:Envelope"`
	XmlNS   string        `xml:"xmlns:soap,attr"`
	Headers []interface{} `xml:"soap:Header"`
	Body    SOAPBody
}

type SOAPEnvelopeResponse

type SOAPEnvelopeResponse struct {
	XMLName     xml.Name `xml:"http://www.w3.org/2003/05/soap-envelope Envelope"`
	Header      *SOAPHeaderResponse
	Body        SOAPBodyResponse
	Attachments []MIMEMultipartAttachment `xml:"attachments,omitempty"`
}

type SOAPFault

type SOAPFault struct {
	XMLName xml.Name `xml:"http://www.w3.org/2003/05/soap-envelope Fault"`

	Code   string     `xml:"faultcode,omitempty"`
	String string     `xml:"faultstring,omitempty"`
	Actor  string     `xml:"faultactor,omitempty"`
	Detail FaultError `xml:"detail,omitempty"`
}

func (*SOAPFault) Error

func (f *SOAPFault) Error() string

type SOAPHeaderResponse

type SOAPHeaderResponse struct {
	XMLName xml.Name `xml:"Header"`

	Headers []interface{}
}

type WSSPassword

type WSSPassword struct {
	XMLName   xml.Name `xml:"wsse:Password"`
	XmlNSWsse string   `xml:"xmlns:wsse,attr"`
	XmlNSType string   `xml:"Type,attr"`

	Data string `xml:",chardata"`
}

type WSSSecurityHeader

type WSSSecurityHeader struct {
	XMLName   xml.Name `xml:"http://www.w3.org/2003/05/soap-envelope wsse:Security"`
	XmlNSWsse string   `xml:"xmlns:wsse,attr"`

	MustUnderstand string `xml:"mustUnderstand,attr,omitempty"`

	Token *WSSUsernameToken `xml:",omitempty"`
}

func NewWSSSecurityHeader

func NewWSSSecurityHeader(user, pass, tokenID, mustUnderstand string) *WSSSecurityHeader

NewWSSSecurityHeader creates WSSSecurityHeader instance

type WSSUsername

type WSSUsername struct {
	XMLName   xml.Name `xml:"wsse:Username"`
	XmlNSWsse string   `xml:"xmlns:wsse,attr"`

	Data string `xml:",chardata"`
}

type WSSUsernameToken

type WSSUsernameToken struct {
	XMLName   xml.Name `xml:"wsse:UsernameToken"`
	XmlNSWsu  string   `xml:"xmlns:wsu,attr"`
	XmlNSWsse string   `xml:"xmlns:wsse,attr"`

	Id string `xml:"wsu:Id,attr,omitempty"`

	Username *WSSUsername `xml:",omitempty"`
	Password *WSSPassword `xml:",omitempty"`
}

type XSDDate

type XSDDate struct {
	// contains filtered or unexported fields
}

XSDDate is a type for representing xsd:date in Golang

func CreateXsdDate

func CreateXsdDate(date time.Time, hasTz bool) XSDDate

CreateXsdDate creates an object represent xsd:datetime object in Golang

func (XSDDate) MarshalXML

func (xd XSDDate) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implementation on XSDDate

func (XSDDate) MarshalXMLAttr

func (xd XSDDate) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr implementation on XSDDate

func (*XSDDate) StripTz

func (xd *XSDDate) StripTz()

StripTz removes the TZ information from the date

func (*XSDDate) ToGoTime

func (xd *XSDDate) ToGoTime() time.Time

ToGoTime converts the date to Golang time.Time by checking if a TZ is specified. If there is a TZ, that TZ is used, otherwise local TZ is used

func (*XSDDate) UnmarshalXML

func (xd *XSDDate) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler on XSDDate to use dateLayout

func (*XSDDate) UnmarshalXMLAttr

func (xd *XSDDate) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr implements xml.UnmarshalerAttr on XSDDate to use dateLayout

type XSDDateTime

type XSDDateTime struct {
	// contains filtered or unexported fields
}

XSDDateTime is a type for representing xsd:datetime in Golang

func CreateXsdDateTime

func CreateXsdDateTime(dt time.Time, hasTz bool) XSDDateTime

CreateXsdDateTime creates an object represent xsd:datetime object in Golang

func (XSDDateTime) MarshalXML

func (xdt XSDDateTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.MarshalerAttr on XSDDateTime

func (XSDDateTime) MarshalXMLAttr

func (xdt XSDDateTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr implements xml.MarshalerAttr on XSDDateTime

func (*XSDDateTime) StripTz

func (xdt *XSDDateTime) StripTz()

StripTz removes TZ information from the datetime

func (*XSDDateTime) ToGoTime

func (xdt *XSDDateTime) ToGoTime() time.Time

ToGoTime converts the time to time.Time by checking if a TZ is specified. If there is a TZ, that TZ is used, otherwise local TZ is used

func (*XSDDateTime) UnmarshalXML

func (xdt *XSDDateTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler on XSDDateTime to use time.RFC3339Nano

func (*XSDDateTime) UnmarshalXMLAttr

func (xdt *XSDDateTime) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr implements xml.UnmarshalerAttr on XSDDateTime to use time.RFC3339Nano

type XSDTime

type XSDTime struct {
	// contains filtered or unexported fields
}

XSDTime is a type for representing xsd:time

func CreateXsdTime

func CreateXsdTime(hour int, min int, sec int, nsec int, loc *time.Location) XSDTime

CreateXsdTime creates an object representing xsd:time in Golang

func (XSDTime) Hour

func (xt XSDTime) Hour() int

Hour returns hour of the xsd:time

func (XSDTime) Location

func (xt XSDTime) Location() *time.Location

Location returns the TZ information of the xsd:time

func (XSDTime) MarshalXML

func (xt XSDTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.Marshaler on XSDTime

func (XSDTime) MarshalXMLAttr

func (xt XSDTime) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

MarshalXMLAttr implements xml.MarshalerAttr on XSDTime

func (XSDTime) Minute

func (xt XSDTime) Minute() int

Minute returns minutes of the xsd:time

func (XSDTime) Nanosecond

func (xt XSDTime) Nanosecond() int

Nanosecond returns nanosecond of the xsd:time

func (XSDTime) Second

func (xt XSDTime) Second() int

Second returns seconds of the xsd:time

func (*XSDTime) UnmarshalXML

func (xt *XSDTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler on XSDTime to use dateTimeLayout

func (*XSDTime) UnmarshalXMLAttr

func (xt *XSDTime) UnmarshalXMLAttr(attr xml.Attr) error

UnmarshalXMLAttr implements xml.UnmarshalerAttr on XSDTime to use dateTimeLayout

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL