Search in sources :

Example 1 with Message

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

the class CxDxMessageFactoryImpl method createCxDxMessage.

/**
 * Creates a CxDx 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 createCxDxMessage(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);
        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 LocationInfoRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new LocationInfoRequestImpl(msg) : new LocationInfoAnswerImpl(msg);
            break;
        case MultimediaAuthenticationRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new MultimediaAuthenticationRequestImpl(msg) : new MultimediaAuthenticationAnswerImpl(msg);
            break;
        case PushProfileRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new PushProfileRequestImpl(msg) : new PushProfileAnswerImpl(msg);
            break;
        case RegistrationTerminationRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new RegistrationTerminationRequestImpl(msg) : new RegistrationTerminationAnswerImpl(msg);
            break;
        case ServerAssignmentRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new ServerAssignmentRequestImpl(msg) : new ServerAssignmentAnswerImpl(msg);
            break;
        case UserAuthorizationRequest.COMMAND_CODE:
            diamMessage = creatingRequest ? new UserAuthorizationRequestImpl(msg) : new UserAuthorizationAnswerImpl(msg);
            break;
        default:
            diamMessage = new ExtensionDiameterMessageImpl(msg);
    }
    if (!diamMessage.hasSessionId() && session != null) {
        diamMessage.setSessionId(session.getSessionId());
    }
    return diamMessage;
}
Also used : Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) ServerAssignmentRequestImpl(org.mobicents.slee.resource.diameter.cxdx.events.ServerAssignmentRequestImpl) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) PushProfileRequestImpl(org.mobicents.slee.resource.diameter.cxdx.events.PushProfileRequestImpl) RegistrationTerminationRequestImpl(org.mobicents.slee.resource.diameter.cxdx.events.RegistrationTerminationRequestImpl) ExtensionDiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl) PushProfileAnswerImpl(org.mobicents.slee.resource.diameter.cxdx.events.PushProfileAnswerImpl) LocationInfoAnswerImpl(org.mobicents.slee.resource.diameter.cxdx.events.LocationInfoAnswerImpl) MultimediaAuthenticationRequestImpl(org.mobicents.slee.resource.diameter.cxdx.events.MultimediaAuthenticationRequestImpl) UserAuthorizationRequestImpl(org.mobicents.slee.resource.diameter.cxdx.events.UserAuthorizationRequestImpl) UserAuthorizationAnswerImpl(org.mobicents.slee.resource.diameter.cxdx.events.UserAuthorizationAnswerImpl) LocationInfoRequestImpl(org.mobicents.slee.resource.diameter.cxdx.events.LocationInfoRequestImpl) MultimediaAuthenticationAnswerImpl(org.mobicents.slee.resource.diameter.cxdx.events.MultimediaAuthenticationAnswerImpl) RegistrationTerminationAnswerImpl(org.mobicents.slee.resource.diameter.cxdx.events.RegistrationTerminationAnswerImpl) ServerAssignmentAnswerImpl(org.mobicents.slee.resource.diameter.cxdx.events.ServerAssignmentAnswerImpl)

Example 2 with Message

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

the class DiameterMessageFactoryImpl method createDiameterMessage.

protected DiameterMessage createDiameterMessage(DiameterHeader diameterHeader, DiameterAvp[] avps, int _commandCode, ApplicationId appId) throws IllegalArgumentException {
    boolean creatingRequest = diameterHeader == null;
    Message msg = null;
    if (!creatingRequest) {
        Message raw = createMessage(diameterHeader, avps, 0, appId);
        // raw.setProxiable(true);
        raw.setRequest(false);
        // just in case. answers never have T flag set
        raw.setReTransmitted(false);
        msg = raw;
    } else {
        Message raw = createMessage(diameterHeader, avps, _commandCode, appId);
        boolean isPeerManagementMessage = _commandCode == CapabilitiesExchangeRequest.commandCode || _commandCode == DeviceWatchdogRequest.commandCode || _commandCode == DisconnectPeerRequest.commandCode;
        raw.setProxiable(!isPeerManagementMessage);
        raw.setRequest(true);
        msg = raw;
    }
    int commandCode = creatingRequest ? _commandCode : diameterHeader.getCommandCode();
    DiameterMessage diamMessage = null;
    switch(commandCode) {
        case Message.ABORT_SESSION_REQUEST:
            diamMessage = creatingRequest ? new AbortSessionRequestImpl(msg) : new AbortSessionAnswerImpl(msg);
            break;
        case Message.ACCOUNTING_REQUEST:
            diamMessage = creatingRequest ? new AccountingRequestImpl(msg) : new AccountingAnswerImpl(msg);
            break;
        case Message.CAPABILITIES_EXCHANGE_REQUEST:
            diamMessage = creatingRequest ? new CapabilitiesExchangeRequestImpl(msg) : new CapabilitiesExchangeAnswerImpl(msg);
            break;
        case Message.DEVICE_WATCHDOG_REQUEST:
            diamMessage = creatingRequest ? new DeviceWatchdogRequestImpl(msg) : new DeviceWatchdogAnswerImpl(msg);
            break;
        case Message.DISCONNECT_PEER_REQUEST:
            diamMessage = creatingRequest ? new DisconnectPeerRequestImpl(msg) : new DisconnectPeerAnswerImpl(msg);
            break;
        case Message.RE_AUTH_REQUEST:
            diamMessage = creatingRequest ? new ReAuthRequestImpl(msg) : new ReAuthAnswerImpl(msg);
            break;
        case Message.SESSION_TERMINATION_REQUEST:
            diamMessage = creatingRequest ? new SessionTerminationRequestImpl(msg) : new SessionTerminationAnswerImpl(msg);
            break;
        default:
            diamMessage = new ExtensionDiameterMessageImpl(msg);
    }
    // Finally, add Origin-Host and Origin-Realm, if not present.
    addOriginHostAndRealm(diamMessage);
    return diamMessage;
}
Also used : DisconnectPeerRequestImpl(org.mobicents.slee.resource.diameter.base.events.DisconnectPeerRequestImpl) AccountingAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AccountingAnswerImpl) Message(org.jdiameter.api.Message) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) ExtensionDiameterMessage(net.java.slee.resource.diameter.base.events.ExtensionDiameterMessage) AbortSessionAnswerImpl(org.mobicents.slee.resource.diameter.base.events.AbortSessionAnswerImpl) AccountingRequestImpl(org.mobicents.slee.resource.diameter.base.events.AccountingRequestImpl) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) ExtensionDiameterMessage(net.java.slee.resource.diameter.base.events.ExtensionDiameterMessage) ExtensionDiameterMessageImpl(org.mobicents.slee.resource.diameter.base.events.ExtensionDiameterMessageImpl) DisconnectPeerAnswerImpl(org.mobicents.slee.resource.diameter.base.events.DisconnectPeerAnswerImpl) ReAuthRequestImpl(org.mobicents.slee.resource.diameter.base.events.ReAuthRequestImpl) AbortSessionRequestImpl(org.mobicents.slee.resource.diameter.base.events.AbortSessionRequestImpl) DeviceWatchdogRequestImpl(org.mobicents.slee.resource.diameter.base.events.DeviceWatchdogRequestImpl) SessionTerminationAnswerImpl(org.mobicents.slee.resource.diameter.base.events.SessionTerminationAnswerImpl) CapabilitiesExchangeRequestImpl(org.mobicents.slee.resource.diameter.base.events.CapabilitiesExchangeRequestImpl) CapabilitiesExchangeAnswerImpl(org.mobicents.slee.resource.diameter.base.events.CapabilitiesExchangeAnswerImpl) ReAuthAnswerImpl(org.mobicents.slee.resource.diameter.base.events.ReAuthAnswerImpl) SessionTerminationRequestImpl(org.mobicents.slee.resource.diameter.base.events.SessionTerminationRequestImpl) DeviceWatchdogAnswerImpl(org.mobicents.slee.resource.diameter.base.events.DeviceWatchdogAnswerImpl)

Example 3 with Message

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

the class DiameterMessageFactoryImpl method createRawMessage.

protected Message createRawMessage(DiameterHeader header, int _commandCode, ApplicationId appId) {
    int commandCode = 0;
    long endToEndId = -1;
    long hopByHopId = -1;
    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, 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) ExtensionDiameterMessage(net.java.slee.resource.diameter.base.events.ExtensionDiameterMessage) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException)

Example 4 with Message

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

the class CreditControlMessageFactoryImpl method createMessage.

public Message createMessage(DiameterHeader header, DiameterAvp[] avps) throws AvpNotAllowedException {
    Message msg = createRawMessage(header);
    AvpSet set = msg.getAvps();
    for (DiameterAvp avp : avps) {
        addAvp(avp, set);
    }
    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) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) AvpSet(org.jdiameter.api.AvpSet)

Example 5 with Message

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

the class GxMessageFactoryImpl method createGxCreditControlAnswer.

public GxCreditControlAnswer createGxCreditControlAnswer(final GxCreditControlRequest request) {
    // Create the answer from the request
    final GxCreditControlRequestImpl ccr = (GxCreditControlRequestImpl) request;
    // final GxCreditControlAnswerImpl msg = new GxCreditControlAnswerImpl(createMessage(ccr.getHeader(), new DiameterAvp[]{}));
    final Message raw = createGxMessage(ccr.getHeader(), new DiameterAvp[] {}, GxCreditControlRequest.commandCode);
    raw.setProxiable(ccr.getHeader().isProxiable());
    raw.setRequest(false);
    // just in case. answers never have T flag set
    raw.setReTransmitted(false);
    final GxCreditControlAnswerImpl msg = new GxCreditControlAnswerImpl(raw);
    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
    final 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 : Message(org.jdiameter.api.Message) GxCreditControlMessage(net.java.slee.resource.diameter.gx.events.GxCreditControlMessage) DiameterMessage(net.java.slee.resource.diameter.base.events.DiameterMessage) GxReAuthMessage(net.java.slee.resource.diameter.gx.events.GxReAuthMessage) DiameterAvp(net.java.slee.resource.diameter.base.events.avp.DiameterAvp) GxCreditControlAnswerImpl(org.mobicents.slee.resource.diameter.gx.events.GxCreditControlAnswerImpl) GxCreditControlRequestImpl(org.mobicents.slee.resource.diameter.gx.events.GxCreditControlRequestImpl) AvpNotAllowedException(net.java.slee.resource.diameter.base.events.avp.AvpNotAllowedException) InternalException(org.jdiameter.api.InternalException) IllegalDiameterStateException(org.jdiameter.api.IllegalDiameterStateException)

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