java.lang.Object
|
+--java.lang.Throwable
|
+--java.lang.Exception
|
+--javax.telephony.JtapiPeerUnavailableException
public JtapiPeerUnavailableException()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1507]Place a phone call
By shanmugavelinfo { at } yahoo { dot } co { dot } in on 2005/08/04 02:29:26 Rate
import javax.telephony.*;
import javax.telephony.events.*;
public class Outcall
{
public static final void main ( String args [ ] ) throws Exception
{
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 ) ;
}
Address origaddr = null;
Terminal origterm = null;
try
{
origaddr = myprovider.getAddress ( "22247828" ) ;
Terminal [ ] terminals = origaddr.getTerminals ( ) ;
if ( terminals == null )
{
System.out.println ( "No Terminals on Address." ) ;
System.exit ( 0 ) ;
}
origterm = terminals [ 0 ] ;
}
catch ( Exception excp )
{
}
Call mycall = null;
try
{
mycall = myprovider.createCall ( ) ;
mycall.addObserver ( new MyOutCallObserver ( ) ) ;
}
catch ( Exception excp )
{
}
try
{
Connection c [ ] = mycall.connect ( origterm, origaddr, "9841882044" ) ;
}
catch ( Exception excp )
{
}
}
}
[1690]Please try to solve it
By ulaganathan { dot } a { at } coesyssolutions { dot } com on 2006/01/02 02:45:43 Rate
if i run this following program i have exception
javax.telephony.JtapiPeerUnavailableException:Default JtapiPeer Could not be created
import javax.telephony.*;
import javax.telephony.events.*;
public class Incall {
public static final void main ( String args [ ] ) {
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 ) ;
}
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 ) ;
}
}
}
[1736]i am adding all jar files but problem is that terminal connection found
By samirsadikshaikh { at } yahoo { dot } co { dot } in on 2006/03/26 13:45:14 Rate
//Module to get JTapi services
import javax.telephony.JtapiPeer;
import javax.telephony.JtapiPeerFactory;
import javax.telephony.Terminal;
import javax.telephony.Provider;
public class Main extends Object
{
public static final void main ( String args [ ] )
{
//A Provider represents the telephony software-entity that
//interfaces with a telephony subsystem
Provider myprovider = null;
try
{
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer ( "net.xtapi.XJtapiPeer" ) ;
myprovider = peer.getProvider ( "MSTAPI" ) ;
}
catch ( Exception excp )
{
System.out.println ( "Can't get Provider: " + excp.toString ( ) ) ;
}
//A Terminal represents a physical hardware endpoint
// connected to the telephony domain
Terminal terminal;
//EventsHandler is the call observer on terminal
try
{
terminal = myprovider.getTerminal ( "0" ) ;
terminal.addCallObserver ( new EventsHandler ( ) ) ;
}
catch ( Exception excp )
{
System.out.println ( "Can't get Terminal: " + excp.toString ( ) ) ;
}
}
}
//EventsHandler file
//Modile to handle all events
import javax.telephony.Terminal;
import javax.telephony.TerminalConnection;
import javax.telephony.Call;
import javax.telephony.Connection;
import javax.telephony.events.CallEv;
import javax.telephony.events.TermConnRingingEv;
import javax.telephony.events.TermConnEv;
import javax.telephony.events.TermConnDroppedEv;
import javax.telephony.media.MediaTerminalConnection;
import javax.telephony.media.MediaCallObserver;
import javax.telephony.media.events.MediaTermConnAvailableEv;
import javax.telephony.media.events.MediaTermConnStateEv;
import javax.telephony.media.events.MediaTermConnDtmfEv;
import javax.telephony.media.events.MediaTermConnUnavailableEv;
import java.net.URL;
import java.io.File;
import java.io.FileWriter;
import java.sql.SQLException;
import gdbpack.Database;
import ttspack.TextToSpeech;
import mailpack.MailAccess;
public class EventsHandler extends java.lang.Object implements MediaCallObserver
{
int j=0,totalMessages=0 ;
int dtmf=0;
char digits [ ] = new char [ 5 ] ;
int password;
int mailCount=1;
int validPassword=0;
String addr,epass;
int count=0;
//Call object represents the telephone call
private Call m_call = null;
//m_TerminalConnection & m_destTerminalConnection represents
//remote & this terminal respectively
private TerminalConnection m_terminalConnection = null;
private TerminalConnection m_destTerminalConnection = null;
private boolean bOrig = false;
//m_connections is the array of connections
private Connection m_connections [ ] = null;
//Class which do text to speech
TextToSpeech t1 = new TextToSpeech ( ) ;
//Class which handle all database
Database db1 = new Database ( ) ;
//Class to access mails
MailAccess m1 = new MailAccess ( ) ;
public void callChangedEvent ( CallEv evlist [ ] )
{
if ( m_call == null )
{
//setMVars function adds callObserver to the terminal
bOrig = false;
setMVars ( evlist [ 0 ] .getCall ( ) ) ;
}
for ( int i = 0; i < evlist.length; i++ )
{
CallEv ev = evlist [ i ] ;
//if the event is Ringing event
switch ( ev.getID ( ) )
{
case TermConnRingingEv.ID:
{
TerminalConnection tc = ( ( TermConnEv ) ev ) .getTerminalConnection ( ) ;
try
{
//Establishes the Call
tc.answer ( ) ;
System.out.println ( "Call Established" ) ;
}
catch ( Exception excp )
{
System.out.println ( "Can not establish call" + excp.toString ( ) ) ;
//Disconnect the connection
}
break;
}
case MediaTermConnAvailableEv.ID:
{
try
{
TerminalConnection tc = ( ( TermConnEv ) ev ) .getTerminalConnection ( ) ;
MediaTerminalConnection mtc = ( MediaTerminalConnection ) tc;
mtc.setDtmfDetection ( true ) ;
Messages ( "Welcome to phonomail system.\n"+
"Press 1 to read the mail\n"+
"Press 2 to skip the mail\n"+
"Press 3 to cancel reading current mail\n"+
"Now please enter your phonomail password",mtc ) ;
}
catch ( Exception excp )
{
TerminalConnection tc = ( ( TermConnEv ) ev ) .getTerminalConnection ( ) ;
MediaTerminalConnection mtc = ( MediaTerminalConnection ) tc;
ErrorMsg ( "Error in getting media connection. Please try afterwords",mtc ) ;
hangup ( mtc ) ;
}
break;
}
case MediaTermConnUnavailableEv.ID:
{
if ( ev instanceof MediaTermConnUnavailableEv )
{
try
{
TerminalConnection tc = ( ( TermConnEv ) ev ) .getTerminalConnection ( ) ;
MediaTerminalConnection mtc = ( MediaTerminalConnection ) tc;
mtc.setDtmfDetection ( false ) ;
hangup ( mtc ) ;
}
catch ( Exception excp )
{
TerminalConnection tc = ( ( TermConnEv ) ev ) .getTerminalConnection ( ) ;
MediaTerminalConnection mtc = ( MediaTerminalConnection ) tc;
ErrorMsg ( "Media connection is currently unavailable.Please try afterwords",mtc ) ;
hangup ( mtc ) ;
}
}
break;
}
case MediaTermConnDtmfEv.ID:
{
TerminalConnection tc = ( ( TermConnEv ) ev ) .getTerminalConnection ( ) ;
MediaTerminalConnection mtc = ( MediaTerminalConnection ) tc;
if ( validPassword==1 ) //Entered full password
{
try
{
char yesno = ( ( MediaTermConnDtmfEv ) ev ) .getDtmfDigit ( ) ;
switch ( yesno )
{
case '1': //Read mail
get_mails ( mtc,1 ) ;
System.out.println ( "Read Mail :"+mailCount ) ;
get_mails ( mtc,0 ) ;
break;
case '2': //Skip mail
mailCount++;
get_mails ( mtc,0 ) ;
break;
case '3': //cancel reading
mtc.stopPlaying ( ) ;
mailCount++;
get_mails ( mtc,0 ) ;
break;
default:
}
}
catch ( Exception excp )
{
ErrorMsg ( "Sorry, We can not accept your choice.Please try afterwords",mtc ) ;
hangup ( mtc ) ;
}
}
else
{
//Array to hold PhonoMail Password
digits [ dtmf ] = ( ( MediaTermConnDtmfEv ) ev ) .getDtmfDigit ( ) ;
dtmf++;
if ( dtmf==5 )
{
String pass1 = new String ( digits ) ;
Integer temp;
password = Integer.parseInt ( pass1 ) ;
try
{
db1.getDatabaseConnection ( ) ;
//Get uesr's Email-ID & Email Password
db1.returnMailInfo ( password ) ;
addr = db1.emailId;
epass = db1.emailPass;
System.out.println ( addr ) ;
System.out.println ( epass ) ;
db1.closeDataBaseConnection ( ) ;
validPassword=1;
//Connect to mail server & get
//Total Messages
totalMessages = m1.getConnection ( "172.16.0.17",addr,epass ) ;
System.out.println ( totalMessages ) ;
get_mails ( mtc,0 ) ;
}
catch ( SQLException e )
{
Messages ( "You have entered wrong password.Please enter correct password",mtc ) ;
validPassword=0;
dtmf=0;
}
catch ( Exception excp )
{
ErrorMsg ( "Your mail account can not be accessed.Please try afterwords",mtc ) ;
hangup ( mtc ) ;
}
}
}
break;
}
default:
// System.out.println ( "\n"+ev.toString ( ) ) ;
}
}
}
public void get_mails ( MediaTerminalConnection mtc,int flag )
{
try
{
if ( mailCount < =totalMessages )
{
int state;
if ( flag==0 ) //read only subject of mail
{
System.out.println ( "Header Mailcount : "+mailCount ) ;
m1.getMessage ( mailCount ) ;
t1.tts ( "Header.txt" ) ;
do
{
state = mtc.getMediaState ( ) ;
state = state & MediaTerminalConnection.PLAYING;
} while ( state!=0 ) ;
mtc.usePlayURL ( new URL ( "file:C:\\PhonoMail\\ULaw\\Mail.wav" ) ) ;
mtc.startPlaying ( ) ;
}
if ( flag==1 ) //read body part also
{
System.out.println ( "Body Mailcount : "+mailCount ) ;
t1.tts ( "Mail.txt" ) ;
do
{
state = mtc.getMediaState ( ) ;
state = state & MediaTerminalConnection.PLAYING;
} while ( state!=0 ) ;
mtc.usePlayURL ( new URL ( "file:C:\\PhonoMail\\ULaw\\Mail.wav" ) ) ;
mtc.startPlaying ( ) ;
mailCount++;
}
}
else
{
ErrorMsg ( "You don't have further mails. Good Bye.",mtc ) ;
hangup ( mtc ) ;
}
}
catch ( Exception excp )
{
ErrorMsg ( "System is not working properly. Please try afterwords",mtc ) ;
hangup ( mtc ) ;
}
}
//Fuction to play Error messages
public void ErrorMsg ( String msg,MediaTerminalConnection mtc )
{
try
{
FileWriter ErrMsg = new FileWriter ( "Error.txt" ) ;
ErrMsg.write ( msg ) ;
ErrMsg.close ( ) ;
t1.tts ( "Error.txt" ) ;
mtc.usePlayURL ( new URL ( "file:C:\\PhonoMail\\ULaw\\Mail.wav" ) ) ;
mtc.startPlaying ( ) ;
int state;
do
{
state = mtc.getMediaState ( ) ;
state = state & MediaTerminalConnection.PLAYING;
} while ( state!=0 ) ;
hangup ( mtc ) ;
}
catch ( Exception e )
{
System.out.println ( e ) ;
hangup ( mtc ) ;
}
}
//Fuction to play simple messages
public void Messages ( String msg,MediaTerminalConnection mtc )
{
try
{
FileWriter Msg = new FileWriter ( "Messages.txt" ) ;
Msg.write ( msg ) ;
Msg.close ( ) ;
t1.tts ( "Messages.txt" ) ;
mtc.usePlayURL ( new URL ( "file:C:\\PhonoMail\\ULaw\\Mail.wav" ) ) ;
mtc.startPlaying ( ) ;
}
catch ( Exception e )
{
System.out.println ( e ) ;
hangup ( mtc ) ;
}
}
//Function to add callObserver to the terminal
private void setMVars ( Call c )
{
m_call = c;
try
{
m_connections = c.getConnections ( ) ;
TerminalConnection [ ] tc;
if ( bOrig == false )
{
m_call.addObserver ( this ) ;
tc = m_connections [ 0 ] .getTerminalConnections ( ) ;
m_terminalConnection = tc [ 0 ] ;
Terminal t = m_terminalConnection.getTerminal ( ) ;
t.addCallObserver ( this ) ;
}
tc = m_connections [ 1 ] .getTerminalConnections ( ) ;
m_destTerminalConnection = tc [ 0 ] ;
}
catch ( Exception e )
{
System.out.println ( e ) ;
}
}
//Function to Disconnect the call & Reinitialising Variables
public void hangup ( MediaTerminalConnection mtc )
{
try
{
mtc.getConnection ( ) .disconnect ( ) ;
m_call = null;
m_connections= null;
m_terminalConnection = null;
m_destTerminalConnection = null;
}
catch ( Exception excp )
{
System.out.println ( "APPLICATION IS NOT FUNCTIONING PROPERLY " +
"MANUALLY RESTART THE APPLICATION\n" ) ;
System.out.println ( excp ) ;
}
finally
{
j=0;
totalMessages=0;
dtmf=0;
mailCount=1;
validPassword=0;
addr="";
epass="";
password=0;
}
}
}
public JtapiPeerUnavailableException(java.lang.String s)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1012]Places a telephone call from 476111 to 5551212
By shail_w81 { at } rediffmail { dot } com on 2004/10/03 14:20:24 Rate
fresher_sunsys@yahoo.com
import javax.telephony.*;
import javax.telephony.events.*;
import javax.telephony.callcontrol.*;
import javax.telephony.callcontrol.events.*;
public class CallCtlOutcall {
public static final void main ( String args [ ] ) {
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 ) ;
}
Address origaddr = null;
Terminal origterm = null;
try {
origaddr = myprovider.getAddress ( "4761111" ) ;
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;
}
Call mycall = null;
try {
mycall = myprovider.createCall ( ) ;
mycall.addObserver ( new MyCallCtlOutCallObserver ( ) ) ;
} catch ( Exception excp ) {
// Handle exceptions
}
try {
Connection c [ ] = mycall.connect ( origterm, origaddr, "5551212" ) ;
} catch ( Exception excp ) {
// Handle all Exceptions
}
}
}