use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class RfServerSessionActivityImpl method createRfAccountingAnswer.
public RfAccountingAnswer createRfAccountingAnswer(RfAccountingRequest request) {
try {
// 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());
}
}
RfAccountingAnswerImpl answer = (RfAccountingAnswerImpl) ((RfMessageFactoryImpl) rfMessageFactory).createRfAccountingMessage(request.getHeader(), copyAvps.toArray(new DiameterAvp[copyAvps.size()]));
// Get the raw Answer
Message rawAnswer = answer.getGenericData();
// This is an answer.
rawAnswer.setRequest(false);
// just in case. answers never have T flag set
rawAnswer.setReTransmitted(false);
answer.setData(request);
return answer;
} catch (Exception e) {
logger.error("", e);
}
return null;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class S6aMessageFactoryImpl method createS6aMessage.
/**
* Creates a S6a 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 createS6aMessage(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 UpdateLocationRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new UpdateLocationRequestImpl(msg) : new UpdateLocationAnswerImpl(msg);
break;
case AuthenticationInformationRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new AuthenticationInformationRequestImpl(msg) : new AuthenticationInformationAnswerImpl(msg);
break;
case CancelLocationRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new CancelLocationRequestImpl(msg) : new CancelLocationAnswerImpl(msg);
break;
case InsertSubscriberDataRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new InsertSubscriberDataRequestImpl(msg) : new InsertSubscriberDataAnswerImpl(msg);
break;
case DeleteSubscriberDataRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new DeleteSubscriberDataRequestImpl(msg) : new DeleteSubscriberDataAnswerImpl(msg);
break;
case PurgeUERequest.COMMAND_CODE:
diamMessage = creatingRequest ? new PurgeUERequestImpl(msg) : new PurgeUEAnswerImpl(msg);
break;
case ResetRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new ResetRequestImpl(msg) : new ResetAnswerImpl(msg);
break;
case NotifyRequest.COMMAND_CODE:
diamMessage = creatingRequest ? new NotifyRequestImpl(msg) : new NotifyAnswerImpl(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 ShServerMessageFactoryImpl method createShMessage.
// Private Methods -----------------------------------------------------
private Message createShMessage(DiameterHeader diameterHeader, DiameterAvp[] avps) throws IllegalArgumentException {
// List<DiameterAvp> list = (List<DiameterAvp>) this.avpList.clone();
boolean isRequest = diameterHeader == null;
Message 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 = raw;
} else {
Message raw = createMessage(null, avps);
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 ShServerMessageFactoryImpl method createUserDataAnswer.
public UserDataAnswer createUserDataAnswer(UserDataRequest request) {
// Message msg = createShMessage(UserDataAnswer.commandCode, session !=
// null ? session.getSessionId() : null, false);
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()]));
UserDataAnswerImpl answer = new UserDataAnswerImpl(msg);
answer.setRouteRecords(request.getRouteRecords());
// add more :) ?
addOrigin(answer);
return answer;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class ShServerMessageFactoryImpl method createMessage.
protected Message createMessage(DiameterHeader header, DiameterAvp[] avps) throws AvpNotAllowedException {
try {
Message msg = createRawMessage(header);
AvpSet set = msg.getAvps();
for (DiameterAvp avp : avps) {
addAvp(avp, set);
}
return msg;
} catch (Exception e) {
logger.error("Failed to create message.", e);
}
return null;
}
Aggregations