use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class S13MessageFactoryImpl method createS13Message.
/**
* Creates a S13 Message with specified command-code and avps filled. If a header is present an answer will be created, if not
* it will generate a request.
*
* @param diameterHeader
* @param avps
* @param _commandCode
* @param appId
* @return
* @throws InternalException
*/
DiameterMessage createS13Message(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws InternalException {
boolean creatingRequest = diameterHeader == null;
Message msg = null;
if (!creatingRequest) {
Message raw = createMessage(diameterHeader, avps, 0, appId);
raw.setProxiable(diameterHeader.isProxiable());
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
// FIXME ? raw.getAvps().removeAvp(Avp.AUTH_APPLICATION_ID);
msg = raw;
} else {
Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
raw.setProxiable(true);
raw.setRequest(true);
msg = raw;
}
int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
DiameterMessage diamMessage = null;
switch(commandCode) {
case MEIdentityCheckRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new MEIdentityCheckRequestImpl(msg) : new MEIdentityCheckAnswerImpl(msg);
break;
default:
diamMessage = new ExtensionDiameterMessageImpl(msg);
}
if (!diamMessage.hasSessionId() && session != null) {
diamMessage.setSessionId(session.getSessionId());
}
return diamMessage;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class CreditControlMessageFactoryImpl method createCreditControlMessage.
// Private Methods -------------------------------------------------
private CreditControlMessage createCreditControlMessage(DiameterHeader diameterHeader, DiameterAvp[] avps) throws IllegalArgumentException {
// List<DiameterAvp> list = (List<DiameterAvp>) this.avpList.clone();
boolean isRequest = diameterHeader == null;
CreditControlMessage msg = null;
if (!isRequest) {
Message raw = createMessage(diameterHeader, avps);
raw.setProxiable(diameterHeader.isProxiable());
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
msg = new CreditControlAnswerImpl(raw);
} else {
Message raw = createMessage(null, avps);
raw.setProxiable(true);
raw.setRequest(true);
msg = new CreditControlRequestImpl(raw);
}
return msg;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class CreditControlSessionImpl method sendSyncMessage.
@Override
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 CreditControlRequest.commandCode:
answer = new CreditControlAnswerImpl(receivedMessage);
break;
default:
logger.error("Received an unknown type of Message for Credit-Control 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 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 org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class DiameterActivityImpl method doSendMessage.
protected Message doSendMessage(DiameterMessage message) {
Message receivedMessage = null;
try {
if (message instanceof DiameterMessageImpl) {
Future<Message> future = this.session.send(((DiameterMessageImpl) message).getGenericData());
receivedMessage = future.get();
} else {
throw new OperationNotSupportedException("Trying to send wrong type of message? [" + message.getClass() + "] \n" + message);
}
} catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
throw new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
} catch (Exception e) {
logger.error("Failure sending sync request.", e);
}
return receivedMessage;
}
Aggregations