Search in sources :

Example 1 with CreditControlAnswerImpl

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

Example 2 with CreditControlAnswerImpl

use of org.mobicents.slee.resource.diameter.cca.events.CreditControlAnswerImpl in project jain-slee.diameter by RestComm.

the class CreditControlMessageFactoryImpl method createCreditControlAnswer.

/*
   * (non-Javadoc)
   * 
   * @see net.java.slee.resource.diameter.cca.CreditControlMessageFactory#createCreditControlAnswer
   * (net.java.slee.resource.diameter.cca.events.CreditControlRequest)
   */
public CreditControlAnswer createCreditControlAnswer(CreditControlRequest request) {
    // Create the answer from the request
    CreditControlRequestImpl ccr = (CreditControlRequestImpl) 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);
    // }
    CreditControlAnswerImpl msg = (CreditControlAnswerImpl) createCreditControlMessage(ccr.getHeader(), new DiameterAvp[0]);
    msg.getGenericData().getAvps().removeAvp(DiameterAvpCodes.DESTINATION_HOST);
    msg.getGenericData().getAvps().removeAvp(DiameterAvpCodes.DESTINATION_REALM);
    msg.getGenericData().getAvps().removeAvp(DiameterAvpCodes.ORIGIN_HOST);
    msg.getGenericData().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;
}
Also used : DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) CreditControlRequestImpl(org.mobicents.slee.resource.diameter.cca.events.CreditControlRequestImpl) CreditControlAnswerImpl(org.mobicents.slee.resource.diameter.cca.events.CreditControlAnswerImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) InternalException(org.jdiameter.api.InternalException) IllegalDiameterStateException(org.jdiameter.api.IllegalDiameterStateException) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException)

Example 3 with CreditControlAnswerImpl

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

Aggregations

CreditControlAnswerImpl (org.mobicents.slee.resource.diameter.cca.events.CreditControlAnswerImpl)3 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)2 Message (org.jdiameter.api.Message)2 CreditControlRequestImpl (org.mobicents.slee.resource.diameter.cca.events.CreditControlRequestImpl)2 NoSuchAvpException (net.java.slee.resource.diameter.base.NoSuchAvpException)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)1 CreditControlMessage (net.java.slee.resource.diameter.cca.events.CreditControlMessage)1 IllegalDiameterStateException (org.jdiameter.api.IllegalDiameterStateException)1 InternalException (org.jdiameter.api.InternalException)1 ErrorAnswerImpl (org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)1