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];
}
}
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();
}
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()]);
}
Aggregations