Putting it All Together
Now that you understand how the components work together, let's take a look at a couple of sample code snippets. The following code listings are from the Click-to-Call application. They use a class named TelSvcWrapper that does the job of interfacing with the AE Services Telephony Web Service API. TelSvcWrapper is a convenience method and template included in the /sampleapps directory of the AE Services Telephony Services Web Service SDK (available to DevConnect Members for download at no charge through the DevConnect website).
Code Listing 1 shows how a CallRequest object gets serialized in the CommunicationProxy in the DMZ, and sent through the firewall to the Application AES Facebook Proxy, where it is decoded
(deserialized) (as seen in Code Listing 2). Code Listing 2 also shows the makeCall method in the TelSvcWrapper library being called after the decoding.
Code Listing 1. Serializing the CallRequest object in the CommunicationProxy
private class ServerCommunicatorConnection extends Thread
{
.
.
.
public void sendRequestToEnterpriseServer(Event request)
{
try
{
synchronized (connectionSynchronizer)
{
writerToEnterpriseServerField.writeObject(request);
writerToEnterpriseServerField.flush();
}
} catch (Exception e)
{
System.err.println("Error: " + e.toString());
e.printStackTrace();
}
}
.
.
.
}
Code Listing 2. Decoding the CallRequest and invoking the makeCall method
import sampleapps.TelSvcWrapper;
import sampleapps.TelSvcWrapper;
private TelSvcWrapper telephonyService;
private ObjectInputStream fromCommunicationProxy;
private ObjectOutputStream toCommunicationProxy;
public void readFromCommunicationProxy()
{
Object inputFromCommunicationProxy,
waitObject = new Object();
CallRequest callRequest;
do
{
try
{
System.out.println("Waiting for request from Communication proxy.");
inputFromCommunicationProxy = readerFromCommunicationProxy.readObject();
System.out.println("Received request from Facephone proxy");
if (inputFromCommunicationProxy instanceof CallRequest)
{
callRequest = (CallRequest) inputFromCommunicationProxy;
System.out.println("Placing call from extension "
+ callRequest.getOriginatorExtension() + " to "
+ callRequest.getRecipientPhoneNumber());
try
{
telephonyService.makeCall(callRequest.getOriginatorExtension(),
callRequest.getRecipientPhoneNumber());
toCommunicationProxy.writeObject(new CallProgress
(callRequest.getOriginatorFacebookUID(),
callRequest.getRecipientFacebookUID(), now +
":Call to successful.", true));
toCommunicationProxy.writeObject
(new CallProgress(callRequest.getOriginatorFacebookUID(),
callRequest.getRecipientFacebookUID(),
now + ": Incoming call from .", false));
toCommunicationProxy.flush();
}
catch (Exception e)
{
System.out.println("Error: " + e.toString());
}
}
else // ...
}
catch (Exception e)
{
System.err.println("Error: " + e.toString());
}
}
while (true);
}
Within the TelScvWrapper Class reside the main methods you would use in your applications to integrate Avaya's telephony features. The following table summarizes each of the main methods.
Table
1. The Main
Methods of the TelSvcWrapper Class
|
Method Name
|
Method Summary
|
|
TelSvcWrapper
|
The class constructor. In addition to
initializing class fields, this method creates a connection to the Telephony
Service. In addition, the method stores values for HTTP headers and SOAP
headers that will be utilized by other methods in the class.
|
|
attach
|
Initiates a telephony
session.
|
|
Release
|
Releases AE
Services resources on the server. If not called, resources remain active
until the AE Services timer frees them.
|
|
makeCall
|
Sets the call
extensions (originating & destination) and uses the class's port object
to make the call.
|
|
disconnectCall
|
Assigns the
originating extension of the existing call (passed as a parameter) and disconnects
the call.
|
|
answerCall
|
Assigns an
extension (passed as a parameter) and answers the call using the answerAlertingCall method of the class's port object.
|
|
conferenceCall
|
Adds a new
party to an existing call.
|
|
transferCall
|
Performs a
blind transfer to a new party of an existing call. The previous party (the
transferring extension) is disconnected.
|
Only Two Minor Issues to Overcome
Two primary hurdles existed in the development of the CTC application. The first was the fact that Facebook does not allow a third-party application access to certain pieces of Facebook member profile information, including phone numbers. The Avaya team overcame this limitation by utilizing database functionality provided by the Facebook platform. When a user activates the Click-to-Call application, it prompts the user for their contact information. This information is then stored in the Facebook platform. Once a user properly activates the application, they then have to populate their own contact numbers, which actually gives greater flexibility to specify multiple numbers (office, home, cell, etc.). Again, all the data resides in the Facebook platform.
The second hurdle was the requirement that the CTC application traverse the Avaya corporate firewall. Given that the firewall closes inactive ports and only allows initial traversal from the outbound direction, the team decided to use a two server solution. This allowed them to accept inbound requests and then initiate the call from within the firewall using Communication Proxy and AE Services Facebook Proxy to send and receive serialized objects through the firewall. By utilizing object serialization and sending serialized objects, data can be passed back and forth via TCP.
Summary
The Avaya AE Services Platform enables the integration of telephony features in the development of your applications. Given the ability to rapidly integrate Avaya's platform into your application, the possibilities for new applications are substantial. From team communications within large, enterprise organizations, to customer support systems for the small business, the Avaya Application Enablement Services provide the technology for creating new customer dynamics using the phone in a Web 2.0 world.