Add support for *text_plain as reply for HTTPAgent

This commit is contained in:
TeoV
2019-07-09 12:12:56 +03:00
committed by Dan Christian Bogos
parent 33919a4893
commit 524f726256
5 changed files with 118 additions and 0 deletions

View File

@@ -57,6 +57,7 @@ var sTestsHA = []func(t *testing.T){
testHAitAuth1001,
testHAitCDRmtcall,
testHAitCDRmtcall2,
testHAitTextPlain,
testHAitStopEngine,
}
@@ -305,6 +306,34 @@ func testHAitCDRmtcall2(t *testing.T) {
}
}
func testHAitTextPlain(t *testing.T) {
httpConst := "http"
addr := haCfg.ListenCfg().HTTPListen
if isTls {
addr = haCfg.ListenCfg().HTTPTLSListen
httpConst = "https"
}
reqUrl := fmt.Sprintf("%s://%s%s?request_type=TextPlainDryRun&CallID=123456&Msisdn=497700056231&Imsi=2343000000000123&Destination=491239440004&MSRN=0102220233444488999&ProfileID=1&AgentID=176&GlobalMSISDN=497700056129&GlobalIMSI=214180000175129&ICCID=8923418450000089629&MCC=234&MNC=10&calltype=callback",
httpConst, addr, haCfg.HttpAgentCfg()[2].Url)
rply, err := httpC.Get(reqUrl)
if err != nil {
t.Fatal(err)
}
eXml := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<response>
<Allow>1</Allow>
<Concatenated>234/Val1</Concatenated>
<MaxDuration>1200</MaxDuration>
</response>`)
if body, err := ioutil.ReadAll(rply.Body); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eXml, body) {
t.Errorf("expecting: <%s>, received: <%s>", string(eXml), string(body))
}
rply.Body.Close()
time.Sleep(time.Millisecond)
}
func testHAitStopEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)

View File

@@ -213,6 +213,8 @@ func newHAReplyEncoder(encType string,
return nil, fmt.Errorf("unsupported encoder type <%s>", encType)
case utils.MetaXml:
return newHAXMLEncoder(w)
case utils.MetaTextPlain:
return newHATextPlainEncoder(w)
}
}
@@ -243,3 +245,27 @@ func (xE *haXMLEncoder) Encode(nM *config.NavigableMap) (err error) {
_, err = xE.w.Write(xmlOut)
return
}
func newHATextPlainEncoder(w http.ResponseWriter) (xE httpAgentReplyEncoder, err error) {
return &haTextPlainEncoder{w: w}, nil
}
type haTextPlainEncoder struct {
w http.ResponseWriter
}
// Encode implements httpAgentReplyEncoder
func (xE *haTextPlainEncoder) Encode(nM *config.NavigableMap) (err error) {
var str string
for _, val := range nM.Values() {
nmItms, isNMItems := val.([]*config.NMItem)
if !isNMItems {
return fmt.Errorf("value: %+v is not []*NMItem", val)
}
for _, nmItm := range nmItms {
str += fmt.Sprintf("%s=%s\n", strings.Join(nmItm.Path, utils.NestingSep), utils.IfaceAsString(nmItm.Data))
}
}
_, err = xE.w.Write([]byte(str))
return
}

View File

@@ -125,6 +125,37 @@
}
],
},
{
"id": "conecto_textplain",
"url": "/conecto_textplain",
"sessions_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}
],
"request_payload": "*url",
"reply_payload": "*text_plain",
"request_processors": [
{
"id": "TextPlainDryRun",
"filters": ["*string:~*req.request_type:TextPlainDryRun","*string:~*req.Msisdn:497700056231"],
"tenant": "cgrates.org",
"flags": ["*dryrun"],
"request_fields":[
],
"reply_fields":[
{"tag": "Allow", "field_id": "response.Allow", "type": "*constant",
"value": "1", "mandatory": true},
{"tag": "Concatenated1", "field_id": "response.Concatenated", "type": "*composed",
"value": "~*req.MCC;/", "mandatory": true},
{"tag": "Concatenated2", "field_id": "response.Concatenated", "type": "*composed",
"value": "Val1"},
{"tag": "MaxDuration", "field_id": "response.MaxDuration", "type": "*constant",
"value": "1200", "blocker": true},
{"tag": "Unused", "field_id": "response.Unused", "type": "*constant",
"value": "0"},
],
},
],
},
],

View File

@@ -125,6 +125,37 @@
}
],
},
{
"id": "conecto_textplain",
"url": "/conecto_textplain",
"sessions_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}
],
"request_payload": "*url",
"reply_payload": "*text_plain",
"request_processors": [
{
"id": "TextPlainDryRun",
"filters": ["*string:~*req.request_type:TextPlainDryRun","*string:~*req.Msisdn:497700056231"],
"tenant": "cgrates.org",
"flags": ["*dryrun"],
"request_fields":[
],
"reply_fields":[
{"tag": "Allow", "field_id": "response.Allow", "type": "*constant",
"value": "1", "mandatory": true},
{"tag": "Concatenated1", "field_id": "response.Concatenated", "type": "*composed",
"value": "~*req.MCC;/", "mandatory": true},
{"tag": "Concatenated2", "field_id": "response.Concatenated", "type": "*composed",
"value": "Val1"},
{"tag": "MaxDuration", "field_id": "response.MaxDuration", "type": "*constant",
"value": "1200", "blocker": true},
{"tag": "Unused", "field_id": "response.Unused", "type": "*constant",
"value": "0"},
],
},
],
},
],

View File

@@ -598,6 +598,7 @@ const (
MetaApier = "*apier"
CGREventString = "CGREvent"
MetaPing = "*ping"
MetaTextPlain = "*text_plain"
)
// Migrator Action