HTTPAgent correctly append the same FieldPath with different processor and correcly access in SessionS AttributeIDs

This commit is contained in:
TeoV
2019-07-09 15:42:45 +03:00
committed by Dan Christian Bogos
parent fc45b4f7b9
commit 3e6d01a638
6 changed files with 52 additions and 30 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -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},
],
},

View File

@@ -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},
],
},

View File

@@ -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