JBoss.orgCommunity Documentation

Chapter 4. Source Code Overview

4.1. Services descriptor source
4.2. SBB SLEE Facilities access
4.2.1. Initial event selector
4.3. Profile Specification Source
4.3.1. Profile descriptor
4.3.2. Profile interface and management
4.4. Blocking Service Source
4.4.1. Service root
4.4.2. Events handlers
4.4.3. User profile access
4.4.4. Call Blocking SBB descriptor
4.5. Forwarding Service Source
4.5.1. Service root
4.5.2. Events handlers
4.5.3. User status check
4.5.4. Call forwarding
4.5.5. User profile access
4.5.6. Call Forwarding SBB descriptor
4.6. Voice Mail Service Source
4.6.1. Service root
4.6.2. SIP Event handlers
4.6.3. MGCP Event handlers
4.6.4. MGCP signals
4.6.5. Voice Mail profile access
4.6.6. Voice Mail SBB descriptor

Important

To obtain the example's complete source code please refer to Section 2.2, “JBoss Communications JAIN SLEE Call Controller2 Example Source Code”.

Chapter Chapter 3, Design Overview explains top level view of example. This chapter explains how components perform their tasks. For more detailed explanation of JSLEE related source code and xml descriptors, please refer to simpler examples, like sip-wakeup

Each components of Call Controller2 runs as independent service. Each service is defined as follows(in order of priority):

Call Controller2 SBBs access JSLEE facilities in the same way. Code to perform this tasks is generic and gathered in super class for all Call Controller2 SBB classes.

It does following:

Call Controller2 profile specification is not complicated. It is designed only as simple service data container. It does not perform any other tasks.

Profile specification descriptor for Call Controller2 declares following values:

Descriptor look as follows:



<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE profile-spec-jar PUBLIC "-//Sun Microsystems, Inc.//DTD JAIN SLEE Profile Specification 1.1//EN" "http://java.sun.com/dtd/slee-profile-spec-jar_1_1.dtd">
<profile-spec-jar>
    <profile-spec>
        <description />
        <profile-spec-name>CallControlProfileCMP</profile-spec-name>
        <profile-spec-vendor>org.mobicents</profile-spec-vendor>
        <profile-spec-version>0.1</profile-spec-version>
        
        <profile-classes>
            <profile-cmp-interface>
                <profile-cmp-interface-name>
                    org.mobicents.slee.examples.callcontrol.profile.CallControlProfileCMP
                </profile-cmp-interface-name>
                <!-- <profile-index unique="True">userAddress</profile-index>  -->
                <cmp-field>
                <cmp-field-name>userAddress</cmp-field-name>
                    <index-hint query-operator="equals"/>
                </cmp-field>
            </profile-cmp-interface>
            <profile-abstract-class>
                <profile-abstract-class-name>
                    org.mobicents.slee.examples.callcontrol.profile.CallControlProfileManagementImpl
                </profile-abstract-class-name>
            </profile-abstract-class>
        </profile-classes>
        
    </profile-spec>
</profile-spec-jar>
        
        

Profile data can be accessed and modified with profile CMP interface. It is interface exposed to JSLEE components. It is defined as follows:



package org.mobicents.slee.examples.callcontrol.profile;
import javax.slee.Address;
public interface CallControlProfileCMP {
    // 'userAddress' CMP field setter
    public abstract void setUserAddress(Address value);
    // 'userAddress' CMP field getter
    public abstract Address getUserAddress();
    // 'blockedAddresses' CMP field setter
    public abstract void setBlockedAddresses(Address[] value);
    // 'blockedAddresses' CMP field getter
    public abstract Address[] getBlockedAddresses();
    // 'backupAddress' CMP field setter
    public abstract void setBackupAddress(Address value);
    // 'backupAddress' CMP field getter
    public abstract Address getBackupAddress();
    // 'voicemailState' CMP field setter
    public abstract void setVoicemailState(boolean value);
    // 'voicemailState' CMP field getter
    public abstract boolean getVoicemailState();
}
        

Profile abstract class implements custom logic to handle profile data and JSLEE callback methods for management operations. This class becomes part of profile object implementation. It allows to control some aspects of profile and its data.

Call Controller2 profile abstract class performs following operations:

It is defined as follows:



import javax.slee.Address;
import javax.slee.AddressPlan;
import javax.slee.CreateException;
import javax.slee.profile.Profile;
import javax.slee.profile.ProfileContext;
import javax.slee.profile.ProfileVerificationException;
public abstract class CallControlProfileManagementImpl implements Profile,
        CallControlProfileCMP {
    private ProfileContext profileCtx;
    /**
     * Initialize the profile with its default values.
     */
    public void profileInitialize() {
        setUserAddress(null);
        setBlockedAddresses(null);
        setBackupAddress(null);
        setVoicemailState(false);
    }
    public void profileLoad() {
    }
    public void profileStore() {
    }
    /**
     * Verify the profile's CMP field settings.
     * 
     * @throws ProfileVerificationException
     *             if any CMP field contains an invalid value
     */
    public void profileVerify() throws ProfileVerificationException {
        // Verify Called User Address
        Address address = getUserAddress();
        if (address != null)
            verifyAddress(address);
        // Verify Blocked Addresses
        Address[] blockedAddresses = getBlockedAddresses();
        if (blockedAddresses != null) {
            for (int i = 0; i < blockedAddresses.length; i++) {
                if (blockedAddresses[i] != null)
                    verifyAddress(blockedAddresses[i]);
            }
        }
        // Verify Backup Address
        Address backupAddress = getBackupAddress();
        if (backupAddress != null)
            verifyAddress(backupAddress);
    }
    public void verifyAddress(Address address)
            throws ProfileVerificationException {
        // Check address plan
        if (address.getAddressPlan() != AddressPlan.SIP)
            throw new ProfileVerificationException("Address \"" + address
                    + "\" is not a SIP address");
        // Check URI scheme - must be sip: or sips:
        String uri = address.getAddressString().toLowerCase();
        if (!(uri.startsWith("sip:") || uri.startsWith("sips:")))
            throw new ProfileVerificationException("Address \"" + address
                    + "\" is not a SIP address");
    }
    public void profileActivate() {
    }
    public void profilePassivate() {
    }
    public void profilePostCreate() throws CreateException {
    }
    public void profileRemove() {
    }
    public void setProfileContext(ProfileContext ctx) {
        this.profileCtx = ctx;
    }
    public void unsetProfileContext() {
        this.profileCtx = null;
    }
}
        

