Connect a phone

That is, how you would try to connect to your provider.
Sure, we guess you are using CISCO, but this way can be equal to many other provider.
Just click next to get the source ..
If you like, just post a comment, i would be glad about that!

import javax.telephony.Address;
import javax.telephony.InvalidArgumentException;
import javax.telephony.JtapiPeer;
import javax.telephony.JtapiPeerFactory;
import javax.telephony.JtapiPeerUnavailableException;
import javax.telephony.MethodNotSupportedException;
import javax.telephony.Provider;
import javax.telephony.ProviderObserver;
import javax.telephony.ResourceUnavailableException;
import javax.telephony.Terminal;


public class CTIExample implements ProviderObserver {
  private static final String PROVIDER_STRING = “;login=loginName;passwd=password”;

  Condition conditionInService = new Condition();

  Provider provider;
  public static void main (String args[]) {
    CTIExample example = new CTIExample();
    if (example.provider == null) {
      JtapiPeer peer;
      try {
        peer = JtapiPeerFactory.getJtapiPeer(null);
        // we now connect to the provider
        example.provider = (Providerpeer.getProvider(PROVIDER_STRING);
        // cause we need 2 have the condition set, we have to 
        // add the ProviderObserver here
        // thats only cisco, we have to wait until the condition is set,
        // to know that everything works fine 
        // you know, that we do not write any stacktrace … we log them, but
        // it is just an example 🙂
      catch (JtapiPeerUnavailableException e) {
      catch (ResourceUnavailableException e) {
      catch (MethodNotSupportedException e) {
    try {
      // thats how we connect a terminal ( the phone(s) with the number 100 )  
      Address address = example.provider.getAddress(“100”);      
      Terminal[] terminals = address.getTerminals();
      // we may got more than one phone with the 100 as number
      // believe me, it is possible 🙂
      for (int j = 0; j < terminals.length; j++) {
        // you may do not know whats that good for .. see the faq,
        // we explain that later
        CTIEventListener.getInstance().initialize(address, terminals[j]);
    catch (InvalidArgumentException e) {

  /* (non-Javadoc)
   * this event is fired, everytime something changed with the provider.
   * f.e. if you are connected, you get the ProvInServiceEv
  public void providerChangedEvent(ProvEv[] eventList) {
    if (eventList != null) {
      // you do not need the for loop, for just this event.
      // but maybe you want to add some more later .. 
      for (int i = 0; i < eventList.length; i++) {
        if (eventList[iinstanceof ProvInServiceEv) {


1 thought on “Connect a phone

  1. Hi Jörg,

    great stuff. I just found this posts and tried to “use” the code.
    After I loaded the code to eclipse I get an error:

    CTIEventListener.getInstance().initialize(address, terminals[j]);
    -> CTIEventListener -> cannot be resolved.

    Any idea?


Leave a Reply

Your email address will not be published. Required fields are marked *