CommuniGate Pro
Version 1.0
 

XIMSS Login

This section contain some simplest programs that employ the CommuniGate Pro XIMSS Client Library to connect to the server, to retrieve the current time information, and to disconnect.



Java Library

package ximsstest;
import com.communigate.ximss.*;

public class LoginWindow extends javax.swing.JFrame implements ActionListener {
  private HashMap sessionParamDict = new HashMap();
  private Session theSession       = null;

  // Login Window UI initialization
  public LoginPanel() {
    ......
  }

  //
  // Login operation (the Login button pressed)
  //
  public void doLogin() {
    // composing the XIMSS Lib login parameters dictionary,
    // retrieveing the username, password, and other parameters from the UI or stored preferences.
    sessionParamDict.clear();
    sessionParamDict.put("serverName", server_name_goes_here);
    sessionParamDict.put("userName",   user_name_goes_here);
    sessionParamDict.put("password",   password_goes_here);
    sessionParamDict.put("secure",     secure_switch_goes_here ? "YES" : "NO");
    sessionParamDict.put("binding",    "HTTP");
    sessionParamDict.put("loginMethod","auto");
    try {
      // setting the platform-specific Callback Factory
      Session.setCallbackFactory(new swingCallbackFactory());
      // creating a XIMSS session;
      // the operation result will be processed with the ximssLoginCompleted method
      Session.create(sessionParamDict, this, "ximssLoginCompleted");
    } catch(Exception ex) {
      DisplayErrorCode(ex.toString());
    }
  }

  //
  // Login operation completed (callback invoked by XIMSS Lib)
  //
  public void ximssLoginCompleted(Session newSession, String errorCode) {
    if(errorCode != null) {                              // failed to log in
      DisplayErrorCode(errorCode); return;               // update UI to inform the user
    }

    // Login succeeded. Change the UI as needed (remove the Login button, switch screens, etc.)
    ......

    // store the created XIMSS session
    theSession = newSession;
    
    // session initialization

    try {
      // set async data message processor for all "unknown" messages
      theSession.setAsyncProcessor(this, "ximssAsyncAll",     null,null,null);
      // set async data message processor for the "session" message
      theSession.setAsyncProcessor(this, "ximssAsyncSession", "session",null,null);
      // set network error processor, called not more often than once in 10 secs
      theSession.setNetworkErrorProcessor(this, "ximssNetworkErrorProcessor",10);
      // now, when all basic async processors have been initialized,
      // start the XIMSS session
      theSession.start();

      // sending a test request - <readTime />
      // the request result will be processed with the ximssOpCompleted method,
      // the responce data will be processed with the ximssOpData method
      // the request should not be sent immediately, glue to the next request
      Element xmlRequest1 = theSession.createXMLNode("readTime");
      theSession.sendRequest(xmlRequest1,    this, "ximssOpData", "ximssOpCompleted", false);

      // sending the <signalBind readIM="1" /> request
      // it will be sent immediately, together with the previously queued request(s)
      Element xmlBindRequest = theSession.createXMLNode("signalBind");
      xmlBindRequest.setAttribute("readIM", "1");
      theSession.sendRequest(xmlBindRequest, this, null, "ximssOpCompleted", true);

    } catch(Exception x) {
      DisplayErrorCode("Exception:" + x.getLocalizedMessage());
    }
  }

  //
  // Network Error processor (callback invoked by XIMSS Lib)
  //
  public Boolean ximssNetworkErrorProcessor(Boolean isFatal,Integer timeElapsed) {
    // if we cannot recover from a transient error for more than 30 seconds ->
    // treat it is a fatal error
    if(timeElapsed >= 30) {isFatal = true;}
    if(isFatal) {                // this is a fatal communication error
      SetOffline();              // inform the user, change the UI to "disconnected"

    } else {                     // display/animate a "problem" indicator somewhere
      DisplayProblemIndicator(); // it should disappear in 15 sec if not re-animated here again
    }
    return(isFatal);             // returned the modified "fatal" indicator
  }

