soapproxy

package module
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 26 Imported by: 1

README

soapproxy

A simple SOAP <-> gRPC proxy.

1. Generate the WSDL

with ./protoc-gen-wsdl:

protoc --wsdl_out=myproxy -I $GOPATH/src $GOPATH/src/unosoft.hu/ws/bruno/pb/dealer/dealer.proto

will create myproxy/dealer.wsdl and myproxy/dealer.wsdl.go.

2. Generate the Client code

with github.com/UNO-SOFT/gprcer/protoc-gen-grpcer:

protoc --grpcer_out=myproxy -I $GOPATH/src $GOPATH/src/unosoft.hu/ws/bruno/pb/dealer/dealer.proto

will create myproxy/dealer.grpcer.go, with grpc.Client implementation in it.

3. Profit!

Then use the SOAPHandler in myproxy/main.go (see ./example/example.go):

cc, err := grpcer.Connect("grpc-host:port", "ca.pem", "localhost")
if err != nil {
	log.Fatal(err)
}
http.ListenAndServe(
	":8080",
	soapproxy.SOAPHandler{Client:NewClient(cc), WSDL:soapproxy.Ungzb64(WSDLgzb64)},
)

Documentation

Index

Constants

View Source
const (
	SOAPHeader = `` /* 130-byte string literal not displayed */
	SOAPBody   = `</soapenv:Header><soapenv:Body>`
	SOAPFooter = `</soapenv:Body></soapenv:Envelope>`
)

Variables

View Source
var (
	DefaultCallTimeout = time.Minute
)
View Source
var DefaultTimeout = 5 * time.Minute

Functions

func FilterEmptyTags

func FilterEmptyTags(w io.Writer, r io.Reader) error

func FindBody

func FindBody(dec *xml.Decoder) (xml.StartElement, error)

FindBody will find the first StartElement after soap:Body.

func NewSOAPHandler added in v0.17.0

func NewSOAPHandler(config SOAPHandlerConfig) soapHandler

func SOAPCall added in v0.9.0

func SOAPCall(ctx context.Context, destURL, action string, reqBody string, resp interface{}, logger *slog.Logger) error

SOAPCall destURL with SOAPAction=action, decoding the response body into resp.

func SOAPCallWithHeader added in v0.11.0

func SOAPCallWithHeader(ctx context.Context,
	destURL string,
	customizeRequest func(*http.Request), customizeResponse func(*http.Response),
	action, soapHeader, reqBody string, resp interface{},
	logger *slog.Logger,
) error

SOAPCallWithHeader calls with the given SOAP- and extra header and action.

func SOAPCallWithHeaderClient added in v0.11.1

func SOAPCallWithHeaderClient(ctx context.Context,
	client *http.Client,
	destURL string,
	customizeRequest func(req *http.Request), customizeResponse func(resp *http.Response),
	action, soapHeader, reqBody string, resp interface{},
	logger *slog.Logger,
) error

SOAPCallWithHeader calls with the given SOAP- and extra header and action.

func Ungzb64

func Ungzb64(s string) string

Ungzb64 decodes-decompresses the given gzipped-base64-encoded string. Esp. useful for reading the WSDLgzb64 from protoc-gen-wsdl embedded WSDL strings.

Types

type Annotation added in v0.3.0

type Annotation struct {
	Raw      bool
	RemoveNS bool
}

type SOAPFault added in v0.4.6

type SOAPFault struct {
	XMLName xml.Name `xml:"SOAP-ENV:Fault"`
	Code    string   `xml:"faultcode,omitempty"`
	String  string   `xml:"faultstring,omitempty"`
	Actor   string   `xml:"faultactor,omitempty"`
	Detail  string   `xml:"detail>ExceptionDetail,omitempty"`
}

SOAPFault fault

type SOAPHandlerConfig added in v0.17.0

type SOAPHandlerConfig struct {
	grpcer.Client `json:"-"`
	*slog.Logger  `json:"-"`
	GetLogger     func(ctx context.Context) *slog.Logger
	DecodeInput   func(*string, *xml.Decoder, *xml.StartElement) (interface{}, error)                                                            `json:"-"`
	EncodeOutput  func(*xml.Encoder, interface{}) error                                                                                          `json:"-"`
	DecodeHeader  func(context.Context, *xml.Decoder, *xml.StartElement) (context.Context, func(context.Context, io.Writer, error) error, error) `json:"-"`
	LogRequest    func(context.Context, string, error)
	WSDL          string
	Locations     []string
	Timeout       time.Duration
}

SOAPHandlerConfig is the configuration for NewSOAPHandler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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