use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class RoMessageFactoryImpl method createRoCreditControlAnswer.
public RoCreditControlAnswer createRoCreditControlAnswer(RoCreditControlRequest request) {
// Create the answer from the request
RoCreditControlRequestImpl ccr = (RoCreditControlRequestImpl) request;
// DiameterAvp sessionIdAvp = null;
// try {
// sessionIdAvp = creditControlAvpFactory.getBaseFactory().createAvp(0,
// DiameterAvpCodes.SESSION_ID, this.session.getSessionId());
// }
// catch (NoSuchAvpException e1) {
// logger.error("Session-Id AVP not found in message", e1);
// }
RoCreditControlAnswerImpl msg = new RoCreditControlAnswerImpl(createMessage(ccr.getHeader(), new DiameterAvp[] {}));
// FIXME: ammendonca: go through proper methods...
Message raw = msg.getGenericData();
raw.setRequest(false);
// just in case. answers never have T flag set
raw.setReTransmitted(false);
raw.getAvps().removeAvp(DiameterAvpCodes.DESTINATION_HOST);
raw.getAvps().removeAvp(DiameterAvpCodes.DESTINATION_REALM);
raw.getAvps().removeAvp(DiameterAvpCodes.ORIGIN_HOST);
raw.getAvps().removeAvp(DiameterAvpCodes.ORIGIN_REALM);
msg.setSessionId(request.getSessionId());
// Now copy the needed AVPs
DiameterAvp[] messageAvps = request.getAvps();
if (messageAvps != null) {
for (DiameterAvp a : messageAvps) {
try {
if (ids.contains(a.getCode())) {
msg.addAvp(a);
}
} catch (Exception e) {
logger.error("Failed to add AVP to answer. Code[" + a.getCode() + "]", e);
}
}
}
addOrigin(msg);
return msg;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class RoMessageFactoryImpl method createRawMessage.
protected Message createRawMessage(DiameterHeader header) {
int commandCode = 0;
long endToEndId = 0;
long hopByHopId = 0;
boolean isRequest = true;
boolean isProxiable = true;
boolean isError = false;
boolean isPotentiallyRetransmitted = false;
if (header != null) {
// Answer
commandCode = header.getCommandCode();
endToEndId = header.getEndToEndId();
hopByHopId = header.getHopByHopId();
isRequest = header.isRequest();
isProxiable = header.isProxiable();
isError = header.isError();
isPotentiallyRetransmitted = header.isPotentiallyRetransmitted();
// aid = ApplicationId.createByAuthAppId(header.getApplicationId());
} else {
commandCode = RoCreditControlRequest.commandCode;
// endToEndId = (long) (Math.random()*1000000);
// hopByHopId = (long) (Math.random()*1000000)+1;
}
Message msg = null;
try {
if (header != null) {
msg = stack.getSessionFactory().getNewRawSession().createMessage(commandCode, roAppId, hopByHopId, endToEndId);
} else {
msg = stack.getSessionFactory().getNewRawSession().createMessage(commandCode, roAppId);
}
} catch (IllegalDiameterStateException e) {
logger.error("Failed to get session factory for message creation.", e);
} catch (InternalException e) {
logger.error("Failed to create new raw session for message creation.", e);
}
// Set the message flags from header (or default)
msg.setRequest(isRequest);
msg.setProxiable(isProxiable);
msg.setError(isError);
msg.setReTransmitted(isRequest && isPotentiallyRetransmitted);
return msg;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class RxMessageFactoryImpl method createRawMessage.
protected Message createRawMessage(DiameterHeader header, int _commandCode, ApplicationId appId) {
int commandCode = 0;
long endToEndId = 0;
long hopByHopId = 0;
boolean isRequest = true;
boolean isProxiable = true;
boolean isError = false;
boolean isPotentiallyRetransmitted = false;
if (header != null) {
commandCode = header.getCommandCode();
endToEndId = header.getEndToEndId();
hopByHopId = header.getHopByHopId();
isRequest = header.isRequest();
isProxiable = header.isProxiable();
isError = header.isError();
isPotentiallyRetransmitted = header.isPotentiallyRetransmitted();
} else {
commandCode = _commandCode;
}
try {
Message msg = stack.getSessionFactory().getNewRawSession().createMessage(commandCode, appId != null ? appId : rxAppId, hopByHopId, endToEndId);
// Set the message flags from header (or default)
msg.setRequest(isRequest);
msg.setProxiable(isProxiable);
msg.setError(isError);
msg.setReTransmitted(isRequest && isPotentiallyRetransmitted);
return msg;
} catch (Exception e) {
logger.error("Failure while trying to create raw message.", e);
}
return null;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class RxSessionActivityImpl method doSendMessage.
// some override from base
protected Message doSendMessage(DiameterMessage message) {
Message receivedMessage = null;
try {
if (message instanceof DiameterMessageImpl) {
Future<Message> future = session.send(((DiameterMessageImpl) message).getGenericData());
receivedMessage = future.get();
} else {
throw new OperationNotSupportedException((new StringBuilder()).append("Trying to send wrong type of message? [").append(message.getClass()).append("] \n").append(message).toString());
}
} catch (AvpNotAllowedException e) {
throw new net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException("Message validation failed.", e, e.getAvpCode(), e.getVendorId());
} catch (Exception e) {
logger.error("Failure sending sync request.", e);
}
return receivedMessage;
}
use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.
the class RfMessageFactoryImpl method createRfAccountingMessage.
protected RfAccountingMessage createRfAccountingMessage(DiameterHeader diameterHeader, DiameterAvp[] avps) throws IllegalArgumentException {
// List<DiameterAvp> list = (List<DiameterAvp>) this.avpList.clone();
boolean isRequest = diameterHeader == null;
RfAccountingMessage 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 RfAccountingAnswerImpl(raw);
} else {
Message raw = createMessage(null, avps);
raw.setProxiable(true);
raw.setRequest(true);
msg = new RfAccountingRequestImpl(raw);
}
return msg;
}
Aggregations