Search in sources :

Example 16 with Message

use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.

the class RfServerSessionActivityImpl method createRfAccountingAnswer.

public RfAccountingAnswer createRfAccountingAnswer(RfAccountingRequest request) {
    try {
        // Extract interesting AVPs
        ArrayList<DiameterAvp> copyAvps = new ArrayList<DiameterAvp>();
        copyAvps.add(avpFactory.createAvp(Avp.SESSION_ID, serverSession.getSessions().get(0).getSessionId()));
        copyAvps.add(avpFactory.createAvp(Avp.ORIGIN_HOST, this.originHost.getBytes()));
        copyAvps.add(avpFactory.createAvp(Avp.ORIGIN_REALM, this.originRealm.getBytes()));
        for (DiameterAvp avp : request.getAvps()) {
            if (avp.getCode() == Avp.ACC_RECORD_NUMBER || avp.getCode() == Avp.ACC_RECORD_TYPE) /* || 
            avp.getCode() == Avp.ACCT_APPLICATION_ID || avp.getCode() == Avp.VENDOR_SPECIFIC_APPLICATION_ID*/
            {
                copyAvps.add((DiameterAvp) avp.clone());
            }
        }
        RfAccountingAnswerImpl answer = (RfAccountingAnswerImpl) ((RfMessageFactoryImpl) rfMessageFactory).createRfAccountingMessage(request.getHeader(), copyAvps.toArray(new DiameterAvp[copyAvps.size()]));
        // Get the raw Answer
        Message rawAnswer = answer.getGenericData();
        // This is an answer.
        rawAnswer.setRequest(false);
        // just in case. answers never have T flag set
        rawAnswer.setReTransmitted(false);
        answer.setData(request);
        return answer;
    } catch (Exception e) {
        logger.error("", e);
    }
    return null;
}
Also used : DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) Message(org.jdiameter.api.Message) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) ArrayList(java.util.ArrayList) RfAccountingAnswerImpl(org.mobicents.slee.resource.diameter.rf.events.RfAccountingAnswerImpl) IOException(java.io.IOException) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)

Example 17 with Message

use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.

the class S6aMessageFactoryImpl method createS6aMessage.

/**
 * Creates a S6a Message with specified command-code and avps filled. If a header is present an answer will be created, if not
 * it will generate a request.
 *
 * @param diameterHeader
 * @param avps
 * @param _commandCode
 * @param appId
 * @return
 * @throws InternalException
 */
DiameterMessage createS6aMessage(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws InternalException {
    boolean creatingRequest = diameterHeader == null;
    Message msg = null;
    if (!creatingRequest) {
        Message raw = createMessage(diameterHeader, avps, 0, appId);
        raw.setProxiable(diameterHeader.isProxiable());
        raw.setRequest(false);
        // just in case. answers never have T flag set
        raw.setReTransmitted(false);
        // FIXME ? raw.getAvps().removeAvp(Avp.AUTH_APPLICATION_ID);
        msg = raw;
    } else {
        Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
        raw.setProxiable(true);
        raw.setRequest(true);
        msg = raw;
    }
    int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
    DiameterMessage diamMessage = null;
    switch(commandCode) {
        case UpdateLocationRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new UpdateLocationRequestImpl(msg) : new UpdateLocationAnswerImpl(msg);
            break;
        case AuthenticationInformationRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new AuthenticationInformationRequestImpl(msg) : new AuthenticationInformationAnswerImpl(msg);
            break;
        case CancelLocationRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new CancelLocationRequestImpl(msg) : new CancelLocationAnswerImpl(msg);
            break;
        case InsertSubscriberDataRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new InsertSubscriberDataRequestImpl(msg) : new InsertSubscriberDataAnswerImpl(msg);
            break;
        case DeleteSubscriberDataRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new DeleteSubscriberDataRequestImpl(msg) : new DeleteSubscriberDataAnswerImpl(msg);
            break;
        case PurgeUERequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new PurgeUERequestImpl(msg) : new PurgeUEAnswerImpl(msg);
            break;
        case ResetRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new ResetRequestImpl(msg) : new ResetAnswerImpl(msg);
            break;
        case NotifyRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new NotifyRequestImpl(msg) : new NotifyAnswerImpl(msg);
            break;
        default:
            diamMessage = new ExtensionDiameterMessageImpl(msg);
    }
    if (!diamMessage.hasSessionId() && session != null) {
        diamMessage.setSessionId(session.getSessionId());
    }
    return diamMessage;
}
Also used : UpdateLocationAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.UpdateLocationAnswerImpl) UpdateLocationRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.UpdateLocationRequestImpl) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) NotifyRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.NotifyRequestImpl) PurgeUEAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.PurgeUEAnswerImpl) CancelLocationRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.CancelLocationRequestImpl) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) NotifyAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.NotifyAnswerImpl) InsertSubscriberDataRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.InsertSubscriberDataRequestImpl) DeleteSubscriberDataAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.DeleteSubscriberDataAnswerImpl) ExtensionDiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl) ResetRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.ResetRequestImpl) AuthenticationInformationAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.AuthenticationInformationAnswerImpl) DeleteSubscriberDataRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.DeleteSubscriberDataRequestImpl) ResetAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.ResetAnswerImpl) AuthenticationInformationRequestImpl(org.mobicents.slee.resource.diameter.s6a.events.AuthenticationInformationRequestImpl) CancelLocationAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.CancelLocationAnswerImpl) InsertSubscriberDataAnswerImpl(org.mobicents.slee.resource.diameter.s6a.events.InsertSubscriberDataAnswerImpl) PurgeUERequestImpl(org.mobicents.slee.resource.diameter.s6a.events.PurgeUERequestImpl)

Example 18 with Message

use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.

the class ShServerMessageFactoryImpl method createShMessage.

// Private Methods -----------------------------------------------------
private Message createShMessage(DiameterHeader diameterHeader, DiameterAvp[] avps) throws IllegalArgumentException {
    // List<DiameterAvp> list = (List<DiameterAvp>) this.avpList.clone();
    boolean isRequest = diameterHeader == null;
    Message 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 = raw;
    } else {
        Message raw = createMessage(null, avps);
        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 19 with Message

use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.

the class ShServerMessageFactoryImpl method createUserDataAnswer.

public UserDataAnswer createUserDataAnswer(UserDataRequest request) {
    // Message msg = createShMessage(UserDataAnswer.commandCode, session !=
    // null ? session.getSessionId() : null, false);
    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()]));
    UserDataAnswerImpl answer = new UserDataAnswerImpl(msg);
    answer.setRouteRecords(request.getRouteRecords());
    // add more :) ?
    addOrigin(answer);
    return answer;
}
Also used : UserDataAnswerImpl(org.mobicents.slee.resource.diameter.sh.events.UserDataAnswerImpl) 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) NoSuchAvpException(net.java.slee.resource.diameter.base.NoSuchAvpException)

Example 20 with Message

use of org.jdiameter.api.Message in project jain-slee.diameter by RestComm.

the class ShServerMessageFactoryImpl method createMessage.

protected Message createMessage(DiameterHeader header, DiameterAvp[] avps) throws AvpNotAllowedException {
    try {
        Message msg = createRawMessage(header);
        AvpSet set = msg.getAvps();
        for (DiameterAvp avp : avps) {
            addAvp(avp, set);
        }
        return msg;
    } catch (Exception e) {
        logger.error("Failed to create message.", e);
    }
    return null;
}
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) AvpSet(org.jdiameter.api.AvpSet) 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)

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