ibm sametime meetings server api

17

Click here to load reader

Upload: paul-godby

Post on 11-May-2015

578 views

Category:

Software


5 download

DESCRIPTION

In this lab you will use the IBM Sametime Remote Client SDK Java APIs to create new persistent meetings in a Sametime environment.

TRANSCRIPT

Page 1: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Author: Paul GodbyEcosystem DevelopmentLast Updated: November 12, 2013

IBM Sametime 9.0 Workshop

Lab Manual

IBM Sametime Meetings Server API

NOTE: In this lab you will be writing code. If you are not a developer (or if you don't feel like typing everything)you can choose to copy/paste the code from the lab solutions files located at:

C:\labs\solutions\IDR-MEETINGSAPI

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

1

Page 2: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Introduction:The IBM Sametime Remote Client SDK package provides Java APIs for room creation and management services as well as real time services against the IBM Sametime Meetings Server. The SDK exposes room management services that mirror the capabilities of the Meeting Center, and real-time services that mirror the capabilities of the Sametime meeting clients.

The IBM Sametime Meetings server, since version 8.5, is based on REST-ful web services. The IBM Remote Client toolkit provides a clean Java wrapper around the room management REST APIs making it easy for customers and partners to integrate and build applications against the server.

In addition to room management services, such as creating, editing, deleting, and searching for rooms, newer versions provide real time services, including creating annotations, sharing document content, logging into a room using an LTPA token, and more.

Description:In this lab, you will learn how to use the Sametime Meetings API to programmatically create and retrieve meetings from an IBM Sametime Meeting server. Using these techniques, you can begin integrating advanced meetings capabilities directly into your own desktop applications. Additionally, you can leverage these APIs into an existing J2EE application to bring these services into your own web applications.

Objective:This lab will explain the following tasks:

Creating a new Java project in Eclipse

Configuring a Java project for Sametime Meetings API development

Using the API to create new meetings

Using the API to retrieve a list of meetings for a specific user

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

2

Page 3: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Procedure:

SERVER SETUP

In order to complete this lab exercise, the following servers will need to be running: LDAP, IBM SametimeMeeting server

Choose one of the following options below to prepare your server environment for this lab.

(Option 1) Start all IBM Sametime services

1. Follow the instructions in the document: How to Start Up Sametime 9.0 with Audio / Video

(Option 2) Start ONLY the IBM Sametime services required for this lab

1. Configure the hosts file using the instructions in the document named in option 1

2. On the desktop, double-click the script: startLDAP.bat

3. On the desktop, double-click the script: startMeeting.bat

CREATE A NEW IBM SAMETIME MEETING

Before beginning the programming exercises, you should first review the Sametime Meeting Room Center. Inthis section, you will use the web interface provided by the server to create a new meeting room and examine thepossible attributes you can associate with the room (such as the room name, password, etc.).

Step 1 In a web browser, navigate to URL: http://sametime9vm.demos.ibm.com:9082/stmeetings

Step 2 (If prompted, accept the certificate) Log in with the following credentials

Field Value

User name dmisawa

Password passw0rd

Step 3 In the middle of the page, click New Meeting Room

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

3

Page 4: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 4 In the New Meeting Room form, enter the following information:

Field Value

Room name Meeting Center UI Room

Password << blank >>

This is a hidden room << unchecked >>

Meeting room has managed access << unchecked >>

Call-in information 111-222-333-4444

Step 5 When finished, click Save.

Step 6 The new room should appear in the user's list of meeting rooms. On the right-hand side of the page, click the more link ( the 2 down arrows ) to expose more information about the room.

Step 7 As you can see in the page, most attributes for the meeting room are listed in the UI. You can very easily see the meeting's name, that no password is required, that the room is not hidden, that participants can join the room at any time, and the call-in information.

Step 8 (Optional) Click the Enter Meeting Room link to explore IBM Sametime Meetings functionality.

Step 9 When finished, leave the web browser open and return to the Windows desktop.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

4

Page 5: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

PREPARE A PROJECT USING THE ECLIPSE IDE

The Eclipse IDE is free and contains tools for creating Web applications, including editors for Java, JavaScript,HTML, CSS, and XML. Best of all, this IDE is free to use. Visit www.eclipse.org/downloads for more information.

Step 10 On the desktop, double-click the “Eclipse” icon to start the Eclipse IDE.

Step 11 In the Workspace Launcher window, you will select a location for your development workspace.A workspace is a development profile that contains your projects, folders, files, and settings. Enter the following information and click OK.

Field Value

Workspace C:\labs\workspaces\sametime_java

Step 12 If you see the Lotus Expeditor Toolkit Configuration dialog, click Cancel.

Step 13 If you see the Welcome to Eclipse page, click the “Workbench” button.

Step 14 From the Eclipse file menu, choose File → New → Project

Step 15 In the New Project wizard, choose Java → Java Project and click Next.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

5

Page 6: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 16 In the New Java Project wizard, enter the following information and click Finish.

Field Value

Project name IDR-MEETINGSAPI

Step 17 If asked about switching to a Java Perspective, click Yes.

Step 18 From the Eclipse top menu bar, click Window → Preferences

Step 19 Expand General → Editors → Text Editors

Step 20 On the right, place a check next to the option “Show line numbers” and click OK.

CREATE NEW JAVA PACKAGES

A Java package is a mechanism for organizing Java classes into namespaces. Programmers also typically usepackages to organize classes belonging to the same category or providing similar functionality.

Step 21 In the Eclipse IDE, expand the project, right-click the “src” folder and choose New → Package.

Step 22 In the New Java Package window, enter the following information and click Finish.

Field Value

Name com.ibm.idr.st.meet

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

6

Page 7: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

PREPARE THE SAMETIME MEETING SERVER API LIBRARIES

In this exercise, you will be using the IBM Sametime Meetings API to write a simple Java application that cancreate and retrieve meetings from the IBM Sametime Meetings server.

In this section you will add the required JARS from the SDK to your Java project.

Step 23 Return to the Eclipse IDE. Right-click the “src” folder and select Build Path → Configure Build Path...

Step 24 Choose the Libraries tab.

Step 25 Click Add External JARS...

Step 26 Navigate to the following location and select the following files (hold down the CTRL key to select multiple files). These libraries contain both the Meeting Server APIs and any of the required dependencies. When finished, click Open.

Field Value

Location C:\labs\st9sdk\server\meeting\toolkit\lib

Files apache-mime4j-<version#>.jarcommons-logging-<version#>.jarhttpclient-<version#>.jarhttpcore-<version#>.jarhttpcore-nio-<version#>.jarhttpmime-<version#>.jarJSON4J.jarmeeting.client.core.jar

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

7

Page 8: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 27 Click OK to close the Java Build Path window. In the Package Explorer on the left, expand the Referenced Libraries section. Verify that you have the following libraries listed. If you are missing any, repeat the previous steps until they are all listed. (Note: Your version numbers may vary from the screenshot depending on which version of the SDK you are using.)

Step 28 Proceed to the next section.

CREATE A NEW MEETING ROOM

In order to create a new meeting room on the IBM Sametime Meeting Server, you will need to make anauthenticated HTTP POST to a specific URL that contains all of the metadata for your new room.

The Sametime Meetings API provides wrappers so that you don't have to worry about managing all of thosethings yourself. You simply instantiate some new objects and call a few methods to interact with the RESTservices on the server.

Step 29 In the Package Explorer, right click the “com.ibm.idr.st.meet” package and select New → Class.

Step 30 In the New Java Class window, leave all of the default values and add the following information. When finished, click Finish.

Field Value

Name Exercise1

Step 31 The new class should automatically open in a Java editor.

Step 32 At line 2, add two new blank lines so that lines 2,3,4 are all blank.

Step 33 In the following code sample, you will need various import statements in order for the code to compile. Rather than add them after the fact, go ahead and include all of the import statements now. This will also enable auto-complete and some of the other functions of the Eclipse IDE to make it easier to write the actual code. At line 3, insert the following import statements:

import java.util.UUID;

import com.ibm.rtc.client.meeting.room.MeetingRoom;import com.ibm.rtc.client.meeting.room.RoomServices;

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

8

Page 9: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 34 Click Save.

Step 35 At line 9, add two additional blank lines so that lines 9,10,11 are all blank.

Step 36 You will create a main function that will build a new meeting room and post it to the Sametime Meetings Server. Paste the following Java code at line 10. A description of all of the following code can be found in the next steps.

public static void main(String args[]) {

}

Step 37 At line 11, add 2 blank lines so that lines 11,12,13 are all blank.

Step 38 First, you will need to provide the metadata for your meeting room. You will also need to provide some user credentials. In a real application, you would obtain these values from a useror potentially a properties (or XML) file. For purposes of this lab exercise, you will just hard code all of the data into the application. At line 12, insert the following lines of code:

String serverUrl = "http://sametime9vm.demos.ibm.com:9082";String userName = "dmisawa";String userPassword = "passw0rd";String roomName = "Meeting Center API Room";String roomPassword = "passw0rd";String callData = "111-222-333-4444";Boolean hidden = false;

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

9

Page 10: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 39 Next, you will need to instantiate the Meeting Room Services. This will allow you to configure your server and user information. At line 19, add 2 blank lines so that lines 19,20,21 are blank.

Step 40 At line 20, insert the following lines of code.

RoomServices roomSvc = null;try {

roomSvc = new RoomServices(serverUrl);roomSvc.login(userName, userPassword);

} catch (Exception e) { e.printStackTrace(); }

Step 41 Next, you will want to provide the metadata for your new meeting room. The Meetings API provides some methods for associating this data with your room. At line 24, add 2 blank lines so that lines 24,25 are now blank.

Step 42 At line 25, insert the following code:

MeetingRoom room = new MeetingRoom(roomName);room.setOriginId(UUID.randomUUID() + "");room.setOriginType("IDR-APP");room.setCallData(callData);room.setUnlisted(hidden);if (!roomPassword.trim().equals("")) {

room.setPassword(roomPassword);}

Step 43 Finally, you will want to use the Meeting Room Services object you created earlier to create your new meeting on the server. At line 33, add 2 blank lines so that lines 33,34 are now blank.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

10

Page 11: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 44 At line 34, insert the following code:

MeetingRoom myRoom = roomSvc.createRoom(room);if (myRoom.getId() != null) {

System.out.println("Room Created: " + myRoom.toString());}else {

System.out.println("Failed to create Room.");}roomSvc.logout();

Note: When creating a new meeting room, you can check for the existence of a returned meeting ID to ensurethe meeting was successfully created on the server. You can also use this meeting ID in the future toprogrammatically update meeting details or delete the meeting from the server.

Step 45 Click Save.

Step 46 Refer to the following table for a description of the code:

Lines Description

12 – 18 Provide server and user information, metadata for new room

22 – 23 Create a new meeting room service and associate the user

25 Create a new meeting room object

26 Always use a unique origin ID

27 The origin type will allow you to identify or retrieve meetings created byyour application in the future

28 Associate call data

29 Determines whether or not the room is hidden

30 – 32 Set a room password (optional)

34 Create the new meeting room

35 Check for the existence of a returned ID to determine success

36 Output a string respresentation of the room details

41 Terminate and clean up the room services

Step 47 From the Eclipse toolbar, click the Run drop-down button and choose Run Configurations...

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

11

Page 12: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 48 In the Run Configurations window, on the left click Java Application to highlight the entry. Afterselecting “Java Application”, click the New Launch Configuration button (the white page with a yellow plus in the upper right corner).

Step 49 On the right, enter the following information.

Field Value

Name IDR – Meetings API

Project IDR-MEETINGSAPI

Main class com.ibm.idr.st.meet.Exercise1

Step 50 Click Apply. Click Run.

Step 51 Once the code begins to execute, you can review the Console tab at the bottom of the Eclipse IDE to review the output messages from the code sample. As you'll recall, the code above will output the details of the new meeting created on the server.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

12

Page 13: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 52 Return to the web browser and refresh the entire page. You should see your new (programmatically created) Sametime Meeting Room! Notice that it includes all of the information from your (programmatically created) meeting room object!

Step 53 Leave the browser open and proceed to the next section.

RETRIEVE A LIST OF MEETING ROOMS

Your third party application may want to retrieve and display a list of meeting rooms for the current user. In thisexample, you will learn how to programmatically retrieve a list of meeting rooms using the API.

Step 54 Return to the Eclipse IDE and close all open files.

Step 55 In the Package Explorer, right-click the “com.ibm.idr.st.meet” package and select New → Class.

Step 56 Leave all of the default values and add the following information. When finished, click Finish.

Field Value

Name Exercise2

Step 57 The new class should automatically open in a Java editor. At line 2, add two additional blank lines so that lines 2,3,4 are all blank.

Step 58 In the following code sample, you will need various import statements in order for the code to compile. Rather than add them after the fact, go ahead and include all of the import statements now. This will also enable auto-complete and some of the other functions of the Eclipse IDE to make it easier to write the actual code. At line 3, insert the following import statements:

import java.util.ArrayList;

import com.ibm.rtc.client.meeting.room.MeetingRoom;import com.ibm.rtc.client.meeting.room.QueryControl;import com.ibm.rtc.client.meeting.room.QueryResults;import com.ibm.rtc.client.meeting.room.RoomServices;

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

13

Page 14: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 59 At line 11, add two additional blank lines so that lines 11,12,13 are all blank.

Step 60 You will create a main function that will retrieve the list of rooms from the server. Paste the following Java code at line 12. A description of all of the following code can be found in the next steps.

public static void main(String args[]) {

}

Step 61 First, you will need to provide server information. You will also need to provide some user credentials. In a real application, you would obtain these values from a user or potentially a properties (or XML) file. For purposes of this lab exercise, you will just hard code all of the datainto the application. At line 13, add two additional blank lines so that lines 13,14,15 are all blank.

Step 62 At line 14, insert the following lines of code:

String serverUrl = "http://sametime9vm.demos.ibm.com:9082";String userName = "dmisawa";String userPassword = "passw0rd";

Step 63 Next, you will need to instantiate the Meeting Room Services. This will allow you to configure your server and user information. At line 17, add 2 blank lines so that lines 17,18,19 are blank.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

14

Page 15: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 64 At line 18, insert the following lines of code:

RoomServices roomSvc = null;try {

roomSvc = new RoomServices(serverUrl);roomSvc.login(userName, userPassword);

} catch (Exception e) { e.printStackTrace(); }

Step 65 Next, you will want to retrieve the list of rooms for the current user and iterate through some of the returned data. At line 22, add 2 blank lines so that lines 22,23 are now blank.

Step 66 At line 23, insert the following code:

QueryResults results = roomSvc.getCallersRooms(QueryControl.getDefault());ArrayList rooms = results.getResults();for (int x=0; x < rooms.size(); x++) {

MeetingRoom room = (MeetingRoom) rooms.get(x);System.out.println("==========");System.out.println("Room: " + room.getRoomName());System.out.println("Creator: " + room.getCreator());System.out.println("Active Users: " + room.getActiveUserCount());System.out.println("Url: " + room.getRoomUrl());

}roomSvc.logout();

Note: In this example, you are using a default QueryControl object. You may also create your own QueryControlobject if you want more control over the scope of the search queries, the result set size, and the ordering of theresult set. Consult the Meetings API JavaDoc for more information.

Step 67 Click Save. Refer to the following table for a description of the code:

Lines Description

14 – 16 Provide server and user information

20 – 21 Create a new meeting room service and associate the user

23 Retrieve the meeting rooms for the current user

24 Get the list of rooms returned from the server

25 – 32 For each meeting room returned, print some basic information

33 Terminate and clean up the room services

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

15

Page 16: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 68 From the Eclipse toolbar, click the Run drop-down button and choose Run → Run Configurations...

Step 69 In the Run Configurations dialog window, choose “IDR – Meetings API” under the Java Application section.

Step 70 On the right, click the Search... button beside the “Main class” field.

Step 71 In the Select Main Type dialog window, choose “Exercise 2 – com.ibm.idr.st.meet” and click OK.

Step 72 Click Apply. Click Run to execute the code.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

16

Page 17: IBM Sametime Meetings Server API

IBM Sametime 9.0 Workshop

Step 73 In the Eclipse console, you should see the result of executing the code. The results may vary from the screenshot depending on which other labs you have finished and how many meeting rooms exist for the current user. (Note: you can maximize the console window by clicking the icon in the top right-hand corner).

Step 74 Feel free to explore some of the other metadata you can retrieve and display for each meeting room by adding additional function calls in the for loop after line 31. The Eclipse IDE auto-complete functionality should list the available functions. You can also consult the SDK documentation.

Summary:

Congratulations, you have completed this lab exercise! Using the techniques you learned in this lab, you can nowbegin to integrate advanced IBM Sametime Meeting Server capabilities into your own applications.

COPYRIGHT IBM CORPORATION 2013. ALL RIGHTS RESERVED.IBM Ecosystem Development

17