Blocking service is simplest of services in Call Controller2

It processes incoming SIP INVITE request and based on callee and caller denies or allows call to happen.

Call blocking service receives only one event: SIP INVITE request. Its responsibility is:

It is defined as follows:



    public void onInvite(javax.sip.RequestEvent event, 
            CallBlockingSbbActivityContextInterface localAci) {
        Request request = event.getRequest();
        try {
            localAci.detach(this.getSbbLocalObject());
            
            FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
            ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
            // From URI
            URI fromURI = fromHeader.getAddress().getURI();
            // To URI
            URI toURI = toHeader.getAddress().getURI();
            // In the Profile Table the port is not used
            ((SipURI)fromURI).removePort();
            ((SipURI)toURI).removePort();
            
            ArrayList targets = getBlockedArrayList(toURI.toString());
                        
            if (targets != null) {
                // Cheking whether the caller is blocked by the called user
                for (int i = 0; i < targets.size(); i++) {
                    if ((targets.get(i).toString()).equalsIgnoreCase(fromURI.toString())) {
                        log.info("########## BLOCKING ADDRESS: " + targets.get(i));
                        log.info("########## BLOCKING FOR URI: " + toURI);
                        localAci.setFilteredByMe(true);
                        // Notifiying the client that the INVITE has been blocked
                        ServerTransaction stBlocking = (ServerTransaction) localAci.getActivity();
                        Response blockingResponse = getMessageFactory().createResponse(
                                Response.FORBIDDEN, request);
                        stBlocking.sendResponse(blockingResponse);
                    }
                }
            }
        } catch (TransactionRequiredLocalException e) {
            log.error(e.getMessage(), e);
        } catch (SLEEException e) {
            log.error(e.getMessage(), e);
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        } catch (SipException e) {
            log.error(e.getMessage(), e);
        } catch (InvalidArgumentException e) {
            log.error(e.getMessage(), e);
        }
    }
        

Call Blocking SBB accesses examples profile in order to determine if callee has defined caller as blocked.

Profile is accessed in following way:



public abstract class CallBlockingSbb extends 
    SubscriptionProfileSbb implements   javax.slee.Sbb
{
   ...
    /**
     * Attempt to find a list of Blocked Addresses (SIP URIs), but the method
     * returns null if the called user (sipAddress) does not block to any user.
     */
    private ArrayList getBlockedArrayList(String sipAddress) {
        //sipAddress is AOR: sip:newbie@mobicents.org
        ArrayList uris = null;
        CallControlProfileCMP profile = super.lookup(new Address(AddressPlan.SIP,
                sipAddress));
        if (profile != null) {
            Address[] addresses = profile.getBlockedAddresses();
            if (addresses != null) {
                uris = new ArrayList(addresses.length);
                for (int i = 0; i < addresses.length; i++) {
                    String address = addresses[i].getAddressString();
                    try {
                        SipURI uri = (SipURI) getAddressFactory().createURI(address);
                        uris.add(uri);
                    } catch (ParseException e) {
                        log.error(e.getMessage(), e);
                    }
                }
            }
        }
        return uris;
    }
}
        

Descriptor contains following definitions:



    <sbb>
        <description />
        <sbb-name>CallBlockingSbb</sbb-name>
        <sbb-vendor>org.mobicents</sbb-vendor>
        <sbb-version>0.1</sbb-version>

        
        <profile-spec-ref>
            <profile-spec-name>CallControlProfileCMP</profile-spec-name>
            <profile-spec-vendor>org.mobicents</profile-spec-vendor>
            <profile-spec-version>0.1</profile-spec-version>
            <profile-spec-alias>CallControlProfile</profile-spec-alias>
        </profile-spec-ref>
        
        <sbb-classes>
            <sbb-abstract-class>
                <sbb-abstract-class-name>
                    org.mobicents.slee.examples.callcontrol.blocking.CallBlockingSbb
                </sbb-abstract-class-name>
            </sbb-abstract-class>
            <sbb-activity-context-interface>
                <sbb-activity-context-interface-name>
                    org.mobicents.slee.examples.callcontrol.blocking.CallBlockingSbbActivityContextInterface
                </sbb-activity-context-interface-name>
            </sbb-activity-context-interface>
        </sbb-classes>
        
        
        
        <event event-direction="Receive" initial-event="True">
            <event-name>Invite</event-name>
            <event-type-ref>
                <event-type-name>javax.sip.message.Request.INVITE</event-type-name>
                <event-type-vendor>net.java.slee</event-type-vendor>
                <event-type-version>1.2</event-type-version>
            </event-type-ref>
            <initial-event-selector-method-name>callIDSelect</initial-event-selector-method-name>
        </event>
        
        <activity-context-attribute-alias>
            <attribute-alias-name>inviteFilteredByCallBlocking</attribute-alias-name>
            <sbb-activity-context-attribute-name>filteredByMe</sbb-activity-context-attribute-name>
        </activity-context-attribute-alias>
        
        <resource-adaptor-type-binding>
            <resource-adaptor-type-ref>
                <resource-adaptor-type-name>JAIN SIP</resource-adaptor-type-name>
                <resource-adaptor-type-vendor>javax.sip</resource-adaptor-type-vendor>
                <resource-adaptor-type-version>1.2</resource-adaptor-type-version>
            </resource-adaptor-type-ref>
            <activity-context-interface-factory-name>slee/resources/jainsip/1.2/acifactory</activity-context-interface-factory-name>
            <resource-adaptor-entity-binding>
                <resource-adaptor-object-name>slee/resources/jainsip/1.2/provider</resource-adaptor-object-name>
                <resource-adaptor-entity-link>SipRA</resource-adaptor-entity-link>
            </resource-adaptor-entity-binding>
        </resource-adaptor-type-binding>
    </sbb>
        
        

