use of org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl in project jain-slee.diameter by RestComm.
the class DiameterMessageFactoryImpl method createDiameterMessage.
protected DiameterMessage createDiameterMessage(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws IllegalArgumentException {
boolean creatingRequest = diameterHeader == null;
Message msg = null;
if (!creatingRequest) {
Message raw = createMessage(diameterHeader, avps, 0, appId);
// raw.setProxiable(true);
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
msg = raw;
} else {
Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
boolean isPeerManagementMessage = _commandCode == CapabilitiesExchangeRequest.commandCode || _commandCode == DeviceWatchdogRequest.commandCode || _commandCode == DisconnectPeerRequest.commandCode;
raw.setProxiable(!isPeerManagementMessage);
raw.setRequest(true);
msg = raw;
}
int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
DiameterMessage diamMessage = null;
switch(commandCode) {
case Message.ABORT_SESSION_REQUEST:
diamMessage = creatingRequest ? new AbortSessionRequestImpl(msg) : new AbortSessionAnswerImpl(msg);
break;
case Message.ACCOUNTING_REQUEST:
diamMessage = creatingRequest ? new AccountingRequestImpl(msg) : new AccountingAnswerImpl(msg);
break;
case Message.CAPABILITIES_EXCHANGE_REQUEST:
diamMessage = creatingRequest ? new CapabilitiesExchangeRequestImpl(msg) : new CapabilitiesExchangeAnswerImpl(msg);
break;
case Message.DEVICE_WATCHDOG_REQUEST:
diamMessage = creatingRequest ? new DeviceWatchdogRequestImpl(msg) : new DeviceWatchdogAnswerImpl(msg);
break;
case Message.DISCONNECT_PEER_REQUEST:
diamMessage = creatingRequest ? new DisconnectPeerRequestImpl(msg) : new DisconnectPeerAnswerImpl(msg);
break;
case Message.RE_AUTH_REQUEST:
diamMessage = creatingRequest ? new ReAuthRequestImpl(msg) : new ReAuthAnswerImpl(msg);
break;
case Message.SESSION_TERMINATION_REQUEST:
diamMessage = creatingRequest ? new SessionTerminationRequestImpl(msg) : new SessionTerminationAnswerImpl(msg);
break;
default:
diamMessage = new ExtensionDiameterMessageImpl(msg);
}
// Finally, add Origin-Host and Origin-Realm, if not present.
addOriginHostAndRealm(diamMessage);
return diamMessage;
}
use of org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl in project jain-slee.diameter by RestComm.
the class DiameterRoResourceAdaptor method createEvent.
/**
* Create Event object from a JDiameter message (request or answer)
*
* @return a DiameterMessage object wrapping the request/answer
* @throws OperationNotSupportedException
*/
private DiameterMessage createEvent(Message message) {
if (message == null) {
throw new NullPointerException("Message argument cannot be null while creating event.");
}
int commandCode = message.getCommandCode();
if (message.isError()) {
return new ErrorAnswerImpl(message);
}
boolean isRequest = message.isRequest();
switch(commandCode) {
case // CCR/CCA
RoCreditControlRequest.commandCode:
return isRequest ? new RoCreditControlRequestImpl(message) : new RoCreditControlAnswerImpl(message);
case // ASR/ASA
AbortSessionAnswer.commandCode:
return isRequest ? new AbortSessionRequestImpl(message) : new AbortSessionAnswerImpl(message);
case // STR/STA
SessionTerminationAnswer.commandCode:
return isRequest ? new SessionTerminationRequestImpl(message) : new SessionTerminationAnswerImpl(message);
case // RAR/RAA
ReAuthAnswer.commandCode:
return isRequest ? new ReAuthRequestImpl(message) : new ReAuthAnswerImpl(message);
case // ACR/ACA
AccountingAnswer.commandCode:
return isRequest ? new AccountingRequestImpl(message) : new AccountingAnswerImpl(message);
default:
return new ExtensionDiameterMessageImpl(message);
}
}
use of org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl 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.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl in project jain-slee.diameter by RestComm.
the class AccountingServerSessionActivityImpl method sendAccountingAnswer.
public void sendAccountingAnswer(AccountingAnswer answer) throws IOException {
try {
AccountingAnswerImpl aca = (AccountingAnswerImpl) answer;
this.serverSession.sendAccountAnswer(new AccountAnswerImpl((Answer) aca.getGenericData()));
// FIXME: check this?
if (this.serverSession.isStateless()) {
endActivity();
} else if (aca.getAccountingRecordType() == AccountingRecordType.STOP_RECORD) {
endActivity();
}
} catch (org.jdiameter.api.validation.AvpNotAllowedException e) {
throw new AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to send message, due to: ", e);
}
throw new IOException("Failed to send message, due to: " + e.getMessage());
}
}
use of org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl 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;
}
Aggregations