Search in sources :

Example 36 with Message

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;
}
Also used : AccountingAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) AbortSessionAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AbortSessionAnswerImpl) SessionTerminationAnswerImpl(org.mobicents.slee.resource.diameter.base.events.SessionTerminationAnswerImpl) CapabilitiesExchangeAnswerImpl(org.mobicents.slee.resource.diameter.base.events.CapabilitiesExchangeAnswerImpl) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) ReAuthAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ReAuthAnswerImpl) ErrorAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl) DisconnectPeerAnswerImpl(org.mobicents.slee.resource.diameter.base.events.DisconnectPeerAnswerImpl) DeviceWatchdogAnswerImpl(org.mobicents.slee.resource.diameter.base.events.DeviceWatchdogAnswerImpl)

Example 37 with Message

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);
        }
    }
}
Also used : GroupedAvpImpl(org.mobicents.slee.resource.diameter.base.events.avp.GroupedAvpImpl) Message(org.jdiameter.api.Message) MessageRepresentation(org.jdiameter.api.validation.MessageRepresentation) AvpRepresentation(org.mobicents.diameter.dictionary.AvpRepresentation)

Example 38 with Message

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;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) ProfileUpdateAnswerImpl(org.mobicents.slee.resource.diameter.sh.events.ProfileUpdateAnswerImpl) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException)

Example 39 with Message

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;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage)

Example 40 with Message

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;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException) SubscribeNotificationsRequestImpl(org.mobicents.slee.resource.diameter.sh.events.SubscribeNotificationsRequestImpl)

Aggregations

Message (org.jdiameter.api.Message)61 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)56 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)22 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)10 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)10 AvpSet (org.jdiameter.api.AvpSet)8 ArrayList (java.util.ArrayList)7 IllegalDiameterStateException (org.jdiameter.api.IllegalDiameterStateException)7 InternalException (org.jdiameter.api.InternalException)7 ErrorAnswerImpl (org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)7 GxCreditControlMessage (net.java.slee.resource.diameter.gx.events.GxCreditControlMessage)5 GxReAuthMessage (net.java.slee.resource.diameter.gx.events.GxReAuthMessage)5 RoCreditControlMessage (net.java.slee.resource.diameter.ro.events.RoCreditControlMessage)4 DiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.DiameterMessageImpl)4 ExtensionDiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl)4 IOException (java.io.IOException)3 AccountingAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl)3 GqAARequestImpl (org.mobicents.slee.resource.diameter.gq.events.GqAARequestImpl)3 GqAbortSessionRequestImpl (org.mobicents.slee.resource.diameter.gq.events.GqAbortSessionRequestImpl)3 GqReAuthRequestImpl (org.mobicents.slee.resource.diameter.gq.events.GqReAuthRequestImpl)3