Forwarding service is simple illustration of call forwarding logic.

It processes incoming SIP INVITE request and based on callee availability permits call to proceed or redirects to backup address if it exists. Its a bit more complicated than Section 4.4, “Blocking Service Source” service as it:

  • uses location service to determine availability of user

  • uses proxy service to rely messages to proper target

CallForwardingSbb performs all its tasks in INVITE event handler. That is:

Event handler code look as follows:



    public void onInvite(javax.sip.RequestEvent event
        , CallForwardingSbbActivityContextInterface localAci) {
        Request request;
        try {
            localAci.detach(this.getSbbLocalObject());
            if (localAci.getFilteredByAncestor()) {
                log.info("########## CALL FORWARDING SBB: FILTERED BY ANCESTOR ##########");
                // Next in chain has to know that someone is looking after
                // message
                localAci.setFilteredByMe(true);
                // If it was not set, every change in the chain of services will
                // extort source change in service lower in chain...
                return;
            }
            request = event.getRequest();
            // ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
            // URI toURI = toHeader.getAddress().getURI();
            URI toURI = event.getRequest().getRequestURI();
            URI contactURI = isUserAvailable(toURI);
            if (contactURI != null) {
                // USER IS AVAILABLE
                localAci.setFilteredByMe(true);
                log.info("########## User " + toURI + " is available with contact " + contactURI);
                // Create proxy child SBB
                ChildRelation ProxyRelation = getJainSipProxySbb();
                SbbLocalObject ProxyChild = ProxyRelation.create();
                // Attach ProxyChild to the activity
                // Event router will pass this event to child SBB,
                // which in this case is the Proxy SBB. It will in turn proxy
                // the request to the callee.
                localAci.attach(ProxyChild);
                return;
            } else {
                log.info("########## User " + toURI + " is not available, not forwarding");
            }
        } catch (SipSendErrorResponseException e) {
            log.error(e.getMessage(), e);
        } catch (CreateException e) {
            log.error(e.getMessage(), e);
        }
        // IF WE GOT HERE IT MEANS THAT USER IS NOT AVAILABLE AND SBB HIGHER IN
        // CHAIN DID NOT FILTER INVITE.
        // WE HAVE TO FIND NEW ADDRESS... OR LEAVE INVITE TO BE PROCESSED BY
        // NEXT SBB IN CHAIN.
        Address add = forwardCall(event, localAci);
        if (add != null) {
            // INVITE WAS FORWARDED
            // let the next service in the chain know that the event was
            // processed here.
            localAci.setFilteredByMe(true);
        }
        // LET NEXT CHAINED SBB TAKE CARE OF INVITE.
        return;
    }
        

CallForwardingSbb depends on location service to check if user is online. Example checks entries in registrar for callees AOR. Registrar stores bindinings in form of mapping: AOR - {ContactAddress-BindingData,...}

Registrar entries are inspected in following way:



    private URI isUserAvailable(URI uri) throws SipSendErrorResponseException {
        String addressOfRecord = uri.toString();
        URI target = null;
        Map bindings = null;
        try {
            bindings = getLocationSbb().getBindings(addressOfRecord);
        } catch (LocationServiceException e) {
            log.error(e.getMessage(), e);
        } catch (TransactionRequiredLocalException e) {
            log.error(e.getMessage(), e);
        } catch (SLEEException e) {
            log.error(e.getMessage(), e);
        } catch (CreateException e) {
            log.error(e.getMessage(), e);
        }
        if (bindings != null & !bindings.isEmpty()) {
            Iterator it = bindings.values().iterator();
            while (it.hasNext()) {
                RegistrationBinding binding = (RegistrationBinding) it.next();
                log.info("########## BINDINGS: " + binding);
                ContactHeader header = null;
                try {
                    header = getHeaderFactory().createContactHeader(
                        getAddressFactory().createAddress(binding.getContactAddress()));
                } catch (ParseException e) {
                    log.error(e.getMessage(), e);
                }
                log.info("########## CONTACT HEADER: " + header);
                if (header == null) { // entry expired
                    continue; // see if there are any more contacts...
                }
                Address na = header.getAddress();
                log.info("isUserAvailable Address: " + na);
                target = na.getURI();
                break;
            }
            if (target == null) {
                log.error("findLocalTarget: No contacts for " + addressOfRecord + " found.");
                throw new SipSendErrorResponseException("User temporarily unavailable",
                        Response.TEMPORARILY_UNAVAILABLE);
            }
        }
        return target;
    }
        

