This example written in Java allows developers to manage VoipNow accounts. Download.
This demonstrative code SHOULD NOT be used in production. It is designed to show how a client application can interact with the VoipNow SystemAPI. Therefore there are no validations and the error checking is relaxed, in order to demonstrate the most common mistakes.
What This Example Does
This example uses SOAP calls to do the things specified below.
Ping the VoipNow Server
The result may be seen in the console of the IDE.
Get the Schema Versions from the Server
The result may be seen in the console of the IDE.
Create a Service Provider Account
A random charging plan from those created by the admin is assigned to this account.
Create an Organization Account
The parent of this organization is a randomly chosen service provider. Also, a random charging plan is assigned to this account from those created by its parent.
Exceptions
If the randomly chosen parent does not have permissions to add more organizations, the organization will not be added.
A Java exception will be seen in the console of your IDE:
org.apache.axis2.AxisFault: Unable to add more users. The limit has been exceeded. at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at com._4psa.voipnowservice._3_0_0.OrganizationPortStub.addOrganization(OrganizationPortStub.java:314) at main.TestAddOrganizationAccount.addAccount(TestAddOrganizationAccount.java:121) at main.TestAddOrganizationAccount.<init>(TestAddOrganizationAccount.java:45) at main.Main.main(Main.java:42)
To solve the issue, simply fix permissions.
Create a User Account
The parent of this user is a randomly chosen organization. Also, a random charging plan is assigned to this account from those created by its parent.
Exceptions
If the randomly chosen parent does not have permissions to add more users, the user will not be added.
A Java exception will be seen in the console of your IDE:
org.apache.axis2.AxisFault: Unable to add more users. The limit has been exceeded. at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at com._4psa.voipnowservice._3_0_0.UserPortStub.addUser(UserPortStub.java:448) at main.TestAddUserAccount.addAccount(TestAddUserAccount.java:113) at main.TestAddUserAccount.<init>(TestAddUserAccount.java:44) at main.Main.main(Main.java:45)
Create an Extension Account
The parent of this extension is a a randomly chosen user. Also, a random charging plan is assigned to this account from those created by its parent.
Exceptions
If the randomly chosen parent does not have permissions to add more extensions, the extension will not be added.
A Java exception will be seen in the console of your IDE:
org.apache.axis2.AxisFault: Unable to add more extensions of the required type. The limit has been exceeded. at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531) at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at com._4psa.voipnowservice._3_0_0.ExtensionPortStub.addExtension(ExtensionPortStub.java:2696) at main.TestAddExtensionAccount.addAccount(TestAddExtensionAccount.java:85) at main.TestAddExtensionAccount.<init>(TestAddExtensionAccount.java:44) at main.Main.main(Main.java:48)
How To Install It
System Requirements
In order to be able to use the Java example, your system should have:
- Java JDK 1.7.0 or later - the example is implemented with jdk1.7.0_06.
- Apache Axis2 1.6.2 or later - the example is implemented with axis2-1.6.2.
- Apache Ant 1.8.4 or later - the example is implemented with apache-ant-1.8.4.
Possible Problem
You might have a problem if the tool for running the example uses a JDK older than the JDK used for building the .jar
files.
Setup
Please download the tool archive.
In order to be able to test the tool, you need a Java IDE. Please follow these steps:
STEP 1: Create a project in your Java IDE.
STEP 2: Include the sources from the archive in the project.
STEP 3: Include the following jars in the project:
The jars from the archive |
|
The jars required by Axis2 | You can find them in AXIS2_HOME\lib and AXIS2_HOME\lib\endorsed . |
STEP 4: Configure some variables from the Constants.java
file. The following constants must be changed for the example to work:
- VOIPNOW_URL: the URL of your VoipNow server with the
http://<VOIPNOW_SERVER_IP>/
orhttps://<VOIPNOW_SERVER_IP>/ format
- ACCESS_TOKEN: the token generated with an authorized VoipNow application. You may find more info about how to generate the token here: Access Management.
STEP 5: Run the project. Observe the results in the console of the IDE. Look in the VoipNow interface to check the results. At least a service provider must be added.
Implementation Details
Authentication to the SystemAPI
Every SOAP request needs to contain the credentials for authenticate a user to the SystemAPI.
The credentials are passed as a UserCredentialsDocument class:
// this is the object representing the credentials UserCredentialsDocument ucd = UserCredentialsDocument.Factory.newInstance(); UserCredentialsDocument.UserCredentials cred = UserCredentialsDocument.UserCredentials.Factory.newInstance(); // set the token generated with an authorized application cred.setAccessToken(Constants.ACCESS_TOKEN); ucd.setUserCredentials(cred);
Add Service Provider
The following example shows how to add a new Service Provider account with SOAP requests in Java.
STEP 1: Create the authentication headers.
STEP 2: Create a Service Provider stub and turn off the Chunked HTTP Flag
ServiceProviderPortStub serviceProviderStub = new ServiceProviderPortStub(Constants.VOIPNOW_URL + "soap2/sp_agent.php"); serviceProviderStub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, false);
STEP 3: Create an AddServiceProvider object containing the information you want to use to create the account:
// Create the AddServiceProvider object AddServiceProvider add_sp = AddServiceProvider.Factory.newInstance(); //Set the company for the Service Provider add_sp.setCompany(Constants.COMPANY); //Set the name of the Service Provider add_sp.setName(Constants.NAME); ...
STEP 4: Wrap the AddServiceProvider object into a AddServiceProviderDocument object and call the addServiceProvider method on the stub:
// Create the AddServiceProviderDocument object AddServiceProviderDocument aspd = AddServiceProviderDocument.Factory.newInstance(); // Wrap the AddServiceProvider object into the AddServiceProviderDocument object aspd.setAddServiceProvider(add_sp); // Call the addServiceProvider method on the stub AddServiceProviderResponseDocument response_document = stub.addServiceProvider(aspd, cred);
The response is represented by an AddServiceProviderResponse object:
AddServiceProviderResponse response = response_document.getAddServiceProviderResponse(); // information from the response System.out.println("operation status: " + response.getResult());
This and more examples can be found in the downloaded package.
Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 4.0 International.