Link to home
Start Free TrialLog in
Avatar of sghosh092199
sghosh092199

asked on

Problems on JTAPI

I have downloaded JTAPI 1.3 specifications in form of Java files and Classes from Sun's Java Telephony download page.

How can I proceed with JTAPI?
ASKER CERTIFIED SOLUTION
Avatar of terajiv
terajiv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Outgoing Telephone Call Example
The following code example places a telephone call using the core Call.connect() method. It, however, looks for the states provided by the Call Control package.

import javax.telephony.*;
import javax.telephony.events.*;

/*
 * The MyOutCallObserver class implements the CallObserver
 * interface and receives all events associated with the Call.
 */
 
public class MyOutCallObserver implements CallObserver {
 
  public void callChangedEvent(CallEv[] evlist) {
 
    for (int i = 0; i < evlist.length; i++) {
 
      if (evlist[i] instanceof ConnEv) {
 
        String name = null;
        try {
          Connection connection = ((ConnEv)evlist[i]).getConnection();
          Address addr = connection.getAddress();
          name = addr.getName();
        } catch (Exception excp) {
          // Handle Exceptions
        }
        String msg = "Connection to Address: " + name + " is ";
 
        if (evlist[i].getID() == ConnAlertingEv.ID) {
          System.out.println(msg + "ALERTING");
        }
        else if (evlist[i].getID() == ConnInProgressEv.ID) {
          System.out.println(msg + "INPROGRESS");
        }
        else if (evlist[i].getID() == ConnConnectedEv.ID) {
          System.out.println(msg + "CONNECTED");
        }
        else if (evlist[i].getID() == ConnDisconnectedEv.ID) {
          System.out.println(msg + "DISCONNECTED");
        }
      }  
    }
  }
}


         ------------------------------------------------------


import javax.telephony.*;
import javax.telephony.events.*;
import MyOutCallObserver;


/*
 * Places a telephone call from 476111 to 5551212
 */
public class Outcall {
 
  public static final void main(String args[]) {
 
    /*
     * Create a provider by first obtaining the default implementation of
     * JTAPI and then the default provider of that implementation.
     */
    Provider myprovider = null;
    try {
      JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
      myprovider = peer.getProvider(null);
    } catch (Exception excp) {
      System.out.println("Can't get Provider: " + excp.toString());
      System.exit(0);
    }
 
   /*
    * We need to get the appropriate objects associated with the
    * originating side of the telephone call. We ask the Address for a list
    * of Terminals on it and arbitrarily choose one.
    */
    Address origaddr = null;
    Terminal origterm = null;
    try {
      origaddr = myprovider.getAddress("4761111");
 
      /* Just get some Terminal on this Address */
      Terminal[] terminals = origaddr.getTerminals();
      if (terminals == null) {
        System.out.println("No Terminals on Address.");
        System.exit(0);
      }  
      origterm = terminals[0];
    } catch (Exception excp) {
      // Handle exceptions;
    }
 
 
    /*
     * Create the telephone call object and add an observer.
     */
    Call mycall = null;
    try {
      mycall = myprovider.createCall();
      mycall.addObserver(new MyOutCallObserver());
    } catch (Exception excp) {
      // Handle exceptions
    }
 
    /*
     * Place the telephone call.
     */
    try {
      Connection c[] = mycall.connect(origterm, origaddr, "5551212");
    } catch (Exception excp) {
      // Handle all Exceptions
    }
  }
}





Incoming Telephone Call Example
The following code example illustrates how an application answers a Call at a particular Terminal. It shows how applications accept calls when (and if) offered. This code example greatly resembles the core InCall code example.

import javax.telephony.*;
import javax.telephony.events.*;

import javax.telephony.*;
import javax.telephony.events.*;

/*
 * The MyInCallObserver class implements the CallObserver and
 * recieves all Call-related events.
 */
 
public class MyInCallObserver implements CallObserver {
 
