|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
现在的情况是c10已经配置为custom java provide,实现类似sdk的jdbcsample,但是用sdk取得passportid时一直是空
Cognos10获取PassPort要单独实现。代码如下 - package com.cognos.common;
- import java.net.MalformedURLException;
- import java.rmi.RemoteException;
- import org.apache.axis.AxisFault;
- import org.apache.axis.client.Stub;
- import org.apache.axis.message.SOAPHeaderElement;
- import com.cognos.developer.schemas.bibus._3.BiBusHeader;
- import com.cognos.developer.schemas.bibus._3.Configuration;
- 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 CognosLog {
- // 创建连接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 = "http://localhost:9300/p2pd/servlet/dispatch";
- //用户名
- private String username = "root";
- //密码
- private String pwd = "lgtq1983";
- //名称空间
- private String namespace = "lgtq1983";
- //构造函数,通过配置文件得到服务器地址,名称空间,用户名和密码,并连接登陆cognos服务器
- public CognosLog(String CM_URL, String username, String pwd,
- String nameSAPce) {
- this.CM_URL = CM_URL;
- this.username = username;
- this.pwd = pwd;
- this.namespace = nameSAPce;
- }
- /**
- * 此方法连接Cognos服务
- *
- * @返回一个连接
- */
- public ContentManagerServiceStub connectToCognosServer() throws RemoteException {
- //BI Bus
- BiBusHeader bibus = null;
- while (bibus == null) {
- // 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 的服务,通过stub方法来初始化,得到连接内容管理服务对象
- cmService = new ContentManagerServiceStub(serverURL,
- cmServiceLocator);
- //创建报表服务对象
- repService = new ReportServiceStub(serverURL,
- reportServiceLocator);
- //设置超时时间,单位为秒,0为从不超时
- cmService.setTimeout(0);
- repService.setTimeout(0);
- } // ...异常捕捉
- catch (MalformedURLException e) {
- System.out.println("Malformed URL:\n" + e.getMessage());
- return null;
- } catch (AxisFault e) {
- e.printStackTrace();
- }
- try {
- //连接cognos报表服务器
- quickLogon();
- } catch (Exception ex) {
- System.out.println("");
- return null;
- }
- SOAPHeaderElement x = ((Stub) cmService).getResponseHeader(
- "http://developer.cognos.com/schemas/bibus/3/",
- "biBusHeader");
- // 得到 biBusHeader SOAP:包含登陆信息的Header
- bibus = BIBusHeaderHelper.getHeaderObject(x);
- if (bibus != null) {
- ((Stub) cmService).setHeader(
- "http://developer.cognos.com/schemas/bibus/3/",
- "biBusHeader", bibus);
- return cmService;
- }
- }
- return null;
- }
- //得到content manager service的接口
- public ContentManagerServiceStub getCMService() {
- return cmService;
- }
- //得到report service 的接口
- public ReportServiceStub getReportService() {
- BiBusHeader bibus = null;
- //从report service得到bibus
- bibus = BIBusHeaderHelper.getHeaderObject(((Stub) repService)
- .getResponseHeader(
- "http://developer.cognos.com/schemas/bibus/3/",
- "biBusHeader"));
- //如果report service的bibus不可用,就从content manager service得到bibus
- if (bibus == null) {
- BiBusHeader CMbibus = null;
- //得到content manager service的bibus
- CMbibus = BIBusHeaderHelper.getHeaderObject(((Stub) cmService)
- .getResponseHeader(
- "http://developer.cognos.com/schemas/bibus/3/",
- "biBusHeader"));
- (repService).setHeader("", "biBusHeader", CMbibus);
- }
- return repService;
- }
- //登陆Cognos 8
- private void quickLogon() throws RemoteException {
- //认证字符串
- StringBuffer credentialXML = new StringBuffer();
- credentialXML.append("<credential>");
- //名称空间
- credentialXML.append("<namespace>");
- credentialXML.append(namespace == null ? "" : namespace);
- credentialXML.append("</namespace>");
- //用户名
- credentialXML.append("<username>");
- credentialXML.append(username == null ? "" : username);
- credentialXML.append("</username>");
- //密码
- credentialXML.append("<password>");
- credentialXML.append(pwd == null ? "" : pwd);
- credentialXML.append("</password>");
- credentialXML.append("</credential>");
- //转换为XML编码的认证字符串
- String encodedCredentials = credentialXML.toString();
- // 调用content manager service的logon方法,此方法为stub的方法
- getCMService().logon(new XmlEncodedXML(encodedCredentials),
- new SearchPathSingleObject[] {});
- System.out.println("服务器连接成功");
- //使用logoff方法来结束session,并且从CAM对象中把passport移除
- }
- public String getPassPort() {
- BiBusHeader bibus = null;
- String passport = null;
- try {
- SOAPHeaderElement x = ((Stub) cmService).getResponseHeader(
- "http://developer.cognos.com/schemas/bibus/3/",
- "biBusHeader");
- bibus = BIBusHeaderHelper.getHeaderObject(x, true, "");
- passport = bibus.getCAM().getCAMPassport().getId().toString();
- System.out.println("passport:"+passport);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return passport;
- }
- /**
- * 测试服务器是否连接成功
- */
- public static void main(String agrs[]) {
- CognosLog cognos = new CognosLog("http://localhost:9300/p2pd/servlet/dispatch","root","huawei","PS");
- try {
- //创建报表服务器连接
- cognos.connectToCognosServer();
- //获取passport值
- cognos.getPassPort();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- }
该贴已经同步到 xiaoerp的微博 |
|