Wiki

« Back to InAndOut

InAndOut-Java

Create the Application Project #

1. Open a command prompt.

2. The cuae requires at a minimum the name of the application project, the implementation language and the module name (java or csharp) to get started. If the language and or the module name are omitted the tool will prompt you for them. Lets use the cuae tool to create a new application.

C:\cd workspace\Etch
C:\workspace\Etch>cuae create InAndOut_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: inandout_java]

7. The tool then asks you for the Triggering event. As our application triggers on an incoming call, select the option 4 and press Enter.

Available application triggering event:
0: Skip this step 1: cisco.uc.cuae.legacy.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] 4}}}

cuae tool now generates the neccesary files for this application.

Generating:

  • application named "InAndOut_Java"
  • with namespace "inandOut_java"
  • with language "java"
  • with trigger event "cisco.uc.cuae.legacy.CallControl.IncomingCall"
  • in location C:\workspace\Etch\

Created project "InAndOut_Java" in directory "C:\workspace\Etch\InAndOut_Java\" }}}

8. Now we need to build the application. This can be done by two ways

-From command prompt: go to application created folder and issue the command 'ant'.

-IDE: By using Eclipse or any other IDE.

Here We are using Eclipse.

9. Open Eclipse. Provide the workspace location which is nothing but the path where your application is located. Click on browse an select the 'Etch'(where our application exists) folder.

10. Select File -> New -> Project

It will open a pop up 'New Project'. Select 'Java project from Existing Ant Buildfile' and click 'Next'

Click on browse and select 'build.xml' from 'C:\workspace\Etch\InAndOut_Java' folder.

Click on finish button. This will create a Java project in Eclipse IDE.

11. Right click in the 'build.xml' file from the project tree, which is at the left-hand side of the Eclipse IDE. Select 'Run As' -> '1 Ant Build Alt+Shift+X,Q'

This will compile and produce output in console window, which is at bottom side of Eclipse IDE.

Above steps create required java source files and other files require for this project. From left side of IDE select 'InAndOut_Java' project name in Project Explorer tab and then click 'F5' to reflect the created files in the project tree.

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 Securityfor 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.

Before running any application we need to register the application with server. To do this write the following code after

// TODO Insert Your Code here
. Save the changes.

String key = server.registerApplication("InAndOut_Java", "Default", "<username>", "<password>");
System.out.println("Application Successfully registered with key:"+key); System.out.println("Press Any key to exit from the application"); System.in.read();}}}

13. Open config.yaml file and enter following configuration for our application and save the changes.

# CUAE Application Configuration Definition

  1. You only need to edit this file if you want to expose configuration to
  2. the administrator through cuaeadmin.
  3. This file was auto-generated from a template but will never be
  4. overwritten. You should edit this file directly if required.
  1. configuration:
  2. Indicates the name of your configuration item. It will be how you
  3. reference this configuration item from code.
  4. - name: myConfValue
  1. Controls how the visible label of the configuration value. For
  2. example, if 'name' was defined as: myConfValue, you may choose to
  3. define 'displayName' as: My Config Value. Think of it as a friendly
  4. name. This field is optional.
  5. displayName: My Config Value
  1. Defines the format of the configuration item's value. This will
  2. control how cuaeadmin renders and validates the value. Possible
  3. values for the 'format' field are: String, Bool, Number, DateTime,
  4. IP_Address, Array, HashTable, DataTable, Password.
  5. format: String
  1. A description of the configuration item that will be displayed to
  2. the administrator in cuadmin. This field is optional.
  3. description: Some description here.
  1. For configuration items that are formatted as numbers, the
  2. 'minValue' and 'maxValue' configuration items define the acceptable
  3. range of input for the item. These fields are optional.
  4. minValue:
  5. maxValue:
  1. Defines the default value of the configuration. This field is
  2. optional.
  3. defaultValue:
  1. Inidicates whether the configuration item is editable. If
  2. 'readOnly' is set to true, the administrator will not be able to
  3. edit it in cuaeadmin, but will be able to view it. The default is
  4. false, and this field is optional.
  5. readOnly:
  1. Indicates whether the configuration item is required. If required,
  2. the administrator will have to set a value before the application
  3. will run. The default is false, and this field is optional.
  4. required: false, optional, default to be false

configuration: - name: discardLeadingDigits format: Number displayName: DiscardLeadingDigits defaultValue: 1 required: True

- name: destinationDN format: String displayName: To defaultValue: NONE required: True

- name: useConfigDN format: String displayName: UseConfigDN defaultValue: false required: True

- name: useFromDN format: String displayName: UseFromDN defaultValue: false required: True }}}

14. Double click on 'ImplInAndOut_JavaClient.java" to edit the file. As you are using the Util's classes HashMap and Map, import them into your file. Place these lines of code after package statement in the file.

import java.util.HashMap;
import java.util.Map;}}}

Declare and intialize these class variables:

String destinationDN = "";
int discardLeadingDigits = 0; boolean useConfigDN = false; boolean useFromDN = false; String inComingCallId = ""; String mmsId = ""; String outGoingCallId = "";}}}

Insert the following code after this line

// TODO insert methods here to provide implementations of InAndOut_JavaClient