Call is beeing forwarded in case user is not logged in - that is registrar does not have binding for user AOR.

Forward operation is performed by means of SIP 3XX response class. Example sends response with code 302 and backup address as contact. It is done as follows:



protected Address forwardCall(javax.sip.RequestEvent event, ActivityContextInterface ac) {
    Address toAddress = null;
    Request request = event.getRequest();
    try {
        // Checking if the called user has any backup address
        ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
        String toURI = toHeader.getAddress().getURI().toString();
        Address backupAddress = getBackupAddress(toURI);
        
        if (backupAddress != null) {
            // Checking whether the called user has any backup address.
            toAddress = getAddressFactory().createAddress(backupAddress.toString());
            // Notifying the caller that the call has to be redirected
            ServerTransaction st = (ServerTransaction) ac.getActivity();
            ContactHeader contactHeader = getHeaderFactory()
                .createContactHeader(toAddress);
            Response response = getMessageFactory().createResponse(
                Response.MOVED_TEMPORARILY, request);
            response.setHeader(contactHeader);
            st.sendResponse(response);
            log.info("########## REQUEST FORWARDED: " + contactHeader.toString());
            // The Request-URI of the new request uses the value
            // of the Contact header field in the response
        }
    } catch (ParseException e) {
        log.error(e.getMessage(), e);
    } catch (TransactionRequiredLocalException e) {
        log.error(e.getMessage(), e);
    } catch (SLEEException e) {
        log.error(e.getMessage(), e);
    } catch (SipException e) {
        log.error(e.getMessage(), e);
    } catch (InvalidArgumentException e) {
        log.error(e.getMessage(), e);
    }
    return toAddress;
}
            

Descriptor contains following definitions:



    <sbb>
        <description />
        <sbb-name>CallForwardingSbb</sbb-name>
        <sbb-vendor>org.mobicents</sbb-vendor>
        <sbb-version>0.1</sbb-version>

        <sbb-ref>
            <sbb-name>ProxySbb</sbb-name>
            <sbb-vendor>mobicents</sbb-vendor>
            <sbb-version>1.1</sbb-version>
            <sbb-alias>JainSipProxySbb</sbb-alias>
        </sbb-ref>
        <sbb-ref>
            <sbb-name>LocationSbb</sbb-name>
            <sbb-vendor>org.mobicents</sbb-vendor>
            <sbb-version>1.2</sbb-version>
            <sbb-alias>LocationSbb</sbb-alias>
        </sbb-ref>
        <profile-spec-ref>
            <profile-spec-name>CallControlProfileCMP</profile-spec-name>
            <profile-spec-vendor>org.mobicents</profile-spec-vendor>
            <profile-spec-version>0.1</profile-spec-version>
            <profile-spec-alias>CallControlProfile</profile-spec-alias>
        </profile-spec-ref>
        
        <sbb-classes>
            <sbb-abstract-class>
                <sbb-abstract-class-name>
                    org.mobicents.slee.examples.callcontrol.forwarding.CallForwardingSbb
                </sbb-abstract-class-name>

                <cmp-field>
                    <cmp-field-name>locationSbbCMP</cmp-field-name>
                </cmp-field>

                <get-child-relation-method>
                    <sbb-alias-ref>JainSipProxySbb</sbb-alias-ref>
                    <get-child-relation-method-name>
                        getJainSipProxySbb
                    </get-child-relation-method-name>
                    <default-priority>0</default-priority>
                </get-child-relation-method>
                <get-child-relation-method>
                    <sbb-alias-ref>LocationSbb</sbb-alias-ref>
                    <get-child-relation-method-name>
                        getLocationSbbChildRelation
                    </get-child-relation-method-name>
                    <default-priority>0</default-priority>
                </get-child-relation-method>
            </sbb-abstract-class>
            <sbb-activity-context-interface>
                <sbb-activity-context-interface-name>
                    org.mobicents.slee.examples.callcontrol.forwarding.CallForwardingSbbActivityContextInterface
                </sbb-activity-context-interface-name>
            </sbb-activity-context-interface>
        </sbb-classes>
        <address-profile-spec-alias-ref>
            CallControlProfile
        </address-profile-spec-alias-ref>
        
        
        <event event-direction="Receive" initial-event="True">
            <event-name>Invite</event-name>
            <event-type-ref>
                    <event-type-name>javax.sip.message.Request.INVITE</event-type-name>
                    <event-type-vendor>net.java.slee</event-type-vendor>
                    <event-type-version>1.2</event-type-version>
            </event-type-ref>
            <initial-event-selector-method-name>
                callIDSelect
            </initial-event-selector-method-name>
        </event>

        
        <activity-context-attribute-alias>
            <attribute-alias-name>
                inviteFilteredByCallBlocking
            </attribute-alias-name>
            <sbb-activity-context-attribute-name>
                filteredByAncestor
            </sbb-activity-context-attribute-name>
        </activity-context-attribute-alias>
        <activity-context-attribute-alias>
            <attribute-alias-name>
                inviteFilteredByCallForwarding
            </attribute-alias-name>
            <sbb-activity-context-attribute-name>
                filteredByMe
            </sbb-activity-context-attribute-name>
        </activity-context-attribute-alias>
        
        <resource-adaptor-type-binding>
            <resource-adaptor-type-ref>
                <resource-adaptor-type-name>
                    JAIN SIP
                </resource-adaptor-type-name>
                <resource-adaptor-type-vendor>
                    javax.sip
                </resource-adaptor-type-vendor>
                <resource-adaptor-type-version>
                    1.2
                </resource-adaptor-type-version>
            </resource-adaptor-type-ref>
            <activity-context-interface-factory-name>
                slee/resources/jainsip/1.2/acifactory
            </activity-context-interface-factory-name>
            <resource-adaptor-entity-binding>
                <resource-adaptor-object-name>
                    slee/resources/jainsip/1.2/provider
                </resource-adaptor-object-name>
                <resource-adaptor-entity-link>
                    SipRA
                </resource-adaptor-entity-link>
            </resource-adaptor-entity-binding>
        </resource-adaptor-type-binding>
    </sbb>
        
        

