Cognos API Connection

Cognos Connection, 通过 Cogons API 访问Cogons 已经安装好的平台,获取已经创建好的Report,修改此report,或者运行此report获取结果等。。。

分析Connection. 简单代码如下:

 

package test;

import java.net.URL;

import javax.xml.namespace.QName;

import org.apache.axis.client.Stub;
import org.apache.axis.message.SOAPHeaderElement;

import com.cognos.developer.schemas.bibus._3.BaseClass;
import com.cognos.developer.schemas.bibus._3.BiBusHeader;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_PortType;
import com.cognos.developer.schemas.bibus._3.ContentManagerService_ServiceLocator;
import com.cognos.developer.schemas.bibus._3.PropEnum;
import com.cognos.developer.schemas.bibus._3.QueryOptions;
import com.cognos.developer.schemas.bibus._3.Report;
import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
import com.cognos.developer.schemas.bibus._3.Sort;
import com.cognos.developer.schemas.bibus._3.XmlEncodedXML;

public class CognosConnectionUtil
{
    private ContentManagerService_PortType cmService = null;

    public static void main(String[] a) throws Exception
    {
        //1. instantiate the class
        CognosConnectionUtil mainClass = new CognosConnectionUtil(); 

        // Step 2: Logon to Cognos
        mainClass.logonToCognos();

        // Step 3: Execute tasks
        mainClass.executeTasks();

        // Step 4: Logoff from Cognos
        mainClass.logoffFromCognos();
    }

    // Step 2: Logon to Cognos
    private void logonToCognos() throws Exception
    {

        String dispatcherURL = "http://xxxxxxxxxxxxxxxxxx/p2pd/servlet/dispatch";

        String nameSpaceID = "XXXXX";

        String userName = "XXXX";

        String password = "XXXXX";

        ContentManagerService_ServiceLocator cmServiceLocator = new ContentManagerService_ServiceLocator();

        URL url = new URL(dispatcherURL);
        cmService = cmServiceLocator.getcontentManagerService(url);

        StringBuffer credentialXML = new StringBuffer();

        credentialXML.append("<credential>");
        credentialXML.append("<namespace>").append(nameSpaceID).append("</namespace>");
        credentialXML.append("<username>").append(userName).append("</username>");
        credentialXML.append("<password>").append(password).append("</password>");
        credentialXML.append("</credential>");

        String encodedCredentials = credentialXML.toString();
        XmlEncodedXML xmlCredentials = new XmlEncodedXML();
        xmlCredentials.set_value(encodedCredentials);

        cmService.logon(xmlCredentials, null);
        SOAPHeaderElement temp = ((Stub) cmService).getResponseHeader("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader");
        System.out.println(temp.toString());
        BiBusHeader CMbibus = (BiBusHeader) temp.getValueAsType(new QName("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader"));
        ((Stub) cmService).setHeader("http://developer.cognos.com/schemas/bibus/3/", "biBusHeader", CMbibus);

    }

    // Step 3: Execute tasks
    private String executeTasks()
    {
        PropEnum props[] = Util.getAllPropEnum();
        BaseClass bc[] = null;
        String searchPath = "/content/folder[@name='Test']/report[@name='test']";

        try
        {
            SearchPathMultipleObject spMulti = new SearchPathMultipleObject(searchPath);
            bc = cmService.query(spMulti, props, new Sort[] {}, new QueryOptions());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        System.out.println("PACKAGES:\n");
        if (bc != null)
        {
            for (int i = 0; i < bc.length; i++)
            {
                Report report = (Report) bc[i];
                System.out.println(report.getDefaultName());
            }
        }
        return searchPath;
    }

    // Step 4: Logoff from Cognos
    private void logoffFromCognos()
    {
        try
        {
            cmService.logoff();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值