Search in sources :

Example 1 with Dictionary

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

the class ValidatorImpl method validate.

// NOTE: this class possibly should be Singleton, however some impl may use something more to perform validation
// hence, its not static, each RA provides instance through RA Sbb Interface.
/*
   * (non-Javadoc)
   * 
   * @see
   * net.java.slee.resource.diameter.Validator#validate(net.java.slee.resource
   * .diameter.base.events.DiameterMessage)
   */
@Override
public void validate(DiameterMessage msg) throws AvpNotAllowedException {
    Dictionary dictionary = DictionarySingleton.getDictionary();
    if (dictionary.isConfigured() && dictionary.isEnabled()) {
        DiameterCommand com = msg.getCommand();
        MessageRepresentation rep = dictionary.getMessage(com.getCode(), com.getApplicationId(), com.isRequest());
        if (rep != null) {
            DiameterMessageImpl impl = (DiameterMessageImpl) msg;
            try {
                rep.validate(impl.getGenericData(), ValidatorLevel.ALL);
            } catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
                throw new AvpNotAllowedException("Failed to validate message.", e, e.getAvpCode(), e.getVendorId());
            }
        }
    }
}
Also used : DiameterCommand(net.java.slee.resource.diameter.base.events.DiameterCommand) Dictionary(org.jdiameter.api.validation.Dictionary) MessageRepresentation(org.jdiameter.api.validation.MessageRepresentation) DiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)

Example 2 with Dictionary

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

the class ValidatorImpl method validate.

/*
   * (non-Javadoc)
   * 
   * @see net.java.slee.resource.diameter.Validator#
   * validate(net.java.slee.resource.diameter.base.events.avp.DiameterAvp)
   */
@Override
public void validate(DiameterAvp avp) throws AvpNotAllowedException {
    Dictionary dictionary = DictionarySingleton.getDictionary();
    if (dictionary.isConfigured() && dictionary.isEnabled()) {
        AvpRepresentation rep = dictionary.getAvp(avp.getCode(), avp.getVendorId());
        // check for grouped?
        if (rep != null && rep.isGrouped()) {
            try {
                GroupedAvpImpl impl = (GroupedAvpImpl) avp;
                rep.validate(impl.getGenericData());
            } catch (ClassCastException cce) {
                throw new AvpNotAllowedException("Failed to validate avp, its not grouped!", cce, avp.getCode(), avp.getVendorId());
            }
        }
    }
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) Dictionary(org.jdiameter.api.validation.Dictionary) AvpRepresentation(org.jdiameter.api.validation.AvpRepresentation) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)

Aggregations

AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)2 Dictionary (org.jdiameter.api.validation.Dictionary)2 DiameterCommand (net.java.slee.resource.diameter.base.events.DiameterCommand)1 AvpRepresentation (org.jdiameter.api.validation.AvpRepresentation)1 MessageRepresentation (org.jdiameter.api.validation.MessageRepresentation)1 DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)1 GroupedAvpImpl (org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl)1