Search in sources :

Example 21 with AvpDataException

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

the class AvpUtilities method getAvpsAsTime.

public static Date[] getAvpsAsTime(int avpCode, AvpSet set) {
    try {
        AvpSet avpSet = set.getAvps(avpCode);
        Date[] values = new Date[avpSet.size()];
        int i = 0;
        for (Avp avp : avpSet) {
            values[i++] = avp.getTime();
        }
        return values;
    } catch (AvpDataException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to obtain AVP with code " + avpCode + " as type Float64.", e);
        }
        return new Date[0];
    }
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) AvpSet(org.jdiameter.api.AvpSet) Avp(org.jdiameter.api.Avp) Date(java.util.Date)

Example 22 with AvpDataException

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

the class DiameterMessageImpl method printAvp.

private String printAvp(Avp avp, String indent) {
    Object avpValue = null;
    StringBuilder avpStringSB = new StringBuilder();
    boolean isGrouped = false;
    try {
        String avpType = AvpDictionary.INSTANCE.getAvp(avp.getCode(), avp.getVendorId()).getType();
        if ("Integer32".equals(avpType) || "AppId".equals(avpType)) {
            avpValue = avp.getInteger32();
        } else if ("Unsigned32".equals(avpType) || "VendorId".equals(avpType)) {
            avpValue = avp.getUnsigned32();
        } else if ("Float64".equals(avpType)) {
            avpValue = avp.getFloat64();
        } else if ("Integer64".equals(avpType)) {
            avpValue = avp.getInteger64();
        } else if ("Time".equals(avpType)) {
            avpValue = avp.getTime();
        } else if ("Unsigned64".equals(avpType)) {
            avpValue = avp.getUnsigned64();
        } else if ("Grouped".equals(avpType)) {
            avpValue = "<Grouped>";
            isGrouped = true;
        } else {
            avpValue = avp.getUTF8String().replaceAll("\r", "").replaceAll("\n", "");
        }
    } catch (Exception ignore) {
        try {
            avpValue = avp.getUTF8String().replaceAll("\r", "").replaceAll("\n", "");
        } catch (AvpDataException e) {
            avpValue = avp.toString();
        }
    }
    avpStringSB.append("| ").append(indent).append("AVP: Code[").append(avp.getCode()).append("] VendorID[").append(avp.getVendorId()).append("] Value[").append(avpValue).append("] Flags[V=").append(avp.isVendorId()).append(";M=").append(avp.isMandatory()).append(";P=").append(avp.isEncrypted()).append("]\r\n");
    if (isGrouped) {
        try {
            for (Avp subAvp : avp.getGrouped()) {
                avpStringSB.append(printAvp(subAvp, indent + "  "));
            }
        } catch (AvpDataException e) {
        // Failed to ungroup... ignore then...
        }
    }
    return avpStringSB.toString();
}
Also used : AvpDataException(org.jdiameter.api.AvpDataException) VendorSpecificApplicationIdAvp(net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp) Avp(org.jdiameter.api.Avp) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ProxyInfoAvp(net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp) FailedAvp(net.java.slee.resource.diameter.base.events.avp.FailedAvp) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) AvpDataException(org.jdiameter.api.AvpDataException)

Example 23 with AvpDataException

use of org.jdiameter.api.AvpDataException 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)

Aggregations

Avp (org.jdiameter.api.Avp)23 AvpDataException (org.jdiameter.api.AvpDataException)23 AvpSet (org.jdiameter.api.AvpSet)22 Date (java.util.Date)2 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)2 ArrayList (java.util.ArrayList)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 FailedAvp (net.java.slee.resource.diameter.base.events.avp.FailedAvp)1 GroupedAvp (net.java.slee.resource.diameter.base.events.avp.GroupedAvp)1 ProxyInfoAvp (net.java.slee.resource.diameter.base.events.avp.ProxyInfoAvp)1 VendorSpecificApplicationIdAvp (net.java.slee.resource.diameter.base.events.avp.VendorSpecificApplicationIdAvp)1 AvpRepresentation (org.mobicents.diameter.dictionary.AvpRepresentation)1