Audio Call V3.0 Web Service – Java Tutorial

 

Download Audio Call V3.0 Web Service – Java Tutorial Sample Code

 

Introduction

The following example will provide you with a step-by-step description of how to develop an “Audio Call v3″ application in Java. I am running Windows Vista on my machine, I used Eclipse Galileo for writing, building, running the sample code and for Java I have JDK 6 installed.

Pre-requisites and Environment setup

Before we start writing any code for the TPCSv3 application, we need to do the following preparations:

Download and install Eclipse Galileo if you do not have it already.

Download and install Apache Axis. We have tried both Axis 1.4 and Axis2 1.5. We will use Axis2 1.5 for our example because Axis2 is easier to install and use. Download Axis2 1.5 and follow the instruction for installation.

Download the files for Third Party Call WSDL and Schema and Common WSDL and Schema then extract them to a local directory (e.g. C:\WSDL). Ensure that you have the following files in you local directory:

Common WSDL definition files
parlayx_common_faults_3_0.wsdl
parlayx_common_types_3_1.xsd
Audio call WSDL definition files
parlayx_audio_call_play_media_service_3.2.wsdl
parlayx_audio_call_play_media_interface_3.2.wsdl
parlayx_audio_call_types_3.2.xsd

Set an environment variable AXIS2_HOME to the pathname of the directory where you extracted Axis2 (e.g. C:\Axis2_1.5). Make sure to add the Axis2 library and binary pathnames to the “path” system environment variable (e.g. C:\Axis2_1.5\lib;C:\Axis2_1.5\bin).

Make sure that your Java environment variables are all set correctly (i.e. JAVA_HOME refers to the required JDK and the Java binaries and library pathnames are added to the “path” environment variable).

Make sure there is no “space character” in file and directory names you choose because Axis seems to have an issue in recognizing files and directories with a space character in them!

Try to test the WSDL2Java tool by calling it from the command prompt and you should get the response as shown in figure below.

Generating the Client Stub

Now we are going to generate the client stub for our application after downloading the WSDL and Schema files and extracting them. Here are the steps to generate the stub:

  1. From the command prompt go to the directory where the WSDL files were extracted (e.g. C:\WSDL\ AudioCall).
  2. To convert the WSDL file definitions to Java execute the following command line : “C:\WSDL\AudioCall>WSDL2Java –uri parlayx_audio_call_play_media_service_3_2.wsdl”
  3. And this operation should result a “src” that has all the required definitions and policy for the Audio Call Service.

Create the Audio Call Service sample

To create a Audio Call Service application we need the following:

Create a new project Java on Eclipse.

Import the “src” folder to your project.

Add the Axis2 1.5 jar files to the project libraries by adding external JAR’s (as shown in figure below):

After finishing the project set up, lets try to add some code to our project and test the service:

Create a new package to your project and then create a new class for the project and paste the following code:


import org.apache.axis2.*;
import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.csapi.www.wsdl.parlayx.third_party_call.v3_4.service.ThirdPartyCallServiceStub;
import org.csapi.www.wsdl.parlayx.audio_call.*;
import org.csapi.www.wsdl.parlayx.audio_call.play_media.v3_2.service.AudioCallPlayMediaServiceStub;
import org.csapi.www.wsdl.parlayx.audio_call.play_media.v3_2.service.PolicyException;
import org.csapi.www.wsdl.parlayx.audio_call.play_media.v3_2.service.ServiceException;
import java.rmi.RemoteException;

public class myAudioCallClass {

