diff --git a/agents/httpagent_it_test.go b/agents/httpagent_it_test.go index a7345786c..505a2cba9 100644 --- a/agents/httpagent_it_test.go +++ b/agents/httpagent_it_test.go @@ -313,22 +313,21 @@ func testHAitTextPlain(t *testing.T) { 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", + reqUrl := fmt.Sprintf("%s://%s%s?request_type=TextPlainDryRun&CallID=123456&Msisdn=497700056231&Imsi=2343000000000123&Destination=491239440004", httpConst, addr, haCfg.HttpAgentCfg()[2].Url) rply, err := httpC.Get(reqUrl) if err != nil { t.Fatal(err) } - eXml := []byte(` - - 1 - 234/Val1 - 1200 -`) + response := []byte(`Variable1=Hola1 +Variable2=Hola2 +ComposedVar=TestComposed +Item1.1=Val2 +`) 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)) + } else if !reflect.DeepEqual(response, body) { + t.Errorf("expecting: \n<%s>\n, received: \n<%s>\n", string(response), string(body)) } rply.Body.Close() time.Sleep(time.Millisecond) diff --git a/agents/libhttpagent.go b/agents/libhttpagent.go index dfb31fa9e..5536b35b0 100644 --- a/agents/libhttpagent.go +++ b/agents/libhttpagent.go @@ -20,6 +20,7 @@ package agents import ( "encoding/xml" + "errors" "fmt" "io/ioutil" "net" @@ -257,14 +258,23 @@ type haTextPlainEncoder struct { // Encode implements httpAgentReplyEncoder func (xE *haTextPlainEncoder) Encode(nM *config.NavigableMap) (err error) { var str string + msgFields := make(map[string]string) // work around to NMap issue 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)) + if len(nmItms) == 0 { + continue } + cfgItm := nmItms[0] // first item gives some config for the rest, cannot iterate through NMItems since they are multipled by order + if len(cfgItm.Path) == 0 { + return errors.New("empty path in config item") + } + msgFields[strings.Join(cfgItm.Path, utils.NestingSep)] = utils.IfaceAsString(cfgItm.Data) + } + for key, val := range msgFields { + str += fmt.Sprintf("%s=%s\n", key, val) } _, err = xE.w.Write([]byte(str)) return diff --git a/config/config.go b/config/config.go index f1a3a5ca7..9d3d8f55c 100755 --- a/config/config.go +++ b/config/config.go @@ -632,7 +632,7 @@ func (self *CGRConfig) checkConfigSanity() error { return fmt.Errorf("<%s> unsupported request payload %s", utils.HTTPAgent, httpAgentCfg.RequestPayload) } - if !utils.IsSliceMember([]string{utils.MetaXml}, httpAgentCfg.ReplyPayload) { + if !utils.IsSliceMember([]string{utils.MetaXml, utils.MetaTextPlain}, httpAgentCfg.ReplyPayload) { return fmt.Errorf("<%s> unsupported reply payload %s", utils.HTTPAgent, httpAgentCfg.ReplyPayload) } diff --git a/data/conf/samples/httpagent/httpagent.json b/data/conf/samples/httpagent/httpagent.json index 11e19a3e4..a71dcd869 100644 --- a/data/conf/samples/httpagent/httpagent.json +++ b/data/conf/samples/httpagent/httpagent.json @@ -142,16 +142,18 @@ "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"}, + {"tag": "Field1", "field_id": "Variable1", "type": "*variable", + "value": "Hola1", "mandatory": true}, + {"tag": "Field2", "field_id": "Variable2", "type": "*variable", + "value": "Hola2", "mandatory": true}, + {"tag": "Field3", "field_id": "ComposedVar", "type": "*composed", + "value": "Test", "mandatory": true}, + {"tag": "Field4", "field_id": "ComposedVar", "type": "*composed", + "value": "Composed", "mandatory": true}, + {"tag": "Field5", "field_id": "Item1.1", "type": "*constant", + "value": "Val1", "mandatory": true}, + {"tag": "Field6", "field_id": "Item1.1", "type": "*constant", + "value": "Val2", "mandatory": true}, ], }, ], diff --git a/data/conf/samples/httpagenttls/httpagent.json b/data/conf/samples/httpagenttls/httpagent.json index 3ca9d29e1..bddc9950d 100755 --- a/data/conf/samples/httpagenttls/httpagent.json +++ b/data/conf/samples/httpagenttls/httpagent.json @@ -142,16 +142,18 @@ "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"}, + {"tag": "Field1", "field_id": "Variable1", "type": "*variable", + "value": "Hola1", "mandatory": true}, + {"tag": "Field2", "field_id": "Variable2", "type": "*variable", + "value": "Hola2", "mandatory": true}, + {"tag": "Field3", "field_id": "ComposedVar", "type": "*composed", + "value": "Test", "mandatory": true}, + {"tag": "Field4", "field_id": "ComposedVar", "type": "*composed", + "value": "Composed", "mandatory": true}, + {"tag": "Field5", "field_id": "Item1.1", "type": "*constant", + "value": "Val1", "mandatory": true}, + {"tag": "Field6", "field_id": "Item1.1", "type": "*constant", + "value": "Val2", "mandatory": true}, ], }, ],