package ximsstest;
import com.communigate.ximss.*;
public class LoginWindow extends javax.swing.JFrame implements ActionListener {
private HashMap sessionParamDict = new HashMap();
private Session theSession = null;
public LoginPanel() {
......
}
public void doLogin() {
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 {
Session.setCallbackFactory(new swingCallbackFactory());
Session.create(sessionParamDict, this, "ximssLoginCompleted");
} catch(Exception ex) {
DisplayErrorCode(ex.toString());
}
}
public void ximssLoginCompleted(Session newSession, String errorCode) {
if(errorCode != null) {
DisplayErrorCode(errorCode); return;
}
......
theSession = newSession;
try {
theSession.setAsyncProcessor(this, "ximssAsyncAll", null,null,null);
theSession.setAsyncProcessor(this, "ximssAsyncSession", "session",null,null);
theSession.setNetworkErrorProcessor(this, "ximssNetworkErrorProcessor",10);
theSession.start();
Element xmlRequest1 = theSession.createXMLNode("readTime");
theSession.sendRequest(xmlRequest1, this, "ximssOpData", "ximssOpCompleted", false);
Element xmlBindRequest = theSession.createXMLNode("signalBind");
xmlBindRequest.setAttribute("readIM", "1");
theSession.sendRequest(xmlBindRequest, this, null, "ximssOpCompleted", true);
} catch(Exception x) {
DisplayErrorCode("Exception:" + x.getLocalizedMessage());
}
}
public Boolean ximssNetworkErrorProcessor(Boolean isFatal,Integer timeElapsed) {
if(timeElapsed >= 30) {isFatal = true;}
if(isFatal) {
SetOffline();
} else {
DisplayProblemIndicator();
}
return(isFatal);
}
public void ximssOpCompleted(String errorCode,Element xmlRequest) {
System.out.printf("%s completed. %s%s\n", xmlRequest.getTagName(),
errorCode == null ? "" : "errorCode=",errorCode == null ? "" : errorCode);
}
public void ximssOpData(Element xmlResponse,Element xmlRequest) {
System.out.printf("%s data: %s\n", xmlRequest.getTagName(), xmlResponse.getTagName());
}
public Object ximssAsyncAll(Element xmlData) {
System.out.printf("async data: %s\n", xmlData.getTagName());
return(xmlData);
}
public Object ximssAsyncSession(Element xmlData) {
System.out.printf("session data: %s, url=%s\n", xmlData.getAttribute("userName"),xmlData.getAttribute("urlID"));
return(null);
}
public void doLogout() throws Exception {
theSession.close(this, "ximssLogoutCompleted");
}
public void ximssLogoutCompleted(String errorCode,Element xmlRequest) {
System.out.printf("Logout completed.%s%s\n",
errorCode == null ? "" : " errorCode=",errorCode == null ? "" : errorCode);
setOffline();
}
#import "LoginWindow.h"
#import "XIMSSSession.h"
@implementation LoginWindow
-(IBAction)doLogin:(id)sender {
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"];
[XIMSSSession create:ximssParams delegate:self onCompletion:@selector(ximssLoginCompleted:errorCode:)];
[ximssParams release];
}
-(void)ximssLoginCompleted:(XIMSSSession*)newSession errorCode:(NSString*)errorCode {
if(errorCode != nil) {
DisplayErrorCode(errorCode); return;
}
NSLog(@"session created");
theSession = newSession;
[theSession setAsyncProcessor:self selector:@selector(ximssAsyncAll:)
tagName:nil attrName:nil attrValue:nil];
[theSession setAsyncProcessor:self selector:@selector(ximssAsyncSession:)
tagName:@"session" attrName:nil attrValue:nil];
[theSession setNetworkErrorProcessor:self selector:@selector(ximssNetworkErrorProcessor:timeElapsed:)
timeLimit:10];
[theSession start];
XIMSSXML* xmlRequest1 = [[XIMSSXML alloc] initWithName:@"readTime"];
[theSession sendRequest:xmlRequest1 delegate:self onData:@selector(ximssOpData:xmlRequest:)
onCompletion:@selector(ximssOpCompleted:xmlRequest:) sendImmediately:false];
[xmlRequest1 release];
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];
}
}
-(id)ximssNetworkErrorProcessor:(bool*)pIsFatal timeElapsed:(int*)pTimeElapsed {
bool isFatal = *pIsFatal;
if(*pTimeElapsed >= 30) {isFatal = true;}
if(isFatal) {
SetOffline();
} else {
DisplayProblemIndicator();
}
return(isFatal ? self : nil);
}
-(void)ximssOpCompleted:(NSString*)errorCode xmlRequest:(XIMSSXML*)xmlRequest {
NSLog(@"%@ completed.%@%@",[xmlRequest getTag],
errorCode == null ? @"" : @" errorCode=",errorCode == null ? @"" : errorCode);
}
-(void)ximssOpData:(XIMSSXML*)xmlData xmlRequest:(XIMSSXML*)xmlRequest {
NSLog(@"%@ data %@",[xmlRequest getTag],[xmlData getTag]);
}
-(id)ximssAsyncAll:(XIMSSXML*)xmlData {
NSLog(@"async data: %@",[xmlData getTag]);
return(xmlData);
}
-(id)ximssAsyncSession:(XIMSSXML*)xmlData {
NSLog(@"session data: %@, url=%@", [xmlData.getAttribute:@"userName" prefix:nil],
[xmlData.getAttribute:@"urlID" prefix:nil]);
return(null);
}
-(void)doLogout {
[theSession close:this onCompletion:@selector(ximssLogoutCompleted:xmlRequest:)];
}
-(void)ximssLogoutCompleted:(NSString*)errorCode xmlRequest:(XIMSSXML*)xmlRequest {
NSLog(@"Logout completed.%@%@",
errorCode == null ? @"" : @" errorCode=",errorCode == null ? @"" : errorCode);
setOffline();
}
CommuniGate Pro Guide. Copyright © 2020, AO StalkerSoft
|