  // XIMSS request result processor (callback invoked by XIMSS Lib when the request completes)
  public void ximssOpCompleted(String errorCode,Element xmlRequest) {
    System.out.printf("%s completed. %s%s\n", xmlRequest.getTagName(),
                      errorCode == null ? "" : "errorCode=",errorCode == null ? "" : errorCode);
  }

  // XIMSS request response processor (callback invoked by XIMSS Lib when a synchronous data message is received)
  public void ximssOpData(Element xmlResponse,Element xmlRequest) {
    System.out.printf("%s data: %s\n", xmlRequest.getTagName(), xmlResponse.getTagName());
  }

  // XIMSS async message processor (callback invoked by XIMSS Lib when an asynchronous data message is received)
  public Object ximssAsyncAll(Element xmlData) {
    System.out.printf("async data: %s\n", xmlData.getTagName());
    return(xmlData);
  }

  // XIMSS async message processor (called only for <session /> messages)
  public Object ximssAsyncSession(Element xmlData) {
    System.out.printf("session data: %s, url=%s\n", xmlData.getAttribute("userName"),xmlData.getAttribute("urlID"));
    return(null);
  }


  //
  // Logout operation (the Logout button pressed)
  //
  public void doLogout() throws Exception {
    theSession.close(this, "ximssLogoutCompleted");
  }

  // XIMSS "close" request result processor (callback invoked by XIMSS Lib)
  public void ximssLogoutCompleted(String errorCode,Element xmlRequest) {
    System.out.printf("Logout completed.%s%s\n",
                      errorCode == null ? "" : " errorCode=",errorCode == null ? "" : errorCode);
    setOffline();                // change the UI to "disconnected"
  }


JavaScript Library

Under Construction

Objective C Library

#import "LoginWindow.h"
#import "XIMSSSession.h"

@implementation LoginWindow

//
// Login operation (the Login button pressed)
//
-(IBAction)doLogin:(id)sender {

  // composing the XIMSS Lib login parameters dictionary,
  // retrieveing the username, password, and other parameters from the UI or stored preferences.
  NSMutableDictionary* ximssParams = [[NSMutableDictionary alloc] init];
  [ximssParams setValue:server_name_goes_here                     forKey:@"serverName"];
  [ximssParams setValue:user_name_goes_here                       forKey:@"userName"];
  [ximssParams setValue:password_goes_here                        forKey:@"password"];
  [ximssParams setValue:secure_switch_goes_here ? @"YES" : @"NO"  forKey:@"secureMode"];
  [ximssParams setValue:accept_all_certificates_goes_here         forKey:@"acceptAllCerts"];
  [ximssParams setValue:binding_goes_here                         forKey:@"binding"];
  [ximssParams setValue:login_method_goes_here                    forKey:@"loginMethod"];

  // creating a XIMSS session;
  // the operation result will be processed with the ximssLoginCompleted:errorCode: method
  [XIMSSSession create:ximssParams delegate:self onCompletion:@selector(ximssLoginCompleted:errorCode:)];
  
  [ximssParams release];
}

//
// Login operation completed (callback invoked by XIMSS Lib)
//
-(void)ximssLoginCompleted:(XIMSSSession*)newSession errorCode:(NSString*)errorCode {
  if(errorCode != nil) {                                 // failed to log in
    DisplayErrorCode(errorCode); return;                 // update UI to inform the user
  }

  // Login succeeded. Change the UI as needed (remove the Login button, switch screens, etc.)
  NSLog(@"session created");

  // store the created XIMSS session
  theSession = newSession;
    
  // session initialization

  // set async data message processor for all "unknown" messages
  [theSession setAsyncProcessor:self selector:@selector(ximssAsyncAll:)
                        tagName:nil          attrName:nil attrValue:nil];
  // set async data message processor for the "session" message
  [theSession setAsyncProcessor:self selector:@selector(ximssAsyncSession:)
                        tagName:@"session"   attrName:nil attrValue:nil];
  // set network error processor, called not more often than once in 10 secs
  // set async data message processor for the "session" message
  [theSession setNetworkErrorProcessor:self selector:@selector(ximssNetworkErrorProcessor:timeElapsed:)
                             timeLimit:10];
  // now, when all basic async processors have been initialized,
  // start the XIMSS session
  [theSession start];
    
  // sending a test request - <readTime />
  // the request result will be processed with the ximssOpCompleted method,
  // the responce data will be processed with the ximssOpData method
  // the request should not be sent immediately, glue to the next request
  XIMSSXML* xmlRequest1 = [[XIMSSXML alloc] initWithName:@"readTime"];
  [theSession sendRequest:xmlRequest1 delegate:self onData:@selector(ximssOpData:xmlRequest:)
             onCompletion:@selector(ximssOpCompleted:xmlRequest:) sendImmediately:false];    
  [xmlRequest1 release];
  
   // sending the <signalBind readIM="1" /> request
   // it will be sent immediately, together with the previously queued request(s)
   Element xmlBindRequest = theSession.createXMLNode("signalBind");
   XIMSSXML* xmlBindRequest = [[XIMSSXML alloc] initWithName:@"signalBind"];
   [xmlBindRequest setAttribute:@"readIM" prefix:nil value:@"1"];

   [theSession sendRequest:xmlBindRequest delegate:self onData:nil
              onCompletion:@selector(ximssOpCompleted:xmlRequest:) sendImmediately:true];    
   [xmlBindRequest release];
  }
}

