内容发布更新时间 : 2024/11/16 0:34:59星期一 下面是文章的全部内容请认真阅读。
用logoff()方法进行注销。 实例代码如下:
//XML认证字符串
StringBuffer credentialXML = new StringBuffer(); credentialXML.append(\//登陆的名称空间
credentialXML.append(\credentialXML.append(namespace);
credentialXML.append(\//用户名
credentialXML.append(\credentialXML.append(uid);
credentialXML.append(\//密码
credentialXML.append(\credentialXML.append(pwd);
credentialXML.append(\credentialXML.append(\...
//转换为XML
XmlEncodedXML credentialXEX = new XmlEncodedXML(); credentialXEX.setValue(credentialXML.toString()); //登陆
connection.getCMService().logon(credentialXEX, null);
此例子中,logon方法被content manager service调用,包含名称空间,用户名和密码的认证字符串经编码以XML的形式传给service。登陆完成之后一个新的用户session就建立起来了。
使用logoff方法来结束session,并且从CAM对象中把passport移除。以下是一个完整的类,此例子包含连接和登陆Cognos 8,并且得到两个最常用的service,Content Manager Service和Report Service。
package com.cognos;
import java.net.MalformedURLException; import java.rmi.RemoteException; import org.apache.axis.AxisFault;
import org.apache.axis.client.Stub;
import org.apache.commons.configuration.Configuration; import com.cognos.developer.schemas.bibus._3.BiBusHeader;
import com.cognos.developer.schemas.bibus._3.ContentManagerServiceStub; import
com.cognos.developer.schemas.bibus._3.ContentManagerService_ServiceLocator; import com.cognos.developer.schemas.bibus._3.ReportServiceStub;
import com.cognos.developer.schemas.bibus._3.ReportService_ServiceLocator; import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject; import com.cognos.developer.schemas.bibus._3.XmlEncodedXML;
public class CRNConnectImpl implements CRNConnect { // 创建连接Cognos8服务的对象.
//Content Manager Service 内容库管理服务Locator对象
private ContentManagerService_ServiceLocator cmServiceLocator = null; //Report Service 报表服务Locator对象
private ReportService_ServiceLocator reportServiceLocator = null; // Content Manager Service 内容库服务对象
private ContentManagerServiceStub cmService = null; //Report Service 报表服务对象
private ReportServiceStub repService = null;
// Cognos 8 Content Manager 服务器地址
private String CM_URL = \ //用户名
private String username = null; //密码
private String pwd = null; //名称空间
private String namespace = null;
//构造函数,通过配置文件得到服务器地址,名称空间,用户名和密码,并连接登陆//Cognos 8
public CRNConnectImpl(Configuration configuration) throws RemoteException { this.CM_URL = configuration.getString(\ this.username = configuration.getString(\ this.pwd = configuration.getString(\ pwd = pwd==null?\ this.namespace = configuration.getString(\ connectToCognosServer(); }
/**
* 此方法连接Cognos服务 *
* @返回一个连接 */
public ContentManagerServiceStub connectToCognosServer() throws RemoteException { //BI Bus BiBusHeader bibus = null; while (bibus == null) { // 创建Cognos 8服务的service locator //content manger service locator 内容管理服务locator cmServiceLocator = new ContentManagerService_ServiceLocator(); //report service locator 报表服务locator reportServiceLocator = new ReportService_ServiceLocator(); try { java.net.URL serverURL = new java.net.URL(CM_URL); // 得到Cognos 8的服务,通过stub方法来初始化,得到连接 //内容管理服务对象 cmService = new ContentManagerServiceStub(serverURL, cmServiceLocator); //报表服务对象 repService = new ReportServiceStub(serverURL, reportServiceLocator); //设置超时时间,单位为秒,0为从不超时 cmService.setTimeout(0); repService.setTimeout(0); } // ...异常捕捉 catch (MalformedURLException e) { System.out.println(\ return null; } catch (AxisFault e) { e.printStackTrace(); } try { //获得连接之后进行登陆 quickLogon(); } catch (RemoteException ex) { System.out.println(\连接失败\ ex.printStackTrace();
}
// If authentication is required, this will generate an // exception
// At this point, this exception can safely be ignored throw ex;
// 得到 biBusHeader SOAP:包含登陆信息的Header bibus = (BiBusHeader) ((Stub) cmService).getHeaderObject(\ \if (bibus != null) { return cmService; }
} return null; }
//得到content manager service的接口
public ContentManagerServiceStub getCMService() { return cmService; }
//得到report service 的接口
public ReportServiceStub getReportService() { BiBusHeader bibus = null; //从report service得到bibus bibus = (BiBusHeader) ( repService).getHeaderObject(\ \ //如果report service的bibus不可用,就从content manager service得到bibus if (bibus == null) { BiBusHeader CMbibus = null; //得到content manager service的bibus CMbibus = (BiBusHeader) ( cmService).getHeaderObject(\ \ (repService).setHeader(\ } return repService; }
//登陆Cognos 8
private void quickLogon() throws RemoteException { //认证字符串 StringBuffer credentialXML = new StringBuffer();
}
}
credentialXML.append(\//名称空间
credentialXML.append(\
credentialXML.append(namespace == null ? \credentialXML.append(\//用户名
credentialXML.append(\
credentialXML.append(username == null ? \credentialXML.append(\//密码
credentialXML.append(\
credentialXML.append(pwd == null ? \credentialXML.append(\
credentialXML.append(\//转换为XML编码的认证字符串
String encodedCredentials = credentialXML.toString();
// 调用content manager service的logon方法,此方法为stub的方法 getCMService().logon(new XmlEncodedXML(encodedCredentials), new SearchPathSingleObject[] {});
// sn_dg_sdk_method_contentManagerService_logon_end_1
运行报表
连接上Cognos 8并成功认证之后,就可以创建或者运行一张报表了。运行一张报表首先得制定这张报表的搜索路径search path,报表服务通过搜索路径在内容库中找到所对应的报表。 用以下BI Bus API方法运行报表或者运行报表定义: ? run(objectPath, parameterValues, options)
直接运行报表,参数为搜索路径,报表参数,运行选项 ? runAt(startTime, objectPath, parameterValues, options)