	/**
	 * @param args
	 * @throws ServiceException
	 * @throws PolicyException
	 */
	public static void main(String[] args) throws RemoteException, PolicyException, ServiceException {

		try {

			// Setup Authentication
			HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
			auth.setUsername("[USERNAME]");
			auth.setPassword("[PASSWORD]");
			auth.setPreemptiveAuthentication(true);

			// Setup the Service Stub
			ThirdPartyCallServiceStub c2cSS = new ThirdPartyCallServiceStub(
			 	"http://[ACE_IP_ADDRESS:9080/RaptorWeb/services/ThirdPartyCall"
			);

			c2cSS._getServiceClient().getOptions().setProperty(
                            org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth
                        );

			ThirdPartyCallServiceStub.MakeCallSession call = new ThirdPartyCallServiceStub.MakeCallSession();

			// First Call Participant ( Calling Participant )
			call.addCallParticipants(new org.apache.axis2.databinding.types.URI("sip", "[SIP_URI]"));

			// Execute the make call
			ThirdPartyCallServiceStub.MakeCallSessionE makeCallSessionE =
                            new ThirdPartyCallServiceStub.MakeCallSessionE();

			makeCallSessionE.setMakeCallSession(call);

			ThirdPartyCallServiceStub.MakeCallSessionResponseE response =
                            c2cSS.makeCallSession(makeCallSessionE);

			//Get the call ID for our session
			String CallID = response.getMakeCallSessionResponse().getResult();
			System.out.println("Response:"+ CallID);

			//Set the end point url for the service
			AudioCallPlayMediaServiceStub audioCallPM = new AudioCallPlayMediaServiceStub(
                            "http://[ACE_IP_ADDRESS:9080/RaptorWeb/services/AudioCallPlayMedia"
                        );

			//Set the authentication parameters
			audioCallPM._getServiceClient().getOptions().setProperty(
                            org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
                            auth
                        );

			//Create Audio Call object and setup the associated CallID, participants, audio file to play
			AudioCallPlayMediaServiceStub.PlayAudioMessage pMSGAudio =
                            new AudioCallPlayMediaServiceStub.PlayAudioMessage();
			AudioCallPlayMediaServiceStub.PlayAudioMessageE pMSGAudioE =
                            new AudioCallPlayMediaServiceStub.PlayAudioMessageE();

			pMSGAudio.setCallSessionIdentifier(CallID);
			pMSGAudio.setCallParticipants(call.getCallParticipants());
			pMSGAudio.setAudioUrl(
                           new org.apache.axis2.databinding.types.URI("play=mission.wav;early=no;locale=en_us")
                        );
			pMSGAudioE.setPlayAudioMessage(pMSGAudio);

			//Execute the playAudioMessage
			AudioCallPlayMediaServiceStub.PlayAudioMessageResponseE pAMSGResponse =
                            audioCallPM.playAudioMessage(pMSGAudioE);

			System.out.println("audioMSGResponse"+ pAMSGResponse.getPlayAudioMessageResponse().getResult());

		}
		catch (org.apache.axis2.databinding.types.URI.MalformedURIException e) {
			System.out.println("Crap: malformed URI!");
			System.out.println(e.getMessage());
		}
		catch (org.csapi.www.wsdl.parlayx.third_party_call.v3_4.service.PolicyException e) {
			System.out.println("Crap: Policy Exception!");
			System.out.println(e.getMessage());
		}
		catch (org.csapi.www.wsdl.parlayx.third_party_call.v3_4.service.ServiceException e) {
			System.out.println("Crap: Service Exception!");
			System.out.println(e.getMessage());
		}

	}

}

 

Replace the bracketed variables with the appropriate values:

USERNAME
Ace User Name
PASSWORD
Ace Password
ACE_IP_ADDRESS
The IP Address of the ACE Server
SIP_URI
A properly formatted SIP URI that matches the provided ACE Documentation ( ie. number@ipaddress – see Coral CEA Sandbox Documentation for more on this topic ).

Now you should try to build and run this code snippet.

Your phone should ring after executing the code.

Adding User Interface (UI) to the Audio Call v3

Now lets try to add a simple UI for our code to perform the playAudioMessage service for a list of numbers to be called. We used the Java Swing library for constructing the UI for our sample. The sample code contains two main parts, first part is for handling the communication events (i.e. makeCall, playAudioMssage, etc) and second part is for handling the UI.

Using the sample code provided at the bottom, extract code to a local directory.

Create a new Java project and choose “Create project from existing source”" in Eclipse (as shown in figure below) and choose the directory where you extracted your files.



Now the project hierarchy should be as shown in the figure below.

Again make sure that you have added the Axis JAR files to the project “Build Path” and have imported the Audio Call Service definition files to the project.

Now we need to set the values of EndPoint address, audio file URI, authentication credentials, and finally called list names and corresponding phone numbers. You can find those parameters in the properties file that comes with the sample.

Now you can run the playAudioMSG_main.java and a window should appear as shown in figure below:

Now you can select one of the names to execute the playAudioMessage and makeCall service.

If the phone rings then the test is successful!