Search in sources :

Example 6 with GroupedAvpImpl

use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl in project jain-slee.diameter by RestComm.

the class AvpUtilities method performPreAddOperations.

/**
 * @param parent the Message/Grouped AVP where AVP will be added to, for validation purposes. if null, no validation is performed.
 * @param avpCode
 * @param vendorId
 * @param set
 * @throws AvpNotAllowedException
 */
private static void performPreAddOperations(Object parent, int avpCode, long vendorId, AvpSet set) throws AvpNotAllowedException {
    if (!dictionary.isEnabled()) {
        // no need to proceed any further.. no validation
        return;
    }
    if (parent instanceof Message) {
        Message msg = (Message) parent;
        MessageRepresentation msgRep = dictionary.getMessage(msg.getCommandCode(), msg.getApplicationId(), msg.isRequest());
        // if we don't know anything about this message, let's just move on..
        if (msgRep == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Unable to find message in dictionary, skipping validation. (Command Code: " + msg.getCommandCode() + ", Application-Id: " + msg.getApplicationId() + ")");
            }
            return;
        }
        if (!msgRep.isAllowed(avpCode, vendorId)) {
            throw new AvpNotAllowedException("Avp defined by code: " + avpCode + ", vendorId: " + vendorId + " is not allowed in message - code: " + msg.getCommandCode() + ", appId: " + msg.getApplicationId() + ", isRequest: " + msg.isRequest(), avpCode, vendorId);
        }
        if (msgRep.isCountValidForMultiplicity(msg.getAvps(), avpCode, vendorId, 1)) {
            // its ok.
            return;
        } else {
            throw new AvpNotAllowedException("Avp not allowed, count exceeded.", avpCode, vendorId);
        }
    } else if (parent instanceof GroupedAvp) {
        GroupedAvpImpl gAvp = (GroupedAvpImpl) parent;
        org.jdiameter.api.validation.AvpRepresentation parentAvpRep = dictionary.getAvp(gAvp.getCode(), gAvp.getVendorId());
        // if we don't know anything about this avp, let's just move on..
        if (parentAvpRep == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Unable to find parent AVP in dictionary, skipping validation. (AVP Code: " + gAvp.getCode() + ", Vendor-Id: " + gAvp.getVendorId() + ")");
            }
            return;
        }
        if (!parentAvpRep.isAllowed(avpCode, vendorId)) {
            throw new AvpNotAllowedException("AVP with Code '" + avpCode + "' and Vendor-Id '" + vendorId + "' is not allowed as a child of AVP with Code '" + parentAvpRep.getCode() + "' and Vendor-Id '" + parentAvpRep.getVendorId() + "'.", avpCode, vendorId);
        }
        // Now we get the actual AVP to add representation...
        org.jdiameter.api.validation.AvpRepresentation avpRep = dictionary.getAvp(avpCode, vendorId);
        // ..to check if it can be added (multiplicity) to the parent.
        if (avpRep.isCountValidForMultiplicity(gAvp.getGenericData(), 1)) {
            // its ok.
            return;
        } else {
            throw new AvpNotAllowedException("Avp not allowed, count exceeded.", avpCode, vendorId);
        }
    }
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) Message(org.jdiameter.api.Message) MessageRepresentation(org.jdiameter.api.validation.MessageRepresentation) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Aggregations

GroupedAvpImpl (org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl)6 ArrayList (java.util.ArrayList)2 AvpRepresentation (org.mobicents.diameter.dictionary.AvpRepresentation)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)1 FailedAvp (net.java.slee.resource.diameter.base.events.avp.FailedAvp)1 ProxyInfoAvp (net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp)1 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)1 Avp (org.jdiameter.api.Avp)1 Message (org.jdiameter.api.Message)1 AvpRepresentation (org.jdiameter.api.validation.AvpRepresentation)1 Dictionary (org.jdiameter.api.validation.Dictionary)1 MessageRepresentation (org.jdiameter.api.validation.MessageRepresentation)1 DiameterAvpImpl (org.mobicents.slee.resource.diameter.base.events.avp.DiameterAvpImpl)1