📄 tstest.java
字号:
/**
* JTAPI TSTest application
* Version 2.0 1/99
*
* This program may be executed as an applet or stand-alone application.
* It uses Avaya's implementation of JTAPI to make a call. The application
* does the following for every call made:
*
* 1) Creates the Provider
* 2) Creates an Address for calling extension
* 3) Creates a Terminal for calling extension
* 4) Creates CallObserver
* 5) Associates CallObserver to the Terminal
* 6) Creates a Call object
* 7) When "Dial" is requested, makes call using the Call.connect() method
* 9) When "Hang-up" is requested, drops call using Connection.disconnect() method
* 10) Shutdown the provider
*
* The JtapiPeer object is created once upon initialization of the application.
* All tracing messages and events are printed on a separate window,
* use the "Show Tracing" option to view this window.
*
* Parameters required:
* SERVICENAME name for service provider
* LOGIN login as administered on the NT domain
* PASSWORD password administered for login
* PHONE extension that will originate the call
* DESTINATION destination number
*/
package hu.vemsoft.tstest;
import hu.vemsoft.j2ee.util.tracer.Debug;
import java.awt.*;
import java.applet.*;
import java.io.IOException;
import java.util.*;
import java.awt.event.*;
import javax.telephony.*;
import javax.telephony.events.*;
public class TSTest implements ProviderObserver, CallObserver
{
JtapiPeer jtapiPeer;
Provider provider;
Terminal terminal;
String log4jFilename = "log/xml/log4j.xml";
String[] services = null;
String serviceName = null;
String login = null;
String password = null;
String phone = null;
String destination = null;
String sleepMiliSec = null;
public static void main(String[] args)
{
TSTest tstest = new TSTest();
try
{
tstest.tSTest_main(args);
}
catch(Exception ex)
{
System.out.println("Exception: - "+ex.getMessage());
ex.printStackTrace();
}
}
public void tSTest_main(String[] args)
{
for (int i = 0; i < args.length; i++)
{
if (args[i].equals("-login"))
{
login = new String(args[i + 1]);
}
else if (args[i].equals("-password"))
{
password = new String(args[i + 1]);
}
else if (args[i].equals("-phone"))
{
phone = new String(args[i + 1]);
}
else if (args[i].equals("-tlink"))
{
serviceName = new String(args[i + 1]);
if (serviceName != null)
{
serviceName.toUpperCase();
}
}
else if (args[i].equals("-destination"))
{
destination = new String(args[i + 1]);
}
else if (args[i].equals("-sleep"))
{
sleepMiliSec = new String(args[i + 1]);
}
}
System.out.print("Init JTAPI... ");
//obtain the JtapiPeer object
if ( !initJtapi() ) {
System.out.print("JTAPI not inited! Exit!");
return;
}
System.out.println("Get services...");
try {
// get service providers on the network -- this depends on
// the administration in the tsapi.pro file
services = jtapiPeer.getServices();
if (services != null) {
for ( int i=0; i < services.length; i++ ) {
System.out.println("Found service: "+services[i]);
}
}
} catch (PlatformException e) {
System.out.print( "JtapiPeer.getServices() caught PlatformException\n" );
System.out.print( "Message: " + e.getMessage() + "\n\n" );
e.printStackTrace();
}
System.out.println("Login...");
login();
System.out.println("Make call...");
makeCall();
//user wants to disconnect existing call
try {
Thread.sleep(Long.parseLong(sleepMiliSec));
} catch (Exception ex) {
System.out.println("Error during sleep... "+ex);
ex.printStackTrace();
}
TerminalConnection[] tc = null;
if ( (tc = terminal.getTerminalConnections()) != null) {
System.out.println("Found Terminal Connection, hangup... ");
hangup( tc[0] );
}
System.out.println("Logout... ");
logout();
System.out.println("End of call!");
}
/**
* This method creates the default JtapiPeer.
*/
public boolean initJtapi()
{
try {
//get default implementation of the JtapiPeer object by sending null,
//optionally you may send com.avaya.jtapi.tsapi.TsapiPeer
jtapiPeer = JtapiPeerFactory.getJtapiPeer( null );
System.out.println("JtapiPeer created successfully.\n\n");
} catch (JtapiPeerUnavailableException e) {
System.out.println( "JtapiPeerFactory.getJtapiPeer: caught JtapiPeerUnavailableException\n");
System.out.println( "Message: " + e.getMessage() + "\n\n" );
System.out.println( "Error: JtapiPeer could not be created. Verify your Jtapi client install.\n\n");
return false;
}
return true;
}
/**
* This method creates the Provider and waits until is in service.
*/
public synchronized void login()
{
String tlink;
String login;
String password;
String hostname;
String callingExt;
String calledExt;
String providerString;
tlink = this.serviceName;
login = this.login;
password = this.password;
providerString = tlink + ";loginID=" + login + ";passwd=" + password;
if ( jtapiPeer != null ) {
try {
// create provider
System.out.println("Get provider with: "+providerString);
provider = jtapiPeer.getProvider(providerString);
System.out.println("Provider created successfully.\n\n");
System.out.println("Waiting for the provider to initialize...\n");
//add a ProviderObserver to the provider
provider.addObserver( this );
// wait to be notified when the provider is in service --
// corresponding notify is in the providerChangedEvent() method
wait ();
} catch (Exception e) {
System.out.println("login() caught " + e + "\n");
System.out.println( "Message: " + e.getMessage() + "\n\n" );
e.printStackTrace();
return;
}
System.out.println( "Provider is in service.\n\n" );
}
}
/**
* This method creates the Terminal, Address and Call objects.
* It adds a callObserver to the originating terminal, and makes the call.
*/
public void makeCall()
{
String callingNumber;
String calledNumber;
Address address = null;
Call call = null;
Connection[] connections = null;
if ( provider != null ) {
callingNumber = this.phone;
calledNumber = this.destination;
try {
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -