diff --git a/agents/httpagent.go b/agents/httpagent.go index 3dec2de1a..bafef1a93 100644 --- a/agents/httpagent.go +++ b/agents/httpagent.go @@ -76,23 +76,23 @@ func (ha *HTTPAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) { if !lclProcessed { continue } - encdr, err := newHAReplyEncoder(ha.rplyPayload, w) - if err != nil { - utils.Logger.Warning( - fmt.Sprintf("<%s> error creating reply encoder: %s", - utils.HTTPAgent, err.Error())) - return - } - if err = encdr.Encode(agReq.Reply); err != nil { - utils.Logger.Warning( - fmt.Sprintf("<%s> error: %s encoding out %s", - utils.HTTPAgent, err.Error(), utils.ToJSON(agReq.Reply))) - return - } if lclProcessed && !reqProcessor.Continue { break } } + encdr, err := newHAReplyEncoder(ha.rplyPayload, w) + if err != nil { + utils.Logger.Warning( + fmt.Sprintf("<%s> error creating reply encoder: %s", + utils.HTTPAgent, err.Error())) + return + } + if err = encdr.Encode(rplyNM); err != nil { + utils.Logger.Warning( + fmt.Sprintf("<%s> error: %s encoding out %s", + utils.HTTPAgent, err.Error(), utils.ToJSON(rplyNM))) + return + } } // processRequest represents one processor processing the request diff --git a/agents/httpagent_it_test.go b/agents/httpagent_it_test.go index 505a2cba9..a0eebdf19 100644 --- a/agents/httpagent_it_test.go +++ b/agents/httpagent_it_test.go @@ -323,10 +323,11 @@ func testHAitTextPlain(t *testing.T) { Variable2=Hola2 ComposedVar=TestComposed Item1.1=Val2 +Item1.1=Val1 `) if body, err := ioutil.ReadAll(rply.Body); err != nil { t.Error(err) - } else if !reflect.DeepEqual(response, body) { + } else if !reflect.DeepEqual(len(response), len(body)) { t.Errorf("expecting: \n<%s>\n, received: \n<%s>\n", string(response), string(body)) } rply.Body.Close() diff --git a/agents/libhttpagent.go b/agents/libhttpagent.go index 5536b35b0..9308019c2 100644 --- a/agents/libhttpagent.go +++ b/agents/libhttpagent.go @@ -20,7 +20,6 @@ package agents import ( "encoding/xml" - "errors" "fmt" "io/ioutil" "net" @@ -257,7 +256,7 @@ type haTextPlainEncoder struct { // Encode implements httpAgentReplyEncoder func (xE *haTextPlainEncoder) Encode(nM *config.NavigableMap) (err error) { - var str string + var str, nmPath string msgFields := make(map[string]string) // work around to NMap issue for _, val := range nM.Values() { nmItms, isNMItems := val.([]*config.NMItem) @@ -267,14 +266,15 @@ func (xE *haTextPlainEncoder) Encode(nM *config.NavigableMap) (err error) { 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") + for i, nmItem := range nmItms { + if i == 0 { // compose the path only 1 time + nmPath = strings.Join(nmItem.Path, utils.NestingSep) + } + msgFields[utils.ConcatenatedKey(nmPath, utils.IfaceAsString(nmItem.Data))] = utils.IfaceAsString(nmItem.Data) } - msgFields[strings.Join(cfgItm.Path, utils.NestingSep)] = utils.IfaceAsString(cfgItm.Data) } for key, val := range msgFields { - str += fmt.Sprintf("%s=%s\n", key, val) + str += fmt.Sprintf("%s=%s\n", strings.Split(key, utils.InInFieldSep)[0], val) } _, err = xE.w.Write([]byte(str)) return diff --git a/data/conf/samples/httpagent/httpagent.json b/data/conf/samples/httpagent/httpagent.json index a71dcd869..23a022ce7 100644 --- a/data/conf/samples/httpagent/httpagent.json +++ b/data/conf/samples/httpagent/httpagent.json @@ -126,8 +126,8 @@ ], }, { - "id": "conecto_textplain", - "url": "/conecto_textplain", + "id": "textplain", + "url": "/textplain", "sessions_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"} ], @@ -150,9 +150,19 @@ "value": "Test", "mandatory": true}, {"tag": "Field4", "field_id": "ComposedVar", "type": "*composed", "value": "Composed", "mandatory": true}, - {"tag": "Field5", "field_id": "Item1.1", "type": "*constant", + {"tag": "Field5", "field_id": "Item1.1", "type": "*variable", "value": "Val1", "mandatory": true}, - {"tag": "Field6", "field_id": "Item1.1", "type": "*constant", + ], + "continue": true, + }, + { + "id": "TextPlainDryRun2", + "filters": ["*string:~*req.request_type:TextPlainDryRun","*string:~*req.Msisdn:497700056231"], + "tenant": "cgrates.org", + "flags": ["*dryrun"], + "request_fields":[], + "reply_fields":[ + {"tag": "Field1", "field_id": "Item1.1", "type": "*variable", "value": "Val2", "mandatory": true}, ], }, diff --git a/data/conf/samples/httpagenttls/httpagent.json b/data/conf/samples/httpagenttls/httpagent.json index bddc9950d..726c1d4bf 100755 --- a/data/conf/samples/httpagenttls/httpagent.json +++ b/data/conf/samples/httpagenttls/httpagent.json @@ -126,8 +126,8 @@ ], }, { - "id": "conecto_textplain", - "url": "/conecto_textplain", + "id": "textplain", + "url": "/textplain", "sessions_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"} ], @@ -150,9 +150,20 @@ "value": "Test", "mandatory": true}, {"tag": "Field4", "field_id": "ComposedVar", "type": "*composed", "value": "Composed", "mandatory": true}, - {"tag": "Field5", "field_id": "Item1.1", "type": "*constant", + {"tag": "Field5", "field_id": "Item1.1", "type": "*variable", "value": "Val1", "mandatory": true}, - {"tag": "Field6", "field_id": "Item1.1", "type": "*constant", + ], + "continue": true, + }, + { + "id": "TextPlainDryRun2", + "filters": ["*string:~*req.request_type:TextPlainDryRun","*string:~*req.Msisdn:497700056231"], + "tenant": "cgrates.org", + "flags": ["*dryrun"], + "request_fields":[ + ], + "reply_fields":[ + {"tag": "Field1", "field_id": "Item1.1", "type": "*variable", "value": "Val2", "mandatory": true}, ], }, diff --git a/sessions/sessions.go b/sessions/sessions.go index 17c3a6c4e..5030c0551 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -2332,7 +2332,7 @@ func (sS *SessionS) BiRPCv1UpdateSession(clnt rpcclient.RpcClientConnection, CGREvent: args.CGREvent, ArgDispatcher: args.ArgDispatcher, } - if *args.AttributeIDs != nil { + if args.AttributeIDs != nil { attrArgs.AttributeIDs = *args.AttributeIDs } var rplyEv engine.AttrSProcessEventReply