Third Party Call V3.0 Web Service – Java Tutorial
Download the Click 2 Call Java Tutorial Code Example
Introduction
The following example will provide you with a step-by-step description of how to develop a “Third Party Call Service v3″ (TPCSv3) 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
- Third party call WSDL definition files
- parlayx_third_party_call_interface_3_4.wsdl
- parlayx_third_party_call_service_3_4.wsdl
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:
From the command prompt go to the directory where the WSDL files were extracted (e.g. C:\WSDL\ThirdPartyCall).
- To convert the WSDL file definitions to Java execute the following command line : “C:\WSDL\ThirdPartyCall>WSDL2Java –uri parlayx_third_party_call_service_3_4.wsdl”
- And this operation should result a “src” that has all the required definitions and policy for the Third Party Call Service.
Create the Third Party Call Service sample
To create a Third Party 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.client.Options;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.csapi.www.wsdl.parlayx.third_party_call.v3_4.service.ThirdPartyCallServiceStub;
import java.rmi.RemoteException;
public class myTPCSv3Class {
/**
* @param args
*/
public static void main(String[] args) throws RemoteException {
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);
}
catch (org.apache.axis2.databinding.types.URI.MalformedURIException e) {
System.out.println("Malformed URI!");
System.out.println(e.getMessage());
}
catch (org.csapi.www.wsdl.parlayx.third_party_call.v3_4.service.PolicyException e) {
System.out.println("Policy Exception!");
System.out.println(e.getMessage());
}
catch (org.csapi.www.wsdl.parlayx.third_party_call.v3_4.service.ServiceException e) {
System.out.println("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 Third Party Call Service V3
Now lets try to add a simple UI for our code to perform the makeCall 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. third party make call, 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 Third Party Call Service definition files to the project.
Now we need to set the values of EndPoint address, authentication credentials, and 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 c2c_ui_main.java and a window should appear as shown in figure below:


Now you can select one of the names to execute the makeCall service.
If the phone rings then the test is successful