//
// Network Error processor (callback invoked by XIMSS Lib)
//
-(id)ximssNetworkErrorProcessor:(bool*)pIsFatal timeElapsed:(int*)pTimeElapsed {
  bool isFatal = *pIsFatal;
  // if we cannot recover from a transient error for more than 30 seconds ->
  // treat it is a fatal error
  if(*pTimeElapsed >= 30) {isFatal = true;}
  if(isFatal) {                 // this is a fatal communication error
    SetOffline();               // inform the user, change the UI to "disconnected"

  } else {                      // display/animate a "problem" indicator somewhere
    DisplayProblemIndicator();  // it should disappear in 15 sec if not re-animated here again
  }
  return(isFatal ? self : nil); // returned the modified "fatal" indicator
}

// XIMSS request result processor (callback invoked by XIMSS Lib when the request completes)
-(void)ximssOpCompleted:(NSString*)errorCode xmlRequest:(XIMSSXML*)xmlRequest {
  NSLog(@"%@ completed.%@%@",[xmlRequest getTag],
        errorCode == null ? @"" : @" errorCode=",errorCode == null ? @"" : errorCode);
}

// XIMSS request response processor (callback invoked by XIMSS Lib when a synchronous data message is received)
-(void)ximssOpData:(XIMSSXML*)xmlData xmlRequest:(XIMSSXML*)xmlRequest {
  NSLog(@"%@ data %@",[xmlRequest getTag],[xmlData getTag]);
}

// XIMSS async message processor (callback invoked by XIMSS Lib when an asynchronous data message is received)
-(id)ximssAsyncAll:(XIMSSXML*)xmlData {
  NSLog(@"async data: %@",[xmlData getTag]);
  return(xmlData);
}

// XIMSS async message processor (called only for <session /> messages)
-(id)ximssAsyncSession:(XIMSSXML*)xmlData {
  NSLog(@"session data: %@, url=%@", [xmlData.getAttribute:@"userName" prefix:nil],
                                     [xmlData.getAttribute:@"urlID"    prefix:nil]);
  return(null);
}


//
// Logout operation (the Logout button pressed)
//
-(void)doLogout {
  [theSession close:this onCompletion:@selector(ximssLogoutCompleted:xmlRequest:)];
}

// XIMSS "close" request result processor (callback invoked by XIMSS Lib)
-(void)ximssLogoutCompleted:(NSString*)errorCode xmlRequest:(XIMSSXML*)xmlRequest {
  NSLog(@"Logout completed.%@%@",
        errorCode == null ? @"" : @" errorCode=",errorCode == null ? @"" : errorCode);
  setOffline();                // change the UI to "disconnected"
}


CommuniGate Pro Guide. Copyright © 2020, AO StalkerSoft