Cognos API Connection

Cognos Connection, access the installed platform of Cogons through the Cogons API, get the report that has been created, modify the report, or run the report to get the result, etc. . .

Analyze the Connection. The simple code is as follows:

 

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[] = Utili.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();
        }
    }
}



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326930599&siteId=291194637