Search in sources :

Example 1 with RoCreditControlAnswerImpl

use of org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl 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;
}
Also used : RoCreditControlRequestImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlRequestImpl) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) RoCreditControlMessage(net.java.slee.resource.diameter.ro.events.RoCreditControlMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) RoCreditControlAnswerImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) InternalException(org.jdiameter.api.InternalException) IllegalDiameterStateException(org.jdiameter.api.IllegalDiameterStateException)

Example 2 with RoCreditControlAnswerImpl

use of org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl 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);
    }
}
Also used : RoCreditControlRequestImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlRequestImpl) AccountingAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl) AbortSessionAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AbortSessionAnswerImpl) AccountingRequestImpl(org.mobicents.slee.resource.diameter.base.events.AccountingRequestImpl) RoCreditControlAnswerImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl) ExtensionDiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl) SleeEndpoint(javax.slee.resource.SleeEndpoint) ReAuthRequestImpl(org.mobicents.slee.resource.diameter.base.events.ReAuthRequestImpl) AbortSessionRequestImpl(org.mobicents.slee.resource.diameter.base.events.AbortSessionRequestImpl) SessionTerminationAnswerImpl(org.mobicents.slee.resource.diameter.base.events.SessionTerminationAnswerImpl) ReAuthAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ReAuthAnswerImpl) ErrorAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl) SessionTerminationRequestImpl(org.mobicents.slee.resource.diameter.base.events.SessionTerminationRequestImpl)

Example 3 with RoCreditControlAnswerImpl

use of org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl in project jain-slee.diameter by RestComm.

the class RoMessageFactoryImpl method createRoCreditControlRequest.

private RoCreditControlMessage createRoCreditControlRequest(DiameterHeader diameterHeader, DiameterAvp[] avps) throws IllegalArgumentException {
    // List<DiameterAvp> list = (List<DiameterAvp>) this.avpList.clone();
    boolean isRequest = diameterHeader == null;
    RoCreditControlMessage 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 RoCreditControlAnswerImpl(raw);
    } else {
        Message raw = createMessage(null, avps);
        raw.setProxiable(true);
        raw.setRequest(true);
        msg = new RoCreditControlRequestImpl(raw);
    }
    return msg;
}
Also used : RoCreditControlMessage(net.java.slee.resource.diameter.ro.events.RoCreditControlMessage) RoCreditControlRequestImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlRequestImpl) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) RoCreditControlMessage(net.java.slee.resource.diameter.ro.events.RoCreditControlMessage) RoCreditControlAnswerImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl)

Example 4 with RoCreditControlAnswerImpl

use of org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl in project jain-slee.diameter by RestComm.

the class RoSessionActivityImpl 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 RoCreditControlRequest.commandCode:
                        answer = new RoCreditControlAnswerImpl(receivedMessage);
                        break;
                    default:
                        logger.error("Received an unknown type of Message for Ro 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) RoCreditControlAnswerImpl(org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl) ErrorAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)

Aggregations

RoCreditControlAnswerImpl (org.mobicents.slee.resource.diameter.ro.events.RoCreditControlAnswerImpl)4 DiameterMessage (net.java.slee.resource.diameter.base.events.DiameterMessage)3 Message (org.jdiameter.api.Message)3 RoCreditControlRequestImpl (org.mobicents.slee.resource.diameter.ro.events.RoCreditControlRequestImpl)3 RoCreditControlMessage (net.java.slee.resource.diameter.ro.events.RoCreditControlMessage)2 ErrorAnswerImpl (org.mobicents.slee.resource.diameter.base.events.ErrorAnswerImpl)2 SleeEndpoint (javax.slee.resource.SleeEndpoint)1 AvpNotAllowedException (net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)1 DiameterAvp (net.java.slee.resource.diameter.base.events.avp.DiameterAvp)1 IllegalDiameterStateException (org.jdiameter.api.IllegalDiameterStateException)1 InternalException (org.jdiameter.api.InternalException)1 AbortSessionAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AbortSessionAnswerImpl)1 AbortSessionRequestImpl (org.mobicents.slee.resource.diameter.base.events.AbortSessionRequestImpl)1 AccountingAnswerImpl (org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl)1 AccountingRequestImpl (org.mobicents.slee.resource.diameter.base.events.AccountingRequestImpl)1 ExtensionDiameterMessageImpl (org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl)1 ReAuthAnswerImpl (org.mobicents.slee.resource.diameter.base.events.ReAuthAnswerImpl)1 ReAuthRequestImpl (org.mobicents.slee.resource.diameter.base.events.ReAuthRequestImpl)1 SessionTerminationAnswerImpl (org.mobicents.slee.resource.diameter.base.events.SessionTerminationAnswerImpl)1 SessionTerminationRequestImpl (org.mobicents.slee.resource.diameter.base.events.SessionTerminationRequestImpl)1