Author Message
jtapi_dev
Joined: Dec 6, 2016
Messages: 2
Offline
Hi,
We use the Avaya Java Telephony API ( JTAPI) to perform various
telephony-related operations like connecting to a Call , answering and
disconnecting a call using the SDK.

1. Can you use JTAPI with EJB ( Enterprise Java Beans ) and annotation to close connection with safety ?

[code ]

@Stateful
@SessionScoped
public class ServiceTelephony implements IServiceTelephony {

@PostConstruct
public void serviceStartup() throws ErreurInterneException {

if (!initJtapi()) {
LOG.debug("Error: JtapiPeer could not be created. Verify your Jtapi client install.");
return;
}
initProvider();
}

@PreDestroy
public void close() {
try {
if (mainCall != null) {
mainCall.drop();
}

if (secondCall != null) {
secondCall.drop();
}

if (provider != null) {
provider.shutdown();
}
} catch (InvalidStateException | MethodNotSupportedException | PrivilegeViolationException | ResourceUnavailableException ex) {
LOG.warn(LogTypeCatalog.ERR_SYS, null, ex);
}

private 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);
LOG.debug("JtapiPeer created successfully.");
} catch (JtapiPeerUnavailableException e) {
try {
jtapiPeer = JtapiPeerFactory.getJtapiPeer("com.avaya.jtapi.tsapi.TsapiPeer");
LOG.debug("JtapiPeer created successfully.");
} catch (JtapiPeerUnavailableException e2) {
LOG.debug("JtapiPeerFactory.getJtapiPeer: caught JtapiPeerUnavailableException");
LOG.debug("Error: JtapiPeer could not be created. Verify your Jtapi client install.");
return false;
}
}
return true;
}

// Init provider
private void initProvider() throws ErreurInterneException {
StringBuilder providerString = new StringBuilder();

String serviceName = conf.phoneServiceName();
String login = conf.phoneServiceLogin();
String password = conf.palarphoneServicePassword();
String callingFrom = AccessControl.getInstance().getUserInformation().getUserDetail().getTel();

// If phone number = 0
if (callingFrom == null || callingFrom.trim().equals("0")) {
callingFrom = conf.phoneTelOfficer();
} else if (conf.phoneNumber()) {
callingFrom = conf.phoneTelOfficer2();
}

LOG.debug("Calling from : [{}]", callingFrom);


LOG.debug("Services : [{}]", getServices());

if (serviceName != null && !serviceName.trim().isEmpty()) {
providerString.append(serviceName);
} else {
serviceName = null;
}

if (login != null && !login.trim().isEmpty()) {
providerString.append(";loginID=");
providerString.append(login);
}

if (password != null && !password.trim().isEmpty()) {
providerString.append(";passwd=");
providerString.append(password);
}

if (jtapiPeer == null) {
throw new ErreurInterneException("Init problem with jtapiPeer");
}

try {
// create provider
if (serviceName != null) {
provider = jtapiPeer.getProvider(providerString.toString());
} else {
provider = jtapiPeer.getProvider(null);
}
LOG.debug("Provider created successfully. Waiting for the provider to initialize...");

//add a Provider Listener to the provider
myProviderListener = new PapillonProviderListener(this);
provider.addProviderListener(myProviderListener);

wait(conf.palarTelephonieProviderTimeout());//Wait for provider to be in 'in service' state
LOG.debug("Provider is in service.");
} catch (Exception e) {
LOG.error(LogTypeCatalog.APP_INIT, "Problème lors de l'initialisation : ", e);
LOG.debug("Please verify that the login information is correct.", "Authentication");
return;
}

try {
try {
addressOfficer = provider.getAddress(callingFrom);
LOG.debug(MessageFormat.format("Address [name = {0}, tel = {1}] created successfully.", addressOfficier.getName(), callingFrom));

// create Terminal
terminalOfficier = provider.getTerminal(callingFrom);
numTelOfficer = callingFrom;
LOG.debug(MessageFormat.format("Terminal [name = {0}, tel = {1}] created successfully.", terminalOfficier.getName(), callingFrom));
} catch (Exception e) {
LOG.error(LogTypeCatalog.APP_INIT, "Problème lors de l'initialisation : ", e);
LOG.debug("Please verify that the dialing extension number is correct.");
throw (e);
}

// add call listener to terminal
LOG.debug("Adding a call listener to the terminal.");

LOG.debug("Changement d'état => [{}]", etatService);
} catch (Exception e) {
LOG.debug("login() caught " + e + "Message: " + e.getMessage());
}
}

}



[code ]

Best regard
Go to:   
Mobile view