next up previous
Next: 10.2.10 An Example that Up: 10.2 SIP Previous: 10.2.8 Fetch SIPIdentitySIPURI in

10.2.9 Fetch SIP Attributes for a SIPIdentitySIPURI

The following code illustrates fetching SIPIdentity attributes from a commObject for a SIPIdentitySIPURI. This is called after the user has selected the SIPURI from the list for registration. It is executed in Step 12 of Figure [*].

public static Hashtable getSIPAttributes()

{

    /* Define variables for storing attributes */

    Hashtable htblsipAttributes = new Hashtable();

    String indexforsipURI = new String();

    String commURIval = new String();

    String sipURIval = new String();

    String varSIPIdentitySIPURI = "SIPIdentitySIPURI";

    String varSIPIdentityPassword= "SIPIdentityPassword";

    String varSIPIdentityProxyDomain = "SIPIdentityProxyDomain";

    String varSIPIdentityRegistrarDomain = "SIPIdentityRegistrarDomain";

    String varProtocolLabel = "SIP:";

    /* Evaluate the index in drop down box that was selected by the user */

    int dummyj = 0;

    while (dummyj<cntCommURIs)

    {

        if (htblsipURIs.get("SIPURI"+dummyj).toString()== dummystr)

        {

            sipURIkey = "SIPURI"+dummyj;

        }

        dummyj++;

    }

    /* After evaluating the index store commURI and sipURI for the

        index selected in drop down */

    try

    {

        if (htblcommURIs.containsKey(sipURIkey))

        {

            commURIval = htblcommURIs.get(sipURIkey).toString();

            sipURIval = htblsipURIs.get(sipURIkey).toString();

            String[] sipAttrs = {"SIPIdentitySIPURI"};

            String retStr = new String();

            Hashtable ctxHtbl = new Hashtable();

            /* Set the directory context with UserDN and the password */

            ctxHtbl.put(Context.INITIAL_CONTEXT_FACTORY,

                "com.sun.jndi.ldap.LdapCtxFactory");

            ctxHtbl.put(Context.PROVIDER_URL,

                vLDAPHost.toString()+":389");

            ctxHtbl.put(Context.SECURITY_AUTHENTICATION,

                "simple");

            ctxHtbl.put(Context.SECURITY_PRINCIPAL,

                vUsrDN);

            ctxHtbl.put(Context.SECURITY_CREDENTIALS,

                vUsrPassword);

            /* Create directory context */

            DirContext ctxSipIdentity = new InitialDirContext(ctxHtbl);

            /* Search for commURIs */

            NamingEnumeration sipIdentityPointer =

            ctxSipIdentity.search(commURIval,"",null);

            SearchResult sipIdentityDetails =

                (SearchResult) sipIdentityPointer.next();

            /* Store the SIPIdentitySIPURIs */

            Attributes sipURIAttr = sipIdentityDetails.getAttributes();

            Attribute vsipIdentitySIPURI =

                sipURIAttr.get("SIPIdentitySIPURI");

            Attribute vsipIdentityRegistrarDomain =

                sipURIAttr.get("SIPIdentityRegistrarAddress");

            Attribute vsipIdentityPassword =

                sipURIAttr.get("SIPIdentityPassword");

            /* Store the values fetched into variables after extracting

                leading spaces */

            String valSIPIdentitySIPURI = vsipIdentitySIPURI.toString().

                substring(varSIPIdentitySIPURI.length()+2);

            String valSIPIdentityRegistrarDomain =

                vsipIdentityRegistrarDomain.toString().substring(

                varSIPIdentityRegistrarDomain.length()+2);

            String valSIPIdentityPassword =

                vsipIdentityPassword.toString().substring(

                varSIPIdentityPassword.length()+2);

            /* Store the values into a hastable so that they can be

                displayed in dropdown for User Interface */

            htblsipAttributes.put("SIPIdentitySIPURI",

                valSIPIdentitySIPURI);

            htblsipAttributes.put("SIPIdentityRegistrarDomain",

                valSIPIdentityRegistrarDomain);

            htblsipAttributes.put("vUsrID",vsipIdentitySIPURI.toString().

                substring(varSIPIdentitySIPURI.length()+2));

            /* Storing the starting character and ending character

                after - SIP: to fetch the actual SIP URI */

            int wheretill = valSIPIdentitySIPURI.toString().indexOf("@");

            int startfrom =

                varSIPIdentitySIPURI.toString().indexOf("sip:")+

            varProtocolLa bel.length()+1;

            /* Store the SIPIdentitySIPURI into a hashtable for

                persistent store*/

            htblsipAttributes.put("vUsrID",valSIPIdentitySIPURI.

                toString().substring(startfrom,wheretill));

            htblsipAttributes.put("Remember","true");

        }

    }

    catch(Exception e)

    {

        System.out.println("Error in getSIPAttributes - "+e.getMessage());

    }

    return htblsipAttributes;

}


next up previous
Next: 10.2.10 An Example that Up: 10.2 SIP Previous: 10.2.8 Fetch SIPIdentitySIPURI in

Video Middleware Cookbook
Questions and Comments : Cookbook Editors