Introduction
This tutorial shows how to use the playground web service interface to set up a call between two parties from a java client. The tutorial is based on the Third Party Call Parlay X web service, and illustrates how to create a java client invoking a web service. As a prerequisite we assume that you are familiar with the following technologies:
- HTML
- XML, SOAP and Web Services
- Eclipse - as an environment for Java and web service development
- Java, inclusive basic HTTP/URL handling
- SIP clients and SIP URIs
Follow the steps below to create a client which invokes the Third Party Call web service.
Place the cursor over this icon to expand screenshots from Eclipse.
- Download and install the Eclipse IDE (Web Tools Platform).
- Create a new project by selecting File | New | Java Project from the menu bar. This initiates the "New Java Project" wizard.
- Give the project a name, and choose your preferences on Java version and project organization. In this tutorial, we named the project "Make Call". The default values are used for all other selections.
- Push "Finish" to continue and close the wizard. The project is created, and the next steps describe how to start adding the required content to your project.
- Next, you have to create stubs for accessing the web services APIs. The process of creating stubs is described in a separate tutorial - Web services client tutorial. Alternatively you can download and store locally the file, playground.jar
- Add the library to your project. To do this, use the right mouse button on your project, and select "Properties", then click "Java Build Path" and "Add External JAR's" button, to select the JAR files. Click the OK button, when you are done.
- In addition to playground.jar you should add the following libraries to your project:
- activation.jar
- mail.jar
- axis.jar - the axis binary download also includes the following required libraries:
- commons-discovery-0.2.jar
- commons-logging-1.0.4.jar
- wsdl4j-1.5.1.jar
- jaxrpc.jar
- saaj.jar
- Add a new Java class to the project. Right click your project, and select "New -> Class" from the menu, to start the "New Java Class" wizard. Name the Java class, in this example "MyMakeCallDemo" and check for automatically generating the main method. Click "Finish" and the java class is generated.
- Finally, cut & paste from the source code below into your java class file
import org.apache.axis.client.Stub;
import org.apache.axis.types.URI;
import org.csapi.www.schema.parlayx.common.v2_1.PolicyException;
import org.csapi.www.schema.parlayx.common.v2_1.ServiceException;
import org.csapi.www.schema.parlayx.third_party_call.v2_3.CallInformation;
import org.csapi.www.schema.parlayx.third_party_call.v2_3.CallStatus;
import org.csapi.www.wsdl.parlayx.third_party_call.v2_3._interface.ThirdPartyCall;
import org.csapi.www.wsdl.parlayx.third_party_call.v2_3.service.ParlayXThirdPartyCall_0_2V1_WS;
import org.csapi.www.wsdl.parlayx.third_party_call.v2_3.service.ParlayXThirdPartyCall_0_2V1_WSLocator;
public class MyMakeCallDemo {
MyMakeCallDemo(String _username, String _pwd){
try {
ParlayXThirdPartyCall_0_2V1_WS thirdPartyCallService =
new ParlayXThirdPartyCall_0_2V1_WSLocator();
URL thirdPartyCallServiceAddress =
new URL(thirdPartyCallService.getThirdPartyCallPortAddress());
ThirdPartyCall cc_port =
thirdPartyCallService.getThirdPartyCallPort(thirdPartyCallServiceAddress);
/**
* Add the necessary authentication data
*/
Stub stub = (Stub)call;
stub.setUsername(_username);
stub.setPassword(_pwd);
/**
* Create the URIs with the address of the two parties
* to set up the call between.
*/
URI a_address = new URI("sip", "sip:????");
URI b_address = new URI("sip", "sip:????");
/**
* Set up the call
*/
String callIdentifier = call.makeCall(a_address, b_address, null);
System.out.println("Success, the call is made with " + callIdentifier );
Thread.sleep(1000);
/**
* Get call status until call terminates.
*/
CallStatus callStatus = null;
{
CallInformation status1 = call.getCallInformation(callIdentifier);
callStatus = status1.getCallStatus();
System.out.println("Success, the call status is " + callStatus );
} while (callStatus != CallStatus.CallTerminated);
System.out.println("Success, the call is now terminated" );
}
catch (PolicyException e){
System.out.println("Got an PolicyException.");
System.out.println("e.getText(): " + e.getText());
System.out.println("e.getClass(): " + e.getClass());
e.printStackTrace();
return;
}
catch (ServiceException e){
System.out.println("Got an ServiceException.");
System.out.println("e.getMessage(): " + e.getMessage());
System.out.println("e.getLocalizedMessage(): " + e.getLocalizedMessage());
System.out.println("e.getClass(): " + e.getClass());
e.printStackTrace();
return;
}
catch (Exception e) {
System.out.println("Got an Exception.");
System.out.println("e.getMessage(): " + e.getMessage());
System.out.println("e.getLocalizedMessage(): " + e.getLocalizedMessage());
System.out.println("e.getClass(): " + e.getClass());
e.printStackTrace();
return;
}
}
/**
* Use your main method to initiate an instance of the class
* and perform the logic placed in the constructor.
*
* Constructor arguments (username and password) are received
* in your welcome to the lab email
*
*/
public static void main(String[] args) {
String username = "[username]";
String password = "[password]";
new MyMakeCallDemo(username, password);
}
}
|


