@Override public Answer createAnswer(long vendorId, long experimentalResultCode) { MessageImpl answer = new MessageImpl(this); try { AvpSet exp_code = answer.getAvps().addGroupedAvp(297, true, false); exp_code.addAvp(Avp.VENDOR_ID, vendorId, true, false, true); exp_code.addAvp(Avp.EXPERIMENTAL_RESULT_CODE, experimentalResultCode, true, false, true); } catch (Exception e) { logger.debug("Can not create answer message", e); } answer.setRequest(false); return answer; }
/** * Create error answer message with Experemental-Result-Code Avp * @param vendorId vendor id * @return error answer message with Experemental-Result-Code Avp */ public IMessage toMessage(int vendorId) { if ( errorMessage != null && errorMessage.getAvps().getAvp(297) == null ) { // EXPERIMENTAL_RESULT = 297 AvpSet er = errorMessage.getAvps().addGroupedAvp(297); er.addAvp(Avp.VENDOR_ID, vendorId); er.addAvp(Avp.EXPERIMENTAL_RESULT_CODE, code); } return errorMessage; } }
public static byte[][] getAvpsAsOctetString(int avpCode, AvpSet set) { try { AvpSet avpSet = set.getAvps(avpCode); byte[][] values = new byte[avpSet.size()][]; int i = 0; for(Avp avp : avpSet) { values[i++] = avp.getOctetString(); } return values; } catch (AvpDataException e) { if(logger.isDebugEnabled()) { logger.debug("Failed to obtain AVP with code " + avpCode + " as type OctetString.", e); } return new byte[0][]; } }
public static byte[] getAvpAsOctetString(int avpCode, AvpSet set) { try { Avp avp = set.getAvp(avpCode); return avp != null ? avp.getOctetString() : null; } catch (AvpDataException e) { if(logger.isDebugEnabled()) { logger.debug("Failed to obtain AVP with code " + avpCode + " as type OctetString.", e); } return null; } }
/** * Method for removing AVP with given code. * * @param avpCode the code of the AVP to be removed * @param set the AvpSet to remove the AVP from */ public static void removeAvp(int avpCode, AvpSet set) { set.removeAvp(avpCode); }
@Override public AvpSet getAvps(int avpCode) { AvpSet result = new AvpSetImpl(); for (Avp avp : this.avps) { if (avp.getCode() == avpCode) { result.addAvp(avp); } } return result; }
protected void fillIPAddressTable(IMessage message) { AvpSet avps = message.getAvps().getAvps(HOST_IP_ADDRESS); if (avps != null) { ArrayList<InetAddress> t = new ArrayList<InetAddress>(); for (int i = 0; i < avps.size(); i++) { try { t.add(avps.getAvpByIndex(i).getAddress()); } catch (AvpDataException e) { logger.warn("Unable to retrieve IP Address from Host-IP-Address AVP"); } } addresses = t.toArray(new InetAddress[t.size()]); } }
public static float getAvpAsFloat32(int avpCode, long vendorId, AvpSet set) { try { Avp avp = set.getAvp(avpCode, vendorId); return avp != null ? avp.getFloat32() : Float.MIN_VALUE; } catch (AvpDataException e) { if(logger.isDebugEnabled()) { logger.debug("Failed to obtain AVP with code " + avpCode + " and Vendor-Id " + vendorId + " as type Float32.", e); } return Float.MIN_VALUE; } }
/** * Method for removing AVP with given code. * * @param avpCode the code of the AVP to be removed * @param set the AvpSet to remove the AVP from */ public static void removeAvp(int avpCode, AvpSet set) { set.removeAvp(avpCode); }
public AccountAnswerImpl(Request request, int accountRecordType, int accReqNumber, long resultCode) { this(request.createAnswer(resultCode)); try { getMessage().getAvps().addAvp(Avp.ACC_RECORD_TYPE, accountRecordType); getMessage().getAvps().addAvp(Avp.ACC_RECORD_NUMBER, accReqNumber); } catch (Exception e) { throw new IllegalArgumentException(e); } }
public static String[] getAvpsAsUTF8String(int avpCode, AvpSet set) { try { AvpSet avpSet = set.getAvps(avpCode); String[] values = new String[avpSet.size()]; int i = 0; for(Avp avp : avpSet) { values[i++] = avp.getUTF8String(); } return values; } catch (AvpDataException e) { if(logger.isDebugEnabled()) { logger.debug("Failed to obtain AVP with code " + avpCode + " as type UTF8String.", e); } return new String[0]; } }
@Override public void validate(AvpSet avpSet) throws AvpNotAllowedException { //this is used in RAs, cause ... AvpSet is asexual AVP, no code, no vendor // let it rip for (AvpRepresentation childrenVAvp : getChildren()) { AvpSet childSset = avpSet.getAvps(childrenVAvp.getCode(), childrenVAvp.getVendorId()); int count = childSset.size(); if (!childrenVAvp.isCountValidForMultiplicity(count)) { throw new AvpNotAllowedException("AVP: " + childrenVAvp + " has wrong count, in grouped parent avp - " + (count) + ", allowed: " + childrenVAvp.getMultiplicityIndicator(), getCode(), getVendorId()); } if (childrenVAvp.isGrouped()) { for (int index = 0; index < childSset.size(); index++) { Avp presumablyGrouped = childSset.getAvpByIndex(index); childrenVAvp.validate(presumablyGrouped); } } // else we are good ? } }
/** * Adds AVP to {@link AvpSet} as Grouped with the given code and given Vendor-Id plus defined mandatory and protected flags. * * @param parent the Message/Grouped AVP where AVP will be added to, for validation purposes. if null, no validation is performed. * @param avpCode the code of the AVP * @param vendorId the Vendor-Id of the AVP * @param set the AvpSet to add AVP * @param isMandatory the value for the mandatory bit * @param isProtected the value for the protected bit * @param childs the value of the AVP to add */ public static AvpSet setAvpAsGrouped(Object parent, int avpCode, long vendorId, AvpSet set, boolean isMandatory, boolean isProtected, DiameterAvp[] childs) { performPreAddOperations(parent, avpCode, vendorId, set); AvpSet grouped = set.addGroupedAvp(avpCode, vendorId, isMandatory, isProtected); for (DiameterAvp child : childs) { grouped.addAvp(child.getCode(), child.byteArrayValue(), child.getVendorId(), child.getMandatoryRule() != DiameterAvp.FLAG_RULE_MUSTNOT, child.getProtectedRule() == DiameterAvp.FLAG_RULE_MUST); } return grouped; }
public static double getAvpAsFloat64(int avpCode, AvpSet set) { try { Avp avp = set.getAvp(avpCode); return avp != null ? avp.getFloat64() : Double.MIN_VALUE; } catch (AvpDataException e) { if(logger.isDebugEnabled()) { logger.debug("Failed to obtain AVP with code " + avpCode + " as type Float64.", e); } return Double.MIN_VALUE; } }