Search in sources :

Example 41 with AvpSet

use of org.jdiameter.api.AvpSet in project jain-slee.diameter by RestComm.

the class GroupedAvpImpl method getExtensionAvpsInternal.

private DiameterAvp[] getExtensionAvpsInternal(AvpSet set) throws Exception {
    List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
    for (Avp a : set) {
        AvpRepresentation avpRep = AvpDictionary.INSTANCE.getAvp(a.getCode(), a.getVendorId());
        if (avpRep != null) {
            if (avpRep.isGrouped()) {
                // warning, this changes getRaw to return byte[0] if successful
                AvpSet grouped = a.getGrouped();
                GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
                gAVP.setExtensionAvps(getExtensionAvpsInternal(grouped));
                avps.add(gAVP);
            } else {
                avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw(), DiameterAvpType.fromString(avpRep.getType())));
            }
        } else {
            // we don't have it in dictionary
            try {
                // warning, this changes getRaw to return byte[0] if successful
                AvpSet grouped = a.getGrouped();
                GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw());
                gAVP.setExtensionAvps(getExtensionAvpsInternal(grouped));
                avps.add(gAVP);
            } catch (AvpDataException ade) {
                avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), a.isMandatory() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.isEncrypted() ? DiameterAvp.FLAG_RULE_MUST : DiameterAvp.FLAG_RULE_MUSTNOT, a.getRaw(), null));
            }
        }
    }
    return avps.toArray(new DiameterAvp[avps.size()]);
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Example 42 with AvpSet

use of org.jdiameter.api.AvpSet in project jain-slee.diameter by RestComm.

the class GxMessageFactoryImpl method addAvp.

protected void addAvp(final DiameterAvp avp, final AvpSet set) {
    // FIXME: alexandre: Should we look at the types and add them with proper function?
    if (avp instanceof GroupedAvp) {
        final AvpSet avpSet = set.addGroupedAvp(avp.getCode(), avp.getVendorId(), avp.getMandatoryRule() == 1, avp.getProtectedRule() == 1);
        final DiameterAvp[] groupedAVPs = ((GroupedAvp) avp).getExtensionAvps();
        for (DiameterAvp avpFromGroup : groupedAVPs) {
            addAvp(avpFromGroup, avpSet);
        }
    } else if (avp != null) {
        set.addAvp(avp.getCode(), avp.byteArrayValue(), avp.getVendorId(), avp.getMandatoryRule() == 1, avp.getProtectedRule() == 1);
    }
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpSet(org.jdiameter.api.AvpSet)

Example 43 with AvpSet

use of org.jdiameter.api.AvpSet in project jain-slee.diameter by RestComm.

the class GxMessageFactoryImpl method createGxMessage.

public Message createGxMessage(final DiameterHeader header, final DiameterAvp[] avps, int commandCode) throws AvpNotAllowedException {
    final Message msg = createRawMessage(header, commandCode);
    final AvpSet set = msg.getAvps();
    for (DiameterAvp avp : avps) {
        addAvp(avp, set);
    }
    return msg;
}
Also used : Message(org.jdiameter.api.Message) GxCreditControlMessage(net.java.slee.resource.diameter.gx.events.GxCreditControlMessage) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) GxReAuthMessage(net.java.slee.resource.diameter.gx.events.GxReAuthMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpSet(org.jdiameter.api.AvpSet)

Example 44 with AvpSet

use of org.jdiameter.api.AvpSet in project jain-slee.diameter by RestComm.

the class GqMessageFactoryImpl method addAvp.

protected void addAvp(DiameterAvp avp, AvpSet set) {
    if (avp instanceof GroupedAvp) {
        AvpSet avpSet = set.addGroupedAvp(avp.getCode(), avp.getVendorId(), avp.getMandatoryRule() == 1, avp.getProtectedRule() == 1);
        DiameterAvp[] groupedAVPs = ((GroupedAvp) avp).getExtensionAvps();
        for (DiameterAvp avpFromGroup : groupedAVPs) {
            addAvp(avpFromGroup, avpSet);
        }
    } else if (avp != null) {
        set.addAvp(avp.getCode(), avp.byteArrayValue(), avp.getVendorId(), avp.getMandatoryRule() == 1, avp.getProtectedRule() == 1);
    }
}
Also used : GroupedAvp(net.java.slee.resource.diameter.base.events.avp.GroupedAvp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpSet(org.jdiameter.api.AvpSet)

Example 45 with AvpSet

use of org.jdiameter.api.AvpSet in project jain-slee.diameter by RestComm.

the class GqMessageFactoryImpl method createMessage.

public Message createMessage(DiameterHeader header, DiameterAvp[] avps) throws AvpNotAllowedException {
    Message msg = createRawMessage(header);
    AvpSet set = msg.getAvps();
    for (DiameterAvp avp : avps) {
        addAvp(avp, set);
    }
    return msg;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpSet(org.jdiameter.api.AvpSet)

Aggregations

AvpSet (org.jdiameter.api.AvpSet)48 Avp (org.jdiameter.api.Avp)30 AvpDataException (org.jdiameter.api.AvpDataException)26 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)20 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)10 Message (org.jdiameter.api.Message)8 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 URISyntaxException (java.net.URISyntaxException)4 ParseException (org.jdiameter.client.api.parser.ParseException)4 ArrayList (java.util.ArrayList)3 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)3 AvpRepresentation (org.mobicents.diameter.dictionary.AvpRepresentation)3 Constructor (java.lang.reflect.Constructor)2 Date (java.util.Date)2 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)2 IllegalDiameterStateException (org.jdiameter.api.IllegalDiameterStateException)2 InternalException (org.jdiameter.api.InternalException)2 AvpRepresentation (org.jdiameter.api.validation.AvpRepresentation)2 ExperimentalResultAvp (net.java.slee.resource.diameter.base.events.avp.ExperimentalResultAvp)1