// messages from the server.

Map<String, String> incomingCallIds = new HashMap<String,String>();
Map<String, String> outgoingCallIds = new HashMap<String,String>(); cisco.uc.cuae.EtchBridge.ConfigEntry[] configs;

@Override public void incomingCall(String sessionId, IncomingCallOptions options) { Read the application configuration try { ConfigEntry[] configs = server.getConfig("Default"); if ( configs == null || configs.length == 0) { return; }

try { for (int i = 0; i<configs.length; i++) { if (configs[i].name.matches("discardLeadingDigits")) { discardLeadingDigits = Integer.parseInt(configs[i].getConfigValue().toString()); } else if (configs[i].name.matches("destinationDN")) { destinationDN = configs[i].getConfigValue().toString(); } else if (configs[i].name.matches("useConfigDN")) { useConfigDN = Boolean.parseBoolean(configs[i].getConfigValue().toString()); } else if (configs[i].name.matches("useFromDN")) { useFromDN = Boolean.parseBoolean(configs[i].getConfigValue().toString()); } } } catch(Exception e) { System.out.println("Exception occured while reading application config:"+e); } } catch(Exception e) { System.out.println("Exception occuered while reading application configs :"+e); }

Accept callAcceptCallResult acr = server.acceptCall(sessionId, options.callId, new AcceptCallOptions()); incomingCallIds.put(sessionId, options.callId);

if (acr.returnValue != CuaeResult.SUCCESS) { System.out.println("answerCall failed"); server.removeCuaeSession(sessionId); return; } /

  • If application wants to discard leading digits before dialing the destination DN
  • or if in the application specified to take the destination DN from 'from DN'
  • /

if (!useConfigDN) { if (useFromDN) { Add to support SIP Phone In / SIP Trunk out testingint num;num= Integer.parseInt((options.from.substring(discardLeadingDigits)));num = num + 1;destinationDN = ""+num;}else{destinationDN = destinationDN.substring(discardLeadingDigits);}}MakeCallOptions mco = new MakeCallOptions();mco.conference = true;mco.conferenceId = "0";mco.hairpin = true;mco.mmsId = acr.mmsId; MakeCallResult mcr = server.beginMakeCall(sessionId, destinationDN, options.from, "InAndOut", mco, null);

outgoingCallIds.put(sessionId, mcr.callId);

if (mcr.returnValue != CuaeResult.SUCCESS) { System.out.println("Failed to beginMakeCall"); server.hangup(sessionId, options.callId, null); server.removeCuaeSession(sessionId); return; } } @Override public void onMakeCallComplete(String sessionId, MakeCallResult results, Object state) {

Get the Out going call id AnswerCallOptions aco = new AnswerCallOptions(); aco.conference = true; aco.conferenceId = results.conferenceId; aco.mmsId = results.mmsId;

if (results.returnValue == CuaeResult.SUCCESS) { AnswerCallResult acr = server.answerCall(sessionId, incomingCallIds.get(sessionId), "InAndOut", aco); if (acr.returnValue != CuaeResult.SUCCESS) { System.out.println("AnswerCall failed"); server.hangup(sessionId, results.callId, null); server.removeCuaeSession(sessionId); return; } } else { System.out.println("MakeCall Failed"); Reject the dialing phoneserver.hangup(sessionId, incomingCallIds.get(sessionId), null);server.removeCuaeSession(sessionId);}}@Overridepublic void startTx(String sessionId, StartTxOptions options){ } @Override public void startRx(String sessionId, StartRxOptions options) {

} @Override public void stopTx(String sessionId, StopTxOptions options) {

} @Override public void remoteHangup( String sessionId,RemoteHangupOptions options) { Get the callid's from respective Hash entriesinComingCallId = incomingCallIds.get(sessionId);outGoingCallId = outgoingCallIds.get(sessionId); if (inComingCallId.equals(options.callId)) server.hangup(sessionId, outGoingCallId, null); else server.hangup(sessionId, inComingCallId, null);

remove HashMap entriesincomingCallIds.remove(sessionId);outgoingCallIds.remove(sessionId); Close the cuae script for a sessionserver.removeCuaeSession(sessionId); } }}}

15. Save the project with your changes and build the project. To build follow step# 11

Package and Install the application#

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:\workspace\InAndOut_Java>cuae package
Created package file "C:\Development\CSHARP\workspace\InAndOut_Java\bin\InAndOut_Java.mca"

C:\workspace\InAndOut_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? [yes or no] n0 Application : C:\workspace\InAndOut_Java\bin\InAndOut_Java.mca Uploading : ===========================> 100% Application ahas been installed successfully }}}

Run the application#

1. login to application server's management console, click on Applications, click on InAndOut_Java. Now configure the application like which protocol to use, To number etc.

2.If you're adding a trigger, go to Applications -> Trigger and click on InAndOut_Java. Type in "To" and your route pattern. Select "Add Parameter".

3. Before using our installed application we need to run to get registered with server. To run the application, goto the eclipse editor and R-Click on MainInAndOut_JavaClient.java and Select "Run As" -> "Java Application".

4. Now execute the test suite which are mentioned in the main application wiki page.

0 Attachments
421 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
No comments yet. Be the first.