10.07.2015 Views

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

catch (DuplicateObjectException e){System.err.println("Duplicate object exception");e.printStackTrace();throw new ServletException("Duplicate object exception");}}The login() method in turn calls the doLogin() method. The doLogin() methodattempts to log the servlet in as a server application. The default connectionmethod is configured to connect through the Sametime mux, so we change thisto connect directly to the server. We do this by explicitly setting the port numberwe wish to connect to (1516), and then calling the setConnectivity() method ofthe ServerAppService object. We specify our login type as LT_SERVER_APP fora server application, then add ourselves as a LoginListener before finally callingthe loginAsServerApp() method. We then wait until we are logged in or until ourlogin attempt times out. See for more details.Example 12-12 SametimeToken doLogin() and isLoggedIn() methodsprotected void doLogin(String m_strSametimeServer){// Login as a server applicationConnection[] connections = { new SocketConnection(1516, 17000),};m_saService.setConnectivity(connections);short loginType = STUserInstance.LT_SERVER_APP;m_saService.addLoginListener(this);m_saService.loginAsServerApp(m_strSametimeServer, loginType,"TokenGenerator", null);int nCount=0;loginExpired = false;// Loop until we have logged in or timed out...do{// Wait about 10 seconds (ie 100 x 100ms) for login to succeed// otherwise throw servlet exceptionif (++nCount > 100){// Login attempt has timed outloginExpired = true;}try{Thread.sleep(100);}catch (InterruptedException e)346 <strong>Lotus</strong> <strong>Instant</strong> <strong>Messaging</strong>/<strong>Web</strong> <strong>Conferencing</strong> (Sametime): Building Sametime-Enabled Applications

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!