we compile this code and it is compiled successfully but when it is run an exception
occurs, as shown in the output.here 4580168 is our home phone number.
***********************************************************************************************
source code
***********************************************************************************************
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.*;
import javax.telephony.events.*;
import java.net.*;
import javax.telephony.*;
import javax.telephony.events.*;
/*
* The MyInCallObserver class implements the CallObserver and
* recieves all Call-related events.
*/
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");
}
}
}
}
}
/*
* Create a provider and monitor a particular terminal for an incoming call.
*/
public class Incall1 {
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("com.ibm.telephony.mm.MM_JtapiPeer");
//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 add1 = myprovider.getTerminal("4580168");
add1.addCallObserver(new MyInCallObserver());
} catch (Exception excp) {
System.out.println("Can't get Terminal: " + excp.toString());
System.exit(0);
}
}
}
**********************************************************************************************
output
**********************************************************************************************
C:\active>java Incall
IBM J323 Engine v5.0.0
(C) Copyright IBM Corporation, 1996-2003. All rights reserved.
Setting login to 'shafaat haider'
Can't get Terminal: javax.telephony.InvalidArgumentException: unknown terminal
4580168
C:\active>