get error message from soap message
This commit is contained in:
+2
-1
@@ -51,7 +51,8 @@ func sendMessage(c *gin.Context) {
|
|||||||
message.Priority, message.Event, message.Val, message.Msg)
|
message.Priority, message.Event, message.Val, message.Msg)
|
||||||
url := getURL(message.URL)
|
url := getURL(message.URL)
|
||||||
resp := internal.Send(url, msg)
|
resp := internal.Send(url, msg)
|
||||||
c.String(http.StatusOK, resp)
|
errMsg := internal.GetErrMsg(resp)
|
||||||
|
c.JSON(http.StatusOK, gin.H{"error": errMsg})
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ const (
|
|||||||
`
|
`
|
||||||
|
|
||||||
msgExp = `<ns1:string>.*<\/ns1:string>`
|
msgExp = `<ns1:string>.*<\/ns1:string>`
|
||||||
|
errExp = `<errorMessage .*<\/errorMessage>`
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateSend xml string for sending
|
// CreateSend xml string for sending
|
||||||
@@ -122,6 +123,17 @@ func GetMsgs(soap string) []string {
|
|||||||
return Map(msgs, split)
|
return Map(msgs, split)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetErrMsg get error message
|
||||||
|
func GetErrMsg(soap string) string {
|
||||||
|
r, _ := regexp.Compile(errExp)
|
||||||
|
msg := r.FindAllString(soap, -1)
|
||||||
|
if len(msg) > 0 && len(msg[0]) > 40 {
|
||||||
|
size := len(msg[0])
|
||||||
|
return msg[0][54 : size-15]
|
||||||
|
}
|
||||||
|
return msg[0]
|
||||||
|
}
|
||||||
|
|
||||||
func split(msg string) string {
|
func split(msg string) string {
|
||||||
if len(msg) > 12 {
|
if len(msg) > 12 {
|
||||||
return msg[12 : len(msg)-13]
|
return msg[12 : len(msg)-13]
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ const (
|
|||||||
</soap:Envelope>`
|
</soap:Envelope>`
|
||||||
|
|
||||||
Msg string = `<?xml version="1.0" encoding="UTF-8"?> <msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="unisysaodbsis.xsd"> <meta> <sndr>AODB</sndr> <seqn>820830</seqn> <dttm>20180527124442</dttm> <type>FLOP</type> <styp>ESTT</styp> </meta> <flop> <flid>10725849</flid> <ffid>CA-CA4242-A-27MAY181955-D</ffid> <estt>27MAY181945</estt> </flop> </msg>`
|
Msg string = `<?xml version="1.0" encoding="UTF-8"?> <msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="unisysaodbsis.xsd"> <meta> <sndr>AODB</sndr> <seqn>820830</seqn> <dttm>20180527124442</dttm> <type>FLOP</type> <styp>ESTT</styp> </meta> <flop> <flid>10725849</flid> <ffid>CA-CA4242-A-27MAY181955-D</ffid> <estt>27MAY181945</estt> </flop> </msg>`
|
||||||
|
|
||||||
|
ErrMsg string = `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>invalid route envent id </faultstring><detail><BHIAFault xmlns="http://ciims.bhia.itdcl.com"><code xmlns="http://msg.ciims.bhia.itdcl.com">20</code><errorMessage xmlns="http://msg.ciims.bhia.itdcl.com">Can not find the event [FLOP-ESTT-ATC-ALL1]</errorMessage></BHIAFault></detail></soap:Fault></soap:Body></soap:Envelope>`
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSend(t *testing.T) {
|
func TestSend(t *testing.T) {
|
||||||
@@ -118,3 +120,9 @@ func TestGetMsg(t *testing.T) {
|
|||||||
assert.Equal(2, len(msgs), "should get 2 message")
|
assert.Equal(2, len(msgs), "should get 2 message")
|
||||||
assert.Equal(Msg, msgs[0], "message")
|
assert.Equal(Msg, msgs[0], "message")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetErrMsg(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
errMsg := GetErrMsg(ErrMsg)
|
||||||
|
assert.Equal("Can not find the event [FLOP-ESTT-ATC-ALL1]", errMsg)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user