Open Interfaces CCT SDK_img_0

CCT Open Interfaces SDK

Tutorial 1 - CXF

1.       Introduction. 2

2.       SOA CCT Tutorial using CXF. 2

Description of Tutorial 2

Notes about this tutorial 3

Step 1: Updating the local hosts file. 4

Step 2: Create Project 4

Step 3: Create Web Service Proxy classes using CXF’s wsdl2java tool 7

Step 4: Create Notification Consumer Service Stubs. 9

Step 5: Create User API Form.. 11

Step 6: Login to CCT Server. 13

Step 7: Logging in an Agent 16

Step 8: Create a new Contact 17

Step 9: Publish Notification Consumer Service. 18

Step 10: Subscribe for Notifications – using NotificationProducer Service. 20

3. Running the Sample Application. 23

 

 

1.            Introduction

This tutorial is intended to bring you through the first steps involved in creating your 3rd party application using WebServices. This tutorial will show you how to:

·         Update your local hosts file.

·         Connect to the splash screen.

·         Create Web Service Proxy classes using CXF’s wsdl2java tool.

·         Create Notification Consumer Service Stubs.

·         Login to the CCT server.

We will also provide you with sample code for you to work with.

 

 

2.            SOA CCT Tutorial using CXF

Description of Tutorial

This tutorial describes how to utilise the features provided by the SOA CCT Web Services. It demonstrates how a new contact can be created, notifications received, and the state of an agent changed, all through web services.

The main procedures in this tutorial are:

Step1: Updating the local hosts file

Step 2: Create Project

Step 3: Create Web Service Proxy classes using CXF’s wsdl2java tool

Step 4: Create Notification Consumer service stubs using wsdl2java

Step 5: Create User API

Step 6: Login to CCT Server

Step 7: Logging in an Agent

Step 8: Creating a new Contact

Step 9: Publish Notification Consumer Service

Step 10: Subscribe for Notifications

This tutorial utilises the Session Service and the Notification Producer Service to demonstrate this functionality.

Please download the source code here.

Notes about this tutorial

The SOA Web Services must be installed and running on an available server.

The tutorial uses eclipse as the IDE and CXF 2.2.5 to publish services.

Apache CXF bin directory has been added to the environmental PATH variable.

Common programming practices such as delegates, events, threading, and exceptions are left to the individual programmer and are not covered in this tutorial.

Exception handling is not shown in the code samples for brevity.

You must determine exactly where or how you want to implement the example code shown in these tutorials in your own application.

 

 

Step 1: Updating the local hosts file

1. Open up the hosts file and map the host name of your server to an IP address

 

 

Step 2: Create Project

To create an Eclipse Java Project:

1. Open Eclipse IDE.

2. Select File > New > Java Project.

3. Select Next.

4. Enter Project Name & Location as desired.

5. Select Next, Next & Finished.

6. Add a new src folder: Right click on the project tab, Select New->Src Folder. Folder named ‘autogen.src’ in this tutorial and is where generated code will be stored.

 

 

 

Step 3: Create Web Service Proxy classes using CXF’s wsdl2java tool

1. Open a command window.

2. Cd to the project’s autogen.src directory.

3. Run wsdl2java command supplying front end and the service url.

e.g. wsdl2java  http://<SERVER_IP_ADDRESS>:<SOA_OPEN_PORT>/SOAOICCT/services/SessionService?wsdl

4. Refresh project in eclipse to import generated files.

The Open Interface Splash is available on the SOA Server: http://<SERVER_IP_ADDRESS>:9090/OI_Splash.jsp

 

 

 

Step 4: Create Notification Consumer Service Stubs

1. Open a command window.

2. Cd to the project’s autogen.src directory.

3. Run wsdl2java –client command supplying the url to the notification consumer wsdl.

4. Refresh project in eclipse to import generated files.

The Notification Consumer wsdl is available from the SOA Server splash screen, available on the SOA Server: http://<SERVER_IP_ADDRESS>:9090/NotificationConsumer.html

 

 

 

Step 5: Create User API Form

The following user form is used through this tutorial. To continue with this tutorial, you must:

[Refer to UserAPIForm.java in project src code]

1.      Add the following controls to the design surface.

2. Add Event Handlers

3. Create a button click event handler for the Connect button.

Code sample: Connect button click event handler stub

private void connectActionPerformed(java.awt.event.ActionEvent evt) {

}

 

4. Create a button click event handler for the Create button.

5. Create a button click event handler for the Login button.

 

 

 

Step 6: Login to CCT Server

[Refer to SessionServiceUtil.java in the source of the sample project]

