Wiki

« Back to HttpInitiatedP2PC...

HttpInitiatedP2PCallBridge-Java

Requirements#

The development machine where you are creating this application should have the following installed.

  1. Install JDK 1.5. Version we used is 1.5.0_15.
  2. Eclipse editor. Version we have used is 3.3.2.
  3. Install the CUAE Developer Tools to get the etch framework and cuae-tool.

Create the Application Project#

1. Open a Command Prompt.

2. To start with, the cuae-tool requires the name of the application project, the implementation language and the module name (java or csharp). If the language and or the module name are omitted, the tool will prompt you for these. Let's use the cuae-tool to create a new application.

  • Create a folder named "Wxp" in C: directory.

 C:\> cd Wxp
C:\Wxp> cuae create HttpInitiatedP2PCallBridge_java}}}

3. The cuae tool will ask for the type of project that you are creating is it application or Plugin. Answer is 'application.'

Project Type? [application or plugin] application

4. Next the cuae tool will ask for the programming language Java or CSharp. Answer is 'java'.

Programming language? [java or csharp] java

5. The cuae tool will ask for the build format that we will be using for this application. Answer Ant.

Build format? [ant or maven2] ant

6. Next the tool will ask you for the namespace for the application, e.g. a Java program might want to use a fully qualified namespace like com.company.inandout_java or something simple like inandout. The tool will offer you a simple namespace based on the project name. Let's accept the tools suggestion for now and use inandout_java. Press Enter

Project namespace? [default: httpinitiatedp2pcallbridge_java]

7. The tool then asks you for the Triggering event. As our application triggers on an GotRequest, select the option 5

   1.JTapi.JTapiIncomingCall
2: cisco.uc.cuae.legacy.JTapi.JTapiCallInitiated 3: cisco.uc.cuae.legacy.JTapi.JTapiCallEstablished 4: cisco.uc.cuae.legacy.CallControl.IncomingCall 5: cisco.uc.cuae.legacy.Http.GotRequest 6: cisco.uc.cuae.legacy.Presence.SubscriptionTerminated 7: cisco.uc.cuae.legacy.Presence.Notify 8: cisco.uc.cuae.legacy.TimerFacility.TimerFire Triggering event? [0-8] 5}}}

8. Now the cuae-tool will create the all the necessary files for this application.

 Generating:

  • application named "HttpInitiatedP2PCallBridge_java"
  • with namespace "httpinitiatedp2pcallbridge_java"
  • with laguage "java"
  • with trigger event "cisco.uc.cuae.legacy.Http.GotRequest"
  • in location C:\Wxp\

Created project "HttpInitiatedP2PCallBridge_java" in directory "C:\Wxp\HttpInitiatedP2PCallBridge_java\"}}}

9. Now goto C:\Wxp\HttpInitiatedP2PCallBridge_java folder. Open the file HttpInitiatedP2PCallBridge_java.etch in a notepad and add the last three lines , starting with "mixin" , and save the file. We are adding the MediaControl mixin because the application will be playing some prompts. To play these prompts the media engine will be using TTS.

 /// CUAE Application Etch Service Definition
This service defines your application and the CUAE services that you use in your application.

The service module namespace, this will be translated to the namespace of the generated source code. module httpinitiatedp2pcallbridge_java

The name of your service.service HttpInitiatedP2PCallBridge_java{ By default, you must always use the EtchBridge service. Do not remove this mixin, otherwise your application won't work.mixin cisco.uc.cuae.EtchBridge

You may add any additional service mixins that you require. For example, if you'd like to make and receive phone calls, add the following line: mixin cisco.uc.cuae.legacy.CallControl mixin cisco.uc.cuae.legacy.Http mixin cisco.uc.cuae.legacy.CallControl mixin cisco.uc.cuae.legacy.MediaControl } }}}

10. Goto cuae-resources in HttpInitiatedP2PCallBridge_Java project. Open file Config.yaml in notepad and add the configuration items. These items can be configured from CUAE once the application is installed on the application server.

configuration:
- name: DialNum1 format: String displayName: DialNum1

- name: DialNum2 format: String displayName: DialNum2 }}}

11. From the cmd shell goto application directory, run Ant to generate source files.

12. Now open Eclipse and click on File->New->Project.

  • It will open a new window. Select Java Project from Existing Ant Bildfile and click Next.

  • A new window will open. Browse for the Build-file to C:\Wxp\HttpInitiatedP2PCallBridge_java, select Build.xml and click on Finish.

  • Ensure that the build was successful. It will create two files, named MainHttpInitiatedP2PCallBridge_javaClient.java and ImplHttpInitiatedP2PCallBridge_javaClient.java, under src->httpinitiatedp2pcallbridge_java. These are the two files in which we have to define and implement our application.

