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("");
        credentialXML.append("").append(nameSpaceID).append("");
        credentialXML.append("").append(userName).append("");
        credentialXML.append("").append(password).append("");
        credentialXML.append("");

        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();
        }
    }
}



 

你可能感兴趣的:(Cognos)