1. Create a private attribute for the service classes required as shown below.

Code sample: Declare service attributes

private SessionService sessionService;

 

 

2. Instantiate the service classes as shown below.

Code sample: Instantiating the Service Proxies

try {

          String sslocation = "http://" + serverDetails":" + serverPort + "/SOAOICCT/services/SessionService?wsdl";

            URL url = new URL(sslocation);

            sessionService = new SOAOICCT(url).getSessionService(); 

} catch (Exception e) {

          e.printStackTrace();

            throw e;

}

 

 

3. Set the User Credentials in a Login Request as shown below.

Code sample: Create Request to Login to CCT Server

LogInToCCTServerRequest loginRequest = new LogInToCCTServerRequest();

loginRequest.setAuthenticationLevel(new AuthenticationLevel());

loginRequest.getAuthenticationLevel().setDomain(domain);

loginRequest.getAuthenticationLevel().setPassword(password);

loginRequest.getAuthenticationLevel().setUsername(user);

 

 

4. Invoke the Login Request & Retrieve Session Token.

Code sample: Invoking SessionServiceloginToCCTServer request

try {

     LogInToCCTServerResponse response = sessionService.logInToCCTServer(loginRequest);

     ssoToken = response.getSsoToken();

} catch (LogInToCCTServerException ex) {

     //handle exception

}

5. Maintain the ssoToken returned from login : it identifies the users session and a valid SSO token is required for all other service requests.

 

 

6. Retrieve terminals associated with the user.

Code sample: Get Terminals Request

GetTerminalsRequest getTerminalsRequest = new GetTerminalsRequest();

 

getTerminalsRequest.setSsoToken(ssoToken);

 

TerminalList terminalsList = sessionService.getTerminals(getTerminalsRequest);

 

if (terminalsList != null) {

        List<Terminal> terminals = terminalsList.getTerminals();

        return terminals;

} else {

         return new ArrayList<Terminal>();

}

 

 

 

 

Step 7: Logging in an Agent

[Refer to UserAPIForm.java in the source of the sample project]

Code sample: Login Agent Request

String agentId = txtAgentID.getText().trim();

LoginAgentRequest loginAgentRequest = new LoginAgentRequest();

 

loginAgentRequest.setSsoToken(ssoToken);

loginAgentRequest.setAgentId(agentId);

loginAgentRequest.setTerminal(terminal);

loginAgentRequest.setAgentPassword(password);

 

sessionService.loginAgent(loginAgentRequest);

 

 

Step 8: Create a new Contact

[Refer to UserAPIForm.java in the source of the sample project]

Code sample: Create a Contact