13. Now we need to make the code changes into the file MainHttpInitiatedP2PCallBridge_javaClient.java. Open it and make the following changes in the code.

Modify the String URI to match the IP address and port of the Cisco Unified Application Server.

URI settings vary slightly between 2.5(1) Beta 1 and more recent versions of 2.5(1), as follows:

2.5(1) and 2.5(1) Beta 2, Beta 3, Beta 4 & later releases#

// TODO Change to correct URI
String uri = "tls://appserver_ipaddress:9000?TlsConnection.authReqd=false&filter=KeepAlive &KeepAlive.Count=5&Packetizer.maxPktSize=102400&TcpTransport.reconnectDelay=4000"; }}}

Note: In Beta 2, the Etch Bridge was updated to use Transport Layer Security for encryption by default. For your applications to work, you must specify TLS as the protocol in the URI and set the authReqd parameter to false. In the example above, the KeepAlive filter and Max Packet Size and Reconnect Delay parameters have also been set.

2.5(1) Beta 1#

// TODO Change to correct URI
String uri = "tcp://appserver_ipaddress:9000?&TcpConnection.reconnect_delay=4000";}}}

Note: In addition to setting the correct IP address and port for the Cisco Unfied Application Server, the Reconnect Delay parameter should be set on all connection URIs.

  • The other change that we need to make in this file is:-

 // TODO Insert Your Code Here
Registering the application to the Application Server. Administrator credentials are used to register the application.

String key = server.registerApplication("HttpInitiatedP2PCallBridge_java", "Default", "<username>", "<password>"); System.out.println("HttpInitiatedP2PCallBridge_java registered with key = " + key);

System.in.read(); }}}

14. We'll now open the file ImplHttpInitiatedP2PCallBridge_javaClient.java and make the following code changes.

  • Global variables need to be defined.

//Global variables to collect the configuration variables
public String DialNum1 = ""; public String DialNum2 = ""; public String g_CallId1 = ""; public String g_CallId2 = ""; public String[] arr_Partitions; public ConfigEntry[] configs;}}}

  • We need to override some predefined methods.

// TODO insert methods here to provide implementations of HttpInitiatedP2PCallBridge_javaClient
messages from the server.

@Override public void gotRequest(String sessionId, GotRequestOptions options) { try { arr_Partitions = server.getPartitions(); for(int i=0;i<arr_Partitions.length;i++) { if (arr_Partitions[i].equals("Default")) { configs = server.getConfig(arr_Partitions[i]); } } } catch(cisco.uc.cuae.EtchBridge.BridgeException err) { System.out.println("The error occurred in getting partitions is :" + err); }

if (configs == null || configs.length == 0) return;

try { for(int i = 0; i<configs.length;i++) { if(configs[i].name.matches("DialNum1")) { DialNum1 = configs[i].configValue.toString(); }

if(configs[i].name.matches("DialNum2")) { DialNum2 = configs[i].configValue.toString(); } } }

catch(Exception e) { System.out.println("Error in reading the application configs " + e.getMessage()); } String str1 = "Call1"; MakeCallResult mcr = server.beginMakeCall(sessionId,DialNum1, null, null, null ,str1);

if (mcr.returnValue == CuaeResult.SUCCESS) { server.sendResponse(sessionId, options.remoteHost, 200, "text/plain", "Call Initiated successfully", "Ok", null); g_CallId1 = mcr.callId; server.sessionEnd(sessionId, null); } else { server.sendResponse(sessionId, options.remoteHost, 200, "text/plain", "Make Call Failed", "Ok", null); server.hangup(sessionId, null, null); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId, null); }

} @Override public void sessionExpired(String sessionId, SessionExpiredOptions options) { server.hangup(sessionId, null, null); server.removeCuaeSession(sessionId); }

@Override public void onMakeCallComplete(String sessionId, MakeCallResult results, Object state) { if (state.toString().equalsIgnoreCase("Call1")) {

PlayResult pr = server.beginPlay(sessionId, "Hello, this is a P2P test application. Press 1 to continue. Or press 2 to hangup", results.connectionId, null, null, state); if (pr.returnValue != CuaeResult.SUCCESS) { System.out.println("Play Failed!!!"); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId, null); } else { System.out.println("Play successful"); }

GatherDigitsOptions gdoptions = new GatherDigitsOptions(); gdoptions.termCondDigitList = "12";

GatherDigitsResult gdresult = server.beginGatherDigits(sessionId, results.connectionId, gdoptions, state);

if(gdresult.returnValue != CuaeResult.SUCCESS) { System.out.println("GatherDigit Failed"); server.removeCuaeSession(sessionId); server.sessionEnd(sessionId, null); } else { System.out.println("GatherDigit Successful"); } } else if (state.toString().equalsIgnoreCase("Call2")) { System.out.println("Now creating P2P bridge"); UnbridgeCallsOptions uco = new UnbridgeCallsOptions();

UnbridgeCallsResult ucr = server.unbridgeCalls(sessionId, g_CallId1, g_CallId2, uco);

if (ucr.returnValue == CuaeResult.SUCCESS) { System.out.println("The two calls are bridged successfully"); } else { System.out.println("The two calls could not be bridged"); } } }