  public void callChangedEvent(CallEv[] evlist) {
    TerminalConnection termconn;
    String name;
    for (int i = 0; i < evlist.length; i++) {
 
      if (evlist[i] instanceof TermConnEv) {
        termconn = null;
        name = null;
 
        try {
          TermConnEv tcev = (TermConnEv)evlist[i];
          Terminal term = termconn.getTerminal();
          termconn = tcev.getTerminalConnection();
          name = term.getName();
        } catch (Exception excp) {
          // Handle exceptions.
        }

        String msg = "TerminalConnection to Terminal: " + name + " is ";
 
        if (evlist[i].getID() == TermConnActiveEv.ID) {
          System.out.println(msg + "ACTIVE");
        }
        else if (evlist[i].getID() == TermConnRingingEv.ID) {
          System.out.println(msg + "RINGING");
 
          /* Answer the telephone Call using "inner class" thread */
          try {
            final TerminalConnection _tc = termconn;
                 Runnable r = new Runnable() {
              public void run(){
                try{
                        _tc.answer();
                } catch (Exception excp){
                  // handle answer exceptions
                }
                  };
            
            };
            Thread T = new Thread(r);
            T.start();
          } catch (Exception excp) {
            // Handle Exceptions;
          }
        } else if (evlist[i].getID() == TermConnDroppedEv.ID) {
          System.out.println(msg + "DROPPED");
        }
      }  
    }
  }
}

            ----------------------------------------------------

import javax.telephony.*;
import javax.telephony.events.*;
import MyInCallObserver;

/*
 * Create a provider and monitor a particular terminal for an incoming call.
 */
public class Incall {
 
  public static final void main(String args[]) {
 
    /*
     * Create a provider by first obtaining the default implementation of
     * JTAPI and then the default provider of that implementation.
     */
    Provider myprovider = null;
    try {
      JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
      myprovider = peer.getProvider(null);
    } catch (Exception excp) {
      System.out.println("Can't get Provider: " + excp.toString());
      System.exit(0);
    }
 
    /*
     * Get the terminal we wish to monitor and add a call observer to that
     * Terminal. This will place a call observer on all call which come to
     * that terminal. We are assuming that Terminals are named after some
     * primary telephone number on them.
     */
    try {
      Terminal terminal = myprovider.getTerminal("4761111");
      terminal.addCallObserver(new MyInCallObserver());
    } catch (Exception excp) {
      System.out.println("Can't get Terminal: " + excp.toString());
      System.exit(0);
  }
  }
}
U can make use of it...
Rajiv

HI, Rajiv and everybody. I am very intesting in java-hardware(JTAPI, Comm & etc). Can you share you experience and me???

My email is axilian@sinamail.com
What expr. u want? If u have any doubts just ask.... or rather why dont u join java's JTAPI Interest group... U can get Expr from around 20/30 experts...
So better u join that If u want from me Im not saying no to that... Just ask any queries...

What about the Points?
:::)))))
 Hi terajiv, I am akokchai. Can you tell which JTAPI interest group can be enjoyed. Autually, I hope to know what product be designed in JTAPI(or TAPI...). Do you have any info(website) of them. Tell me please.


Have a nice day.bye.
Hi Terajiv and others,


The programs given by Mr.Terajiv, (beleive, downloads from Java.sun.com)which are when executed will give peer and provider problems.

This is about providing info and my doubt also. Please do the needful.

Found solution partially from JTAPI Java.sun.com Forums.

1. JTAPI implementation CallPath from IBM is downloaded.

I tried “MyPhone” program posted by Mr. Keane in the JTAPI Java.sun.com Forum..
================MyPhone.java=============
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.events.*;
import MyCallCtlInCallObserver;


public class MyPhone {
 
public static final void main(String[] args){

      Provider myprovider = null;
      try {
            System.out.println("Initializing Peer...");
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer("com.ibm.telephony.callpath.CSAJtapiPeer");                               System.out.println("Peer Initialized.");
            System.out.println("Peer Name:" + peer.getName ());

//List of services
            String srvLst[] = peer.getServices();
            System.out.println("No of Services:" +       srvLst.length);
            myprovider = peer.getProvider("foo.foobar.com;login=blah;passwd=blah");
            //myprovider = peer.getProvider(null);
            }catch(ProviderUnavailableException puExcp){
            System.out.println(puExcp.getCause() + " : " +
            puExcp.toString());
            }catch(Exception excp){
// Handle exceptions
System.out.println("Excp:" + excp);
}
}
}


I am using JTAPI(IBM CallPath) and the class path is set.

I tried this with a modem connection.

When executed the program found the following at the command prompt…

Initializing Peer...
Peer Initialized.
Peer Name:com.ibm.telephony.callpath.CSAJtapiPeer
No of Services:0
162 : javax.telephony.ProviderUnavailableException

Did any one of you here have any other way to detect call connection?

I tried all the possibilities specified by various friends from the forum, but same provider problem is persisting.

Is there anyone with any new suggestion to overcome this problem?

Please reply back.

Thanking you.

With Best Wishes,
Sneha.