use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class DiameterActivityImpl method sendSyncMessage.
public DiameterMessage sendSyncMessage(DiameterMessage message) {
DiameterMessage answer = null;
Message receivedMessage = doSendMessage(message);
if (receivedMessage != null) {
if (!receivedMessage.isRequest()) {
if (receivedMessage.isError()) {
answer = new ErrorAnswerImpl(receivedMessage);
} else {
switch(receivedMessage.getCommandCode()) {
case AbortSessionAnswer.commandCode:
answer = new AbortSessionAnswerImpl(receivedMessage);
break;
case AccountingAnswer.commandCode:
answer = new AccountingAnswerImpl(receivedMessage);
break;
case CapabilitiesExchangeAnswer.commandCode:
answer = new CapabilitiesExchangeAnswerImpl(receivedMessage);
break;
case DeviceWatchdogAnswer.commandCode:
answer = new DeviceWatchdogAnswerImpl(receivedMessage);
break;
case DisconnectPeerAnswer.commandCode:
answer = new DisconnectPeerAnswerImpl(receivedMessage);
break;
case ReAuthAnswer.commandCode:
answer = new ReAuthAnswerImpl(receivedMessage);
break;
case SessionTerminationAnswer.commandCode:
answer = new SessionTerminationAnswerImpl(receivedMessage);
break;
default:
logger.error("Received an unknown type of Message for Base Activity: " + receivedMessage);
break;
}
}
} else {
logger.error("Received a REQUEST message when expecting an ANSWER.");
}
} else {
logger.debug("No answer received. Returning null.");
}
return answer;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class AvpUtilities method performPreAddOperations.
/**
* @param parent the Message/Grouped AVP where AVP will be added to, for validation purposes. if null, no validation is performed.
* @param avpCode
* @param vendorId
* @param set
* @throws AvpNotAllowedException
*/
private static void performPreAddOperations(Object parent, int avpCode, long vendorId, AvpSet set) throws AvpNotAllowedException {
if (!dictionary.isEnabled()) {
// no need to proceed any further.. no validation
return;
}
if (parent instanceof Message) {
Message msg = (Message) parent;
MessageRepresentation msgRep = dictionary.getMessage(msg.getCommandCode(), msg.getApplicationId(), msg.isRequest());
// if we don't know anything about this message, let's just move on..
if (msgRep == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to find message in dictionary, skipping validation. (Command Code: " + msg.getCommandCode() + ", Application-Id: " + msg.getApplicationId() + ")");
}
return;
}
if (!msgRep.isAllowed(avpCode, vendorId)) {
throw new AvpNotAllowedException("Avp defined by code: " + avpCode + ", vendorId: " + vendorId + " is not allowed in message - code: " + msg.getCommandCode() + ", appId: " + msg.getApplicationId() + ", isRequest: " + msg.isRequest(), avpCode, vendorId);
}
if (msgRep.isCountValidForMultiplicity(msg.getAvps(), avpCode, vendorId, 1)) {
// its ok.
return;
} else {
throw new AvpNotAllowedException("Avp not allowed, count exceeded.", avpCode, vendorId);
}
} else if (parent instanceof GroupedAvp) {
GroupedAvpImpl gAvp = (GroupedAvpImpl) parent;
org.jdiameter.api.validation.AvpRepresentation parentAvpRep = dictionary.getAvp(gAvp.getCode(), gAvp.getVendorId());
// if we don't know anything about this avp, let's just move on..
if (parentAvpRep == null) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to find parent AVP in dictionary, skipping validation. (AVP Code: " + gAvp.getCode() + ", Vendor-Id: " + gAvp.getVendorId() + ")");
}
return;
}
if (!parentAvpRep.isAllowed(avpCode, vendorId)) {
throw new AvpNotAllowedException("AVP with Code '" + avpCode + "' and Vendor-Id '" + vendorId + "' is not allowed as a child of AVP with Code '" + parentAvpRep.getCode() + "' and Vendor-Id '" + parentAvpRep.getVendorId() + "'.", avpCode, vendorId);
}
// Now we get the actual AVP to add representation...
org.jdiameter.api.validation.AvpRepresentation avpRep = dictionary.getAvp(avpCode, vendorId);
// ..to check if it can be added (multiplicity) to the parent.
if (avpRep.isCountValidForMultiplicity(gAvp.getGenericData(), 1)) {
// its ok.
return;
} else {
throw new AvpNotAllowedException("Avp not allowed, count exceeded.", avpCode, vendorId);
}
}
}
use of org.jdiameter.api.Message 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 org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class ShClientMessageFactoryImpl method createShMessage.
private Message createShMessage(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode) throws IllegalArgumentException {
// List<DiameterAvp> list = (List<DiameterAvp>) this.avpList.clone();
boolean isRequest = diameterHeader == null;
Message msg = null;
if (!isRequest) {
Message raw = createMessage(diameterHeader, avps, 0);
raw.setProxiable(diameterHeader.isProxiable());
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
msg = raw;
} else {
Message raw = createMessage(null, avps, _commandCode);
raw.setProxiable(true);
raw.setRequest(true);
msg = raw;
}
return msg;
}
use of org.jdiameter.api.Message 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