@Override public void onGatherDigitsComplete(String sessionId, GatherDigitsResult result, Object state) { if(result.digits.contains("1")) { String str2 = "Call2"; MakeCallResult mcr1 = server.beginMakeCall(sessionId, DialNum2, null, null, null, str2); System.out.println("Test 3:-"); if (mcr1.returnValue == CuaeResult.SUCCESS) { System.out.println("Call Initiated successfully."); g_CallId2 = mcr1.callId; } else { System.out.println("Make Call Failed!!!");

server.sessionEnd(sessionId,null); } } else { server.hangup(sessionId, g_CallId1, null); } } }}}

Packaging and loading the application#

  • Once the above mentioned changes are made, open a command window and change directory to C:\Wxp\HttpInitiatedP2PCallBridge_java and run the below given command.

C:\Wxp\HttpInitiatedP2PCallBridge_java>cuae package

Installing The Test Application#

  • To install the test application on a CUAE server, execute the cuae install command from a DOS command shell in test application parent directory of the test application. The cuae install command varies slightly between 2.5(1) Beta 1 and Beta 2.

2.5(1) Beta 2#

You are prompted to enter an IP address, username, and password (to view the help, run the cuae install -h command). When prompted, enter Y or N to save management settings. This will save the answers to the above three questions in the properties file and remember them the next time you go to install.

Note: You are also prompted for the communications protocol (TCP or TLS). Select the protocol that is set on the Management Service. TLS is the default supported protocol. If you want to use TCP, follow the instructions in Management Service Transport Layer Security (TLS) to change the default URI of the Management Service before running these commands.

C:\Wxp\HttpInitiatedP2PCallBridge_java>cuae package
Created package file "C:\Wxp\HttpInitiatedP2PCallBridge_java\bin\HttpInitiatedP2PCallBridge_java.mca"

C:\Wxp\HttpInitiatedP2PCallBridge_java>cuae install Enter the hostname or IP address of the management service (for example: localhost, 1.1.1.1): localhost Protocol: tls Generated mgmt-service uri: tls://localhost:9001?TlsConnection.authReqd=false Enter management service login username: Entermanagement service login password: Save the amanagement settings with the project? [yes or no] no Application : C:\Wxp\HttpInitiatedP2PCallBridge_java\bin\HttpInitiatedP2PCallBridge_java.mca Uploading : ===========================> 100% Application has been installed successfully}}}

2.5(1) Beta 1#

You are prompted to enter an IP address, username, and password (to view the help, run the cuae install -h command). When prompted, enter Y or N to save management settings. This will save the answers to the above three questions in the properties file and remember them the next time you go to install.

C:\Wxp\HttpInitiatedP2PCallBridge_java>cuae package
Created package file "C:\Wxp\HttpInitiatedP2PCallBridge_java\bin\HttpInitiatedP2PCallBridge_java.mca"

C:\Wxp\HttpInitiatedP2PCallBridge_java>cuae install Enter management service uri or host/IP <for example: localhost, tcp://1.1.1.1.:4001>: Enter management service login username: Entermanagement service login password: Save the amanagement settings with the project? [YyNn] n Application : C:\workspace\HttpInitiatedP2PCallBridge_java\bin\HttpInitiatedP2PCallBridge_java.mca Uploading : ===========================> 100% Application ahas been installed successfully}}}

Note: You need to provide the uri for your application server. Like

tcp://<IP address of your application server>:4001
and then you need to provide the login username and password for the application server.

Running the application#

  • Before running the application, we need to make some configurations
  • Find the application you have just installed in CUAE Admin (Applications -> List Applications).
  • Click on the application and configure the fields with DN's to place a call

  • After all the above mentioned changes are made, R-click on the Build.xml and run it as Ant Build (As told in step 10).
  • R-click on the MainHttpInitiatedP2PCallBridge_javaClient.java and select the option Run as -> Java Application

  • It will register the application with the application server and start waiting for the triggering event to occur.
  • Login into CUAE admin goto Applications -> List Triggers. Select the application and add trigger parameter "url" and it's value "P2PBridged".
  • To trigger the application, open a web-page and write
    http://<IP address of the Application Server>:8000/P2PBridged
    . This will trigger the application and it will start executing
0 Attachments
270 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
No comments yet. Be the first.