use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class AccountingServerSessionActivityImpl method createAccountingAnswer.
public AccountingAnswer createAccountingAnswer(AccountingRequest request) {
try {
// Get the impl
DiameterMessageImpl implRequest = (DiameterMessageImpl) request;
// Extract interesting AVPs
ArrayList<DiameterAvp> copyAvps = new ArrayList<DiameterAvp>();
copyAvps.add(avpFactory.createAvp(Avp.SESSION_ID, serverSession.getSessions().get(0).getSessionId()));
copyAvps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, this.originHost.getBytes()));
copyAvps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, this.originRealm.getBytes()));
for (DiameterAvp avp : request.getAvps()) {
if (avp.getCode() == Avp.ACC_RECORD_NUMBER || avp.getCode() == Avp.ACC_RECORD_TYPE || avp.getCode() == Avp.ACCT_APPLICATION_ID || avp.getCode() == Avp.VENDOR_SPECIFIC_APPLICATION_ID) {
copyAvps.add((DiameterAvp) avp.clone());
}
}
DiameterMessageImpl answer = (DiameterMessageImpl) messageFactory.createMessage(implRequest.getHeader(), copyAvps.toArray(new DiameterAvp[copyAvps.size()]));
// This is an answer.
Message rawAnswer = answer.getGenericData();
rawAnswer.setRequest(false);
// just in case. answers never have T flag set
rawAnswer.setReTransmitted(false);
return new AccountingAnswerImpl(rawAnswer);
} catch (Exception e) {
logger.error("", e);
}
return null;
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class GroupedAvpImpl method addAvp.
private void addAvp(DiameterAvp avp, AvpSet set) {
if (avp instanceof GroupedAvp) {
AvpSet avpSet = set.addGroupedAvp(avp.getCode(), avp.getVendorId(), avp.getMandatoryRule() != DiameterAvp.FLAG_RULE_MUSTNOT, avp.getProtectedRule() == DiameterAvp.FLAG_RULE_MUST);
DiameterAvp[] groupedAVPs = ((GroupedAvp) avp).getExtensionAvps();
for (DiameterAvp avpFromGroup : groupedAVPs) {
addAvp(avpFromGroup, avpSet);
}
} else if (avp != null) {
set.addAvp(avp.getCode(), avp.byteArrayValue(), avp.getVendorId(), avp.getMandatoryRule() != DiameterAvp.FLAG_RULE_MUSTNOT, avp.getProtectedRule() == DiameterAvp.FLAG_RULE_MUST);
}
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp 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()]);
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class ShServerMessageFactoryImpl method createProfileUpdateAnswer.
public ProfileUpdateAnswer createProfileUpdateAnswer(ProfileUpdateRequest request) {
List<DiameterAvp> avps = new ArrayList<DiameterAvp>();
DiameterAvp sessionIdAvp = null;
try {
sessionIdAvp = localFactory.getBaseFactory().createAvp(0, DiameterAvpCodes.SESSION_ID, request.getSessionId());
avps.add(sessionIdAvp);
} catch (NoSuchAvpException e) {
logger.error("Unable to create Session-Id AVP.", e);
}
if (request.getUserIdentity() != null) {
avps.add(request.getUserIdentity());
}
Message msg = createShMessage(request.getHeader(), avps.toArray(new DiameterAvp[avps.size()]));
ProfileUpdateAnswerImpl answer = new ProfileUpdateAnswerImpl(msg);
answer.setRouteRecords(request.getRouteRecords());
addOrigin(answer);
return answer;
}
use of net.java.slee.resource.diameter.base.events.avp.DiameterAvp in project jain-slee.diameter by RestComm.
the class ShClientMessageFactoryImpl method createSubscribeNotificationsRequest.
public SubscribeNotificationsRequest createSubscribeNotificationsRequest() {
DiameterAvp[] avps = new DiameterAvp[0];
if (session != null) {
try {
DiameterAvp sessionIdAvp = null;
sessionIdAvp = baseAvpFactory.createAvp(0, DiameterAvpCodes.SESSION_ID, session.getSessionId());
avps = new DiameterAvp[] { sessionIdAvp };
} catch (NoSuchAvpException e) {
logger.error("Unexpected failure trying to create Session-Id AVP.", e);
}
}
Message msg = createShMessage(null, avps, SubscribeNotificationsRequest.commandCode);
SubscribeNotificationsRequestImpl snr = new SubscribeNotificationsRequestImpl(msg);
addOrigin(snr);
return snr;
}
Aggregations