public static Contact createContact(SsoToken ssoToken,Terminal terminal, Address srcAddress, String destAddressName) throws Exception {

try {

     CreateContactRequest createContactRequest = new CreateContactRequest();

     createContactRequest.setSsoToken(ssoToken);

     createContactRequest.setTerminal(terminal);

 

     Address destAddress = new Address();

     destAddress.setAddressName(destAddressName);

     createContactRequest.setDstAddress(destAddress);

     createContactRequest.setSrcAddress(srcAddress);

     ContactResponse resp = sessionService.createContact(createContactRequest);

     return response.getContact();

 

} catch (Exception ex) {

     throw ex;

}

 

 

 

Step 9: Publish Notification Consumer Service

[Refer to SubscribeUtil.java in the source of the sample project]

1. Add a class to implement Notification Consumer Service interface as follows.

Code sample: Service Implementer

@javax.jws.WebService(name = "NotificationConsumer",

serviceName = "SOAOICCT_NotificationConsumer",

portName = "NotificationConsumer",

targetNamespace = "http://www.nortel.com/soa/oi/cct/NotificationConsumer",

endpointInterface = "com.nortel.soa.oi.cct.notificationconsumer.NotificationConsumer")

 

public class NotificationConsumerImpl implements NotificationConsumer

{

     @Override

     public void notify(List<NotificationMessageHolderType> notificationMessage) {

          // TODO Handle Notification Here

     }

}

 

 

3. Publish the service class.

Code sample: Publish Notification Consumer Service

public static void publishNotificationConsumer() {

     String ncUri = "http://" + getIpAddress() + ":" + port + "/SOAOICCT/services/NotificationConsumer";

     notificationHandler = new NotificationConsumerImpl();

      Endpoint.publish(notificationConsumerUri, notificationHandler);

}

 

NOTE: You can verify the NotificationConsumer is up by viewing the wsdl in a web browser

e.g. http://<LOCAL_SERVER>:9090/SOAOICCT/services/NotificationConsumer?wsdl

 

 

Step 10: Subscribe for Notifications – using NotificationProducer Service

[Refer to SubscribeUtil.java in the source of the sample project]

 

1. Define Endpoint Reference Type.

This details the notification consumer service endpoint where notifications will be sent to.

Code sample: Define a EndpointReferenceType

//Setup the endpoint reference type object

EndpointReferenceType consumerReference = new EndpointReferenceType();

AttributedURI uri = new AttributedURI();

value.setValue(notificationConsumerUri);

 

//QName(targetNameSpace, serviceName)

QName name = new QName("http://www.nortel.com/soa/oi/cct/NotificationConsumer", "SOAOICCT_NotificationConsumer");

 

consumerReference.setAddress(uri);

 

consumerReference.setServiceName(new ServiceNameType());

 

consumerReference.getServiceName().setPortName("NotificationConsumer");

 

consumerReference.getServiceName().setValue(name);

 

  

    2. Define Subscription Policy.

         These attributes are set to true if session related notifications are required.

Code sample: Define a subscription policy

SubscriptionPolicyType subscriptionPolicy = new SubscriptionPolicyType();

 

subscriptionPolicy.setSessionTerminationImminentNotificationsEnabled(true);

 

subscriptionPolicy.setSessionTerminationNotificationsEnabled(true);

 

subscriptionPolicy.setSubscriptionTerminationImminentNotificationsEnabled(true);

 

subscriptionPolicy.setSubscriptionTerminationNotificationsEnabled(true);

 

 

    3. Define Topic Expression.

This details the types of notifications that will be subscribed for. In the example below TerminalConnectionStateListeners are registered for.

Code sample: Define a Topic Expression

//Detail the types of notifications that you are going to subscribe for

TopicExpressionType topicExp = new TopicExpressionType();

topicExp.setDialect("Simple");

NotificationTopicType notificationTopic = new NotificationTopicType();

                    

TerminalConnectionStateListenerType terminalConnectionStateListener = new TerminalConnectionStateListenerType();

List<TerminalConnectionState> terminalConnectionStateListenerEvents = new ArrayList<TerminalConnectionState>();

terminalConnectionStateListener.getTerminalConnectionStateEvent().addAll(terminalConnectionStateListenerEvents);

List<Terminal> terminalConnectionStateListenerEntities = new ArrayList<Terminal>();

terminalConnectionStateListener.getTerminalEntity().addAll(terminalConnectionStateListenerEntities);

notificationTopic.setTerminalConnectionStateListener(terminalConnectionStateListener);

                    

QName _TopicExpressionTypeNotificationTopic_QNAME = new QName("http://www.nortel.com/soa/oi/cct/BaseNotification", "NotificationTopic");

JAXBElement<NotificationTopicType> notificationTopicType = new JAXBElement<NotificationTopicType>(_TopicExpressionTypeNotificationTopic_QNAME, NotificationTopicType.class, TopicExpressionType.class, notificationTopic);

                    

topicExp.getContent().add(notificationTopicType);

 

4. Call the Notification Producer subscribe method.

Code sample: Notification Consumer Subscription

try {

      EndpointReferenceType subscriptionEndpoint = notificationProducerService.subscribe(

            consumerReference,

            topicExp,

            useNotify,

            precondition,

            selector,

            subscriptionPolicy,

            initialTerminationTime,

            ssoToken);

} catch (Exception e ) {

           e.printStackTrace();

            throw e;

}

 

 

NOTE: Maintain the subscriptionEndpoint returned from subscribe as it will be required to unsubscribe.

 

 

 

 

3. Running the Sample Application

1.      Download the zip file.

2.      Open Eclipse.

3.      Import an existing project using File – Import option.

 

4.      To set the input, open the Run Dialog & provide the details required (server & user details).

5.      Enter in the appropriate details.

a.      Program arguments:

                                                                i.      Server Name – cs1ktest

                                                              ii.      Open SOA OI CCT port number - 9180

b.      VM Arguments

                                                                i.      User Name Duser=”agent123123”

                                                              ii.      User Password -Dpassword=”password123”

                                                            iii.      Domain -Ddomain=”localhost”

 

 

6.      Once Project is imported & compiled, Right click on project & select Run As – Java Application.

 

7.      Once Running – validate the Notification Consumer endpoint is running by using a web browser.

 

untitled

 

8.      Click Connect – this attempts to login the user and subscribe for notifications.

 

 

9.      Enter Agent ID & Click login to login agent.

 

 

10.  Enter valid destination address & click on Create to create a contact.