Search in sources :

Example 1 with GroupedAvpImpl

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;
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl)

Example 2 with GroupedAvpImpl

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;
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl)

Example 3 with GroupedAvpImpl

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()]);
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) DiameterAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.DiameterAvpImpl) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) 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) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Example 4 with GroupedAvpImpl

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;
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with GroupedAvpImpl

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

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