Search in sources :

Example 11 with Message

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;
}
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 12 with Message

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

Example 13 with Message

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

Example 14 with Message

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

Example 15 with Message

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;
}
Also used : RfAccountingMessage(net.java.slee.resource.diameter.rf.events.RfAccountingMessage) Message(org.jdiameter.api.Message) RfAccountingMessage(net.java.slee.resource.diameter.rf.events.RfAccountingMessage) RfAccountingAnswerImpl(org.mobicents.slee.resource.diameter.rf.events.RfAccountingAnswerImpl) RfAccountingRequestImpl(org.mobicents.slee.resource.diameter.rf.events.RfAccountingRequestImpl)

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