use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl in project jain-slee.diameter by RestComm.
the class DiameterAvpFactoryImpl method createAvp.
/*
* (non-Javadoc)
* @see net.java.slee.resource.diameter.base.DiameterAvpFactory#createAvp(int, int, net.java.slee.resource.diameter.base.events.avp.DiameterAvp[])
*/
public DiameterAvp createAvp(int vendorId, int avpCode, DiameterAvp[] avps) throws NoSuchAvpException, AvpNotAllowedException {
GroupedAvpImpl avp = (GroupedAvpImpl) AvpUtilities.createAvp(avpCode, vendorId, GroupedAvpImpl.class);
avp.setExtensionAvps(avps);
return avp;
}
use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl in project jain-slee.diameter by RestComm.
the class AvpUtilities method createAvp.
/*
* (non-Javadoc)
* @see net.java.slee.resource.diameter.base.DiameterAvpFactory#createAvp(int, int, net.java.slee.resource.diameter.base.events.avp.DiameterAvp[])
*/
public static DiameterAvp createAvp(int avpCode, long vendorId, DiameterAvp[] avps) throws AvpNotAllowedException {
GroupedAvpImpl avp = (GroupedAvpImpl) AvpUtilities.createAvp(avpCode, vendorId, GroupedAvpImpl.class);
avp.setExtensionAvps(avps);
return avp;
}
use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl in project jain-slee.diameter by RestComm.
the class DiameterMessageImpl method getAvpsInternal.
// ===== AVP Management =====
private DiameterAvp[] getAvpsInternal(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) {
// log.error("Avp with code: " + a.getCode() + " VendorId: " + a.getVendorId() + " is not listed in dictionary, skipping!");
continue;
} else {
if (avpRep.getType().equals("Grouped")) {
// TODO: There's no info about if AVP has mandatory or protected flags set...
GroupedAvpImpl gAVP = new GroupedAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw());
gAVP.setExtensionAvps(getAvpsInternal(a.getGrouped()));
// This is a grouped AVP... let's make it like that.
avps.add(gAVP);
} else {
// TODO: There's no info about if AVP has mandatory or protected flags set...
avps.add(new DiameterAvpImpl(a.getCode(), a.getVendorId(), avpRep.getRuleMandatoryAsInt(), avpRep.getRuleProtectedAsInt(), a.getRaw(), DiameterAvpType.fromString(avpRep.getType())));
}
}
}
return avps.toArray(new DiameterAvp[avps.size()]);
}
use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl in project jain-slee.diameter by RestComm.
the class AvpAssistant method testMethods.
public int testMethods(DiameterAvp avp, Class<?> interfaze) throws Exception {
System.out.println(":::::::: Testing accessors for Class " + avp.getClass().getSimpleName() + " ::::::::");
int nFailures = 0;
for (Method m : interfaze.getMethods()) {
// clearAVPsInMessage(message);
// int commandCode = message.getCommand().getCode();
String methodName = m.getName();
if (AvpAssistant.methodsToIgnore.contains(methodName)) {
continue;
} else if (methodName.startsWith("get")) {
Class<?> avpType = m.getReturnType();
Object toGo = AvpAssistant.getValueFromEnumerated(avpType);
if (toGo == null)
toGo = AvpAssistant.getValueFromClass(avpType);
if (toGo != null) {
Method hasser = null;
try {
hasser = interfaze.getMethod(getSingularMethodName(methodName.replaceFirst("get", "has")));
Object hasAvpBeforeSet = hasser.invoke(avp);
Assert.assertFalse("Message already has value before setting for " + methodName.replaceAll("get", "") + "... aborting", (Boolean) hasAvpBeforeSet);
} catch (NoSuchMethodException e) {
// skip it...
}
Method setter = interfaze.getMethod(methodName.replaceFirst("g", "s"), avpType);
// System.out.println("Setting value " + setter.getName() +"(" + toGo.toString() +")");
setter.invoke(avp, toGo);
if (hasser != null) {
Object hasAvpAfterSet = hasser.invoke(avp);
Assert.assertTrue("Message does not has value after setting for " + methodName.replaceAll("get", "") + "... aborting", (Boolean) hasAvpAfterSet);
}
// System.out.println("Current message: \r\n" + snr);
Object obtained = m.invoke(avp);
// System.out.println("Got value " + obtained.toString());
boolean passed = false;
try {
if (avpType == byte[].class) {
passed = Arrays.equals((byte[]) toGo, (byte[]) obtained);
} else if (avpType == long[].class) {
passed = Arrays.equals((long[]) toGo, (long[]) obtained);
} else {
passed = (avpType.isArray() ? Arrays.equals((Object[]) toGo, (Object[]) obtained) : obtained.equals(toGo));
}
} catch (Exception e) {
e.printStackTrace();
// ignore... we fail!
}
// Validate AVP Flags
ArrayList<String> failedAvpFlags = checkAvpFlags(((GroupedAvpImpl) avp).getGenericData());
if (failedAvpFlags.size() > 0) {
System.err.println("The following AVPs flags have failed to check against dictionary:");
for (String failedAvpFlag : failedAvpFlags) {
System.err.println(failedAvpFlag);
}
Assert.fail(failedAvpFlags.toString());
}
nFailures = passed ? nFailures : nFailures + 1;
System.out.println("[" + (passed ? "PASSED" : "FAILED") + "] " + methodName.replace("get", "") + " with param of type '" + avpType.getName() + "' " + (hasser != null ? " WITH has" : " WITHOUT has"));
} else {
System.out.println("[??????] Unable to test " + methodName.replace("get", "") + " with param of type '" + avpType.getName() + "'.");
Assert.fail("Missing AVP Implementation class to test " + methodName);
}
}
}
return nFailures;
}
use of org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl 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());
}
}
}
}
Aggregations