Voice mail service illustrates usage of MGCP protocol to control Media Server. It is capable of following:

SIP are more complicated as they more complicated tasks including MGCP signaling and SDP negotiation.

VoiceMailSbb defines two handlers for SIP.

INVITE event handler performs following tasks:

Handler is defined as follows:



    public void onInvite(javax.sip.RequestEvent event,
            VoiceMailSbbActivityContextInterface localAci) {
        Response response;
        log.info("########## VOICE MAIL SBB: INVITE ##########");
        // Request
        Request request = event.getRequest();
        // Setting Request
        this.setInviteRequest(request);
        // Server Transaction
        ServerTransaction st = event.getServerTransaction();
        try {
            if (localAci.getFilteredByAncestor()) {
                log
                        .info("########## VOICE MAIL SBB: FILTERED BY ANCESTOR ##########");
                return;
            }
            // if we are calling to vmail this means we want to check our mail
            // box
            // sameUser = true
            boolean sameUser = sameUser(event);
            URI uri;
            if (sameUser) {
                // The user is the caller
                FromHeader fromHeader = (FromHeader) request
                        .getHeader(FromHeader.NAME);
                uri = fromHeader.getAddress().getURI();
            } else {
                // The user is the callee - we are calling someone else
                ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
                uri = toHeader.getAddress().getURI();
            }
            // In the Profile Table the port is not used
            ((SipURI) uri).removePort();
            // Responding to the user
            // To know whether the user has the Voice mail service enabled
            boolean isSubscriber = isSubscriber(uri.toString());
            if (isSubscriber) {
                // Formalities of sip, so we dont get retrans
                // Attaching to SIP Dialog activity
                Dialog dial = getSipFactoryProvider().getNewDialog(
                        (Transaction) st);
                ActivityContextInterface dialogAci = sipACIF
                        .getActivityContextInterface((DialogActivity) dial);
                // attach this SBB object to the Dialog activity to receive
                // subsequent events on this Dialog
                dialogAci.attach(this.getSbbLocalObject());
                // Notify caller that we're TRYING to reach voice mail. Just a
                // formality, we know we can go further than TRYING at this
                // point
                response = getMessageFactory().createResponse(Response.TRYING,
                        request);
                st.sendResponse(response);
                // RINGING. Another formality of the SIP protocol.
                response = getMessageFactory().createResponse(Response.RINGING,
                        request);
                st.sendResponse(response);
                String sdp = new String(event.getRequest().getRawContent());
                CallIdentifier callID = this.mgcpProvider
                        .getUniqueCallIdentifier();
                // this is not requiered, but to be good MGCP citizen we will
                // obey mgcp call id rule.
                setCallIdentifier(callID);
                EndpointIdentifier endpointID = new EndpointIdentifier(
                        PRE_ENDPOINT_NAME, mmsBindAddress + ":"
                                + MGCP_PEER_PORT);
                CreateConnection createConnection = new CreateConnection(this,
                        callID, endpointID, ConnectionMode.SendRecv);
                try {
                    createConnection
                            .setRemoteConnectionDescriptor(new ConnectionDescriptor(
                                    sdp));
                } catch (ConflictingParameterException e) {
                    e.printStackTrace();
                }
                int txID = mgcpProvider.getUniqueTransactionHandler();
                createConnection.setTransactionHandle(txID);
                MgcpConnectionActivity connectionActivity = null;
                try {
                    connectionActivity = mgcpProvider.getConnectionActivity(
                            txID, endpointID);
                    ActivityContextInterface epnAci = mgcpActivityContestInterfaceFactory
                            .getActivityContextInterface(connectionActivity);
                    epnAci.attach(getSbbContext().getSbbLocalObject());
                } catch (FactoryException ex) {
                    ex.printStackTrace();
                } catch (NullPointerException ex) {
                    ex.printStackTrace();
                } catch (UnrecognizedActivityException ex) {
                    ex.printStackTrace();
                }
                mgcpProvider
                        .sendMgcpEvents(new JainMgcpEvent[] { createConnection });
                log
                        .info("########## VOICE MAIL AVAILABLE FOR USER: sent PR CRCX request ##########");
            } else {
                // Voice Mail service disabled
                response = getMessageFactory().createResponse(
                        Response.TEMPORARILY_UNAVAILABLE, request);
                log.info("########## NO VOICE MAIL AVAILABLE FOR USER: "
                        + uri.toString());
                st.sendResponse(response);
            }
        } catch (TransactionRequiredLocalException e) {
            log.error(e.getMessage(), e);
        } catch (SLEEException e) {
            log.error(e.getMessage(), e);
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        } catch (SipException e) {
            log.error(e.getMessage(), e);
        } catch (InvalidArgumentException e) {
            log.error(e.getMessage(), e);
        } catch (NullPointerException e) {
            log.error(e.getMessage(), e);
        }
    }
            

For details on MGCP protocol please refer to:

  • RFC3435

  • mgcp-demo documentation

  • MGCP RA documentation

This event is received as answer to CRCX request. Voice Mail receives this in two cases:

It performs following task:

Handler is defined as follows:



public void onCreateConnectionResponse(CreateConnectionResponse event,
        ActivityContextInterface aci) {
    log.info("Receive CRCX response: " + event);
    ReturnCode status = event.getReturnCode();
    switch (status.getValue()) {
    case ReturnCode.TRANSACTION_EXECUTED_NORMALLY:
        log.info("Connection created properly.");
        break;
    default:
        ReturnCode rc = event.getReturnCode();
        log.error("CRCX failed. Value = " + rc.getValue() + " Comment = "
                + rc.getComment());
        sendServerError("Failed to create connection, code: "
                    + event.getReturnCode(), Response.SERVER_INTERNAL_ERROR);
        return;
    }
    boolean startMailMedia = false;
    if (event.getSecondEndpointIdentifier() == null) {
        // this is response for PR creation
        // we have one connection activity, lets send another crcx
        // send OK with sdp
        DialogActivity da = getDialogActivity();
        ServerTransaction txn = getServerTransaction();
        if (txn == null) {
            log.error("SIP activity lost, close RTP connection");
            releaseState();
            return;
        }
        Request request = txn.getRequest();
        ContentTypeHeader contentType = null;
        try {
            contentType = getHeaderFactory().createContentTypeHeader("application", "sdp");
        } catch (ParseException ex) {
        }
        String localAddress = getSipFactoryProvider().getListeningPoints()[0].getIPAddress();
        int localPort = getSipFactoryProvider().getListeningPoints()[0].getPort();
        javax.sip.address.Address contactAddress = null;
        try {
            contactAddress = getAddressFactory().createAddress(
                "sip:" + localAddress + ":" + localPort);
        } catch (ParseException ex) {
            log.error(ex.getMessage(), ex);
        }
        ContactHeader contact = getHeaderFactory()
            .createContactHeader(contactAddress);
        Response response = null;
        try {
            response = getMessageFactory().createResponse(
                Response.OK, request, contentType, 
                event.getLocalConnectionDescriptor().toString().getBytes());
        } catch (ParseException ex) {
        }
        response.setHeader(contact);
        try {
            txn.sendResponse(response);
        } catch (InvalidArgumentException ex) {
            log.error(ex.getMessage(), ex);
        } catch (SipException ex) {
            log.error(ex.getMessage(), ex);
        }
        EndpointIdentifier endpointID = new EndpointIdentifier(
                IVR_ENDPOINT_NAME, mmsBindAddress + ":" + MGCP_PEER_PORT);
        CreateConnection createConnection = new CreateConnection(this,
                getCallIdentifier(), endpointID, ConnectionMode.SendRecv);
        int txID = mgcpProvider.getUniqueTransactionHandler();
        createConnection.setTransactionHandle(txID);
        // now set other end
        try {
            createConnection.setSecondEndpointIdentifier(event
                    .getSpecificEndpointIdentifier());
        } catch (ConflictingParameterException e) {
            e.printStackTrace();
        }
        MgcpConnectionActivity connectionActivity = null;
        try {
            connectionActivity = mgcpProvider.getConnectionActivity(txID,
                    endpointID);
            ActivityContextInterface epnAci = mgcpActivityContestInterfaceFactory
                    .getActivityContextInterface(connectionActivity);
            epnAci.attach(getSbbContext().getSbbLocalObject());
            // epnAci.attach(getParentCmp());
        } catch (FactoryException ex) {
            ex.printStackTrace();
        } catch (NullPointerException ex) {
            ex.printStackTrace();
        } catch (UnrecognizedActivityException ex) {
            ex.printStackTrace();
        }
        mgcpProvider
                .sendMgcpEvents(new JainMgcpEvent[] { createConnection });
    } else {
        // this is last
        startMailMedia = true;
    }
    EndpointIdentifier eid = event.getSpecificEndpointIdentifier();
    log.info("Creating endpoint activity on: " + eid);
    MgcpEndpointActivity eActivity = mgcpProvider.getEndpointActivity(eid);
    ActivityContextInterface eAci = mgcpActivityContestInterfaceFactory
            .getActivityContextInterface(eActivity);
    eAci.attach(this.getSbbContext().getSbbLocalObject());
    if (startMailMedia) {
        startMailMedia();
    }
}
            

This event is received as result of requested notification - Voice Mail requests to be notified on certain conditions.

Depending on observed event type, handler performs different action.

Handler is defined as follows:



public void onNotifyRequest(Notify event, ActivityContextInterface aci) {
    NotifyResponse response = new NotifyResponse(event.getSource(),
            ReturnCode.Transaction_Executed_Normally);
    response.setTransactionHandle(event.getTransactionHandle());
    log.info("########## VOICE MAIL SBB: Sending Notify response["+response+"] to ["+event+"]["+event.getTransactionHandle()+"] ["+response.getTransactionHandle()+"]##########");
        
    mgcpProvider.sendMgcpEvents(new JainMgcpEvent[] { response });
        
    EventName[] observedEvents = event.getObservedEvents();
    for (EventName observedEvent : observedEvents) {
        switch (observedEvent.getEventIdentifier().intValue()) {
        case MgcpEvent.REPORT_ON_COMPLETION:
            log.info("########## VOICE MAIL SBB: Signal completed, event identifier["+observedEvent.getEventIdentifier()+"] ##########");
            
            if(observedEvent.getEventIdentifier().toString().equals("oc"))
            {
                onAnnouncementComplete();
            }
                
            break;
        case MgcpEvent.REPORT_FAILURE:
            log.info("########## VOICE MAIL SBB: Signal failed, event identifier["+observedEvent.getEventIdentifier()+"] ##########");
            //releaseState();
            sendByeRequest();
            break;
        
        case MgcpEvent.DTMF_1:
            this.checkDtmfDigit("1");
            break;
        case MgcpEvent.DTMF_7:
            this.checkDtmfDigit("7");
            break;
        case MgcpEvent.DTMF_9:
            this.checkDtmfDigit("9");
            break;
            
        default:
            log.info("########## VOICE MAIL SBB: Notify on unknown event, event identifier["+observedEvent.getEventIdentifier()+"]identifier["+observedEvent.getEventIdentifier().intValue()+"] ##########");
            break;
        }
            
    }
}
            

VoiceMailSbb sends request to media server in order to trigger media play or record. It also requests to be notified on certain events:

It sends MGCP Notification Request with signals(play or record) to be applied and events to be detected.

Notification Request is built as follows:



    public void sendRQNT(String audioFileUrl, boolean record, boolean detectDtmf) {
        MgcpEndpointActivity endpointActivity = getEndpointActivity("IVR");
        if (endpointActivity == null) {
            // bad practice
            throw new RuntimeException("There is no IVR endpoint activity");
        }
        MgcpConnectionActivity connectionActivity = getConnectionActivity(endpointActivity
                .getEndpointIdentifier());
        if (connectionActivity == null) {
            // bad practice
            throw new RuntimeException(
                    "There is no IVR connection activity");
        }
        EndpointIdentifier endpointID = endpointActivity
                .getEndpointIdentifier();
        ConnectionIdentifier connectionID = new ConnectionIdentifier(
                connectionActivity.getConnectionIdentifier());
        NotificationRequest notificationRequest = new NotificationRequest(this,
                endpointID, mgcpProvider.getUniqueRequestIdentifier());
        RequestedAction[] actions = new RequestedAction[] { RequestedAction.NotifyImmediately };
        
        
        if (audioFileUrl != null) {
            EventName[] signalRequests = null;
            if (!record) {
                signalRequests = new EventName[] { new EventName(
                        PackageName.Announcement, MgcpEvent.ann
                                .withParm(audioFileUrl),connectionID) };
            } else {
                signalRequests = new EventName[] { new EventName(AUPackage.AU,
                        AUMgcpEvent.aupr.withParm(audioFileUrl), connectionID) };
            }
            notificationRequest.setSignalRequests(signalRequests);
            
            //add notification, in case dtmf part is not included
            RequestedEvent[] requestedEvents = {
                    new RequestedEvent(new EventName(PackageName.Announcement
                        , MgcpEvent.oc,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Announcemen
                        t, MgcpEvent.of,connectionID), actions),
                     };
            notificationRequest.setRequestedEvents(requestedEvents);
        }
        
        if (detectDtmf) {
            
            
            
            // This has to be present, since MGCP states that new RQNT erases
            // previous set.
            RequestedEvent[] requestedEvents = {
                    new RequestedEvent(new EventName(PackageName.Announcement
                        , MgcpEvent.oc,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Announcement
                        , MgcpEvent.of,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf0,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf1,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf2,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf3,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf4,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf5,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf6,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf7,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf8,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmf9,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmfA,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmfB,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmfC,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmfD,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmfStar,connectionID), actions),
                    new RequestedEvent(new EventName(PackageName.Dtmf,
                            MgcpEvent.dtmfHash,connectionID), actions) };
            notificationRequest.setRequestedEvents(requestedEvents);
        }
        notificationRequest.setTransactionHandle(mgcpProvider
                .getUniqueTransactionHandler());
        NotifiedEntity notifiedEntity = new NotifiedEntity(JBOSS_BIND_ADDRESS,
                JBOSS_BIND_ADDRESS, MGCP_PORT);
        notificationRequest.setNotifiedEntity(notifiedEntity);
        // we can send empty RQNT, that is clean all req.
        mgcpProvider
                .sendMgcpEvents(new JainMgcpEvent[] { notificationRequest });
        log.info(" NotificationRequest sent: \n" + notificationRequest);
    }
          

Descriptor contains following definitions:



     <sbb>
        <description />
        <sbb-name>VoiceMailSbb</sbb-name>
        <sbb-vendor>org.mobicents</sbb-vendor>
        <sbb-version>0.1</sbb-version>

        <profile-spec-ref>
            <profile-spec-name>CallControlProfileCMP</profile-spec-name>
            <profile-spec-vendor>org.mobicents</profile-spec-vendor>
            <profile-spec-version>0.1</profile-spec-version>
            <profile-spec-alias>CallControlProfile</profile-spec-alias>
        </profile-spec-ref>
        <sbb-classes>
            <sbb-abstract-class>
                <sbb-abstract-class-name>
                    org.mobicents.slee.examples.callcontrol.voicemail.VoiceMailSbb
                </sbb-abstract-class-name>
                <cmp-field>
                    <cmp-field-name>inviteRequest</cmp-field-name>
                </cmp-field>
                <cmp-field>
                    <cmp-field-name>callIdentifier</cmp-field-name>
                </cmp-field>
                <cmp-field>
                    <cmp-field-name>sameUser</cmp-field-name>
                </cmp-field>
            </sbb-abstract-class>
            <sbb-activity-context-interface>
                <sbb-activity-context-interface-name>
                    org.mobicents.slee.examples.callcontrol.voicemail.VoiceMailSbbActivityContextInterface
                </sbb-activity-context-interface-name>
            </sbb-activity-context-interface>
        </sbb-classes>

        <event event-direction="Receive" initial-event="True">
            <event-name>Invite</event-name>
            <event-type-ref>
                <event-type-name>javax.sip.message.Request.INVITE</event-type-name>
                <event-type-vendor>net.java.slee</event-type-vendor>
                <event-type-version>1.2</event-type-version>
            </event-type-ref>
            <initial-event-selector-method-name>
                callIDSelect
            </initial-event-selector-method-name>
        </event>

        <event event-direction="Receive" initial-event="False">
            <event-name>ByeEvent</event-name>
            <event-type-ref>
                <event-type-name>javax.sip.Dialog.BYE</event-type-name>
                <event-type-vendor>net.java.slee</event-type-vendor>
                <event-type-version>1.2</event-type-version>
            </event-type-ref>
        </event>
        <!-- MGCP events  -->
        <event event-direction="Receive" initial-event="False">
            <event-name>NotificationRequestResponse</event-name>
            <event-type-ref>
                <event-type-name>
                    net.java.slee.resource.mgcp.NOTIFICATION_REQUEST_RESPONSE
                </event-type-name>
                <event-type-vendor>net.java</event-type-vendor>
                <event-type-version>1.0</event-type-version>
            </event-type-ref>
        </event>

        <event event-direction="Receive" initial-event="False">
            <event-name>NotifyRequest</event-name>
            <event-type-ref>
                <event-type-name>
                    net.java.slee.resource.mgcp.NOTIFY
                </event-type-name>
                <event-type-vendor>net.java</event-type-vendor>
                <event-type-version>1.0</event-type-version>
            </event-type-ref>
        </event>
        <event event-direction="Receive" initial-event="False">
            <event-name>CreateConnectionResponse</event-name>
            <event-type-ref>
                <event-type-name>
                    net.java.slee.resource.mgcp.CREATE_CONNECTION_RESPONSE
                </event-type-name>
                <event-type-vendor>net.java</event-type-vendor>
                <event-type-version>1.0</event-type-version>
            </event-type-ref>
        </event>


        <event event-direction="Receive" initial-event="False">
            <event-name>ActivityEndEvent</event-name>
            <event-type-ref>
                <event-type-name>javax.slee.ActivityEndEvent</event-type-name>
                <event-type-vendor>javax.slee</event-type-vendor>
                <event-type-version>1.0</event-type-version>
            </event-type-ref>
        </event>

        <activity-context-attribute-alias>
            <attribute-alias-name>
                inviteFilteredByCallForwarding
            </attribute-alias-name>
            <sbb-activity-context-attribute-name>
                filteredByAncestor
            </sbb-activity-context-attribute-name>
        </activity-context-attribute-alias>
        <env-entry>
            <description>
                This is the path where the recorded files will reside.
                it is part of record/announce path. Full path is comined as follows:
                ${MOBICENTS_SLEE_EXAMPLE_CC2_RECORDINGS_HOME}/${filesRoute}.
            </description>
            <env-entry-name>filesRoute</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>${files.route}</env-entry-value>
        </env-entry>
        <env-entry>
            <description>This is the IP address of media server 
             to which MGCP requests are sent</description>
            <env-entry-name>server.address</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>${server.address}</env-entry-value>
        </env-entry>
        <resource-adaptor-type-binding>
            <resource-adaptor-type-ref>
                <resource-adaptor-type-name>
                    JAIN SIP
                </resource-adaptor-type-name>
                <resource-adaptor-type-vendor>
                    javax.sip
                </resource-adaptor-type-vendor>
                <resource-adaptor-type-version>
                    1.2
                </resource-adaptor-type-version>
            </resource-adaptor-type-ref>
            <activity-context-interface-factory-name>
                slee/resources/jainsip/1.2/acifactory
            </activity-context-interface-factory-name>
            <resource-adaptor-entity-binding>
                <resource-adaptor-object-name>
                    slee/resources/jainsip/1.2/provider
                </resource-adaptor-object-name>
                <resource-adaptor-entity-link>
                    SipRA
                </resource-adaptor-entity-link>
            </resource-adaptor-entity-binding>
        </resource-adaptor-type-binding>
        <resource-adaptor-type-binding>
            <resource-adaptor-type-ref>
                <resource-adaptor-type-name>
                    jain-mgcp
                </resource-adaptor-type-name>
                <resource-adaptor-type-vendor>
                    net.java
                </resource-adaptor-type-vendor>
                <resource-adaptor-type-version>
                    2.0
                </resource-adaptor-type-version>
            </resource-adaptor-type-ref>
            <activity-context-interface-factory-name>
                slee/resources/jainmgcp/2.0/acifactory
            </activity-context-interface-factory-name>
            <resource-adaptor-entity-binding>
                <resource-adaptor-object-name>
                    slee/resources/jainmgcp/2.0/provider
                </resource-adaptor-object-name>
                <resource-adaptor-entity-link>
                    MGCPRA
                </resource-adaptor-entity-link>
            </resource-adaptor-entity-binding>
        </resource-adaptor-type-binding>
    </sbb>