SDK登录cognos

通过SDK登录cognos

一种是拼xml,如这里的实现https://github.com/cosysoft/cognos-tools/blob/master/src/com/ibm/cognos/Logon.java

部分代码:

public String logon(CRNConnect connection) {
        // NOTE: If you are already logged on, you must first log off
        // before you can log on as a different user.
        logoff(connection);

        String namespaceInfo[] = getNamespaces(connection);

        // namespaceInfo is name/ID pairs -- always even
        String namespaces[] = new String[namespaceInfo.length / 2];
        String namespaceIDs[] = new String[namespaceInfo.length / 2];

        for (int j = 0, k = 0; k < namespaceInfo.length; j++, k++) {
            namespaces[j] = namespaceInfo[k++];
            namespaceIDs[j] = namespaceInfo[k];
        }

        userID = "admin";
        password = "123";
        nameSpace = "OpenDJ";
        StringBuffer credentialXML = new StringBuffer();
        credentialXML.append("");

        credentialXML.append("");
        credentialXML.append(nameSpace);
        credentialXML.append("");

        credentialXML.append("");
        credentialXML.append(userID);
        credentialXML.append("");

        credentialXML.append("");
        credentialXML.append(password);
        credentialXML.append("");

        credentialXML.append("");

        String encodedCredentials = credentialXML.toString();

        credentialString = encodedCredentials;

        try {
            connection.getCMService().logon(
                    new XmlEncodedXML(encodedCredentials),
                    new SearchPathSingleObject[] {});
            SOAPHeaderElement x = ((Stub) connection.getCMService())
                    .getResponseHeader(
                            "http://developer.cognos.com/schemas/bibus/3/",
                            "biBusHeader");
            ((Stub) connection.getCMService()).setHeader(x);

            password = "";
        } catch (java.rmi.RemoteException remoteEx) {
            userID = "";
            password = "";
            nameSpace = "";
            credentialString = "";
            
            remoteEx.printStackTrace();
            return "";
        }

        System.out.println("登陆成功.................");
        return ("Logon successful.");
    }
View Code

另一种是通过bibus设置session中的form

bibus.getHdrSession().setFormFieldVars(ffs);

部分代码:

BiBusHeader bibus = BIBusHeaderHelper.getHeaderObject(((Stub)repService).getResponseHeader("http://developer.cognos.com/schemas/bibus/3/", BIBUSConstants.BIBUS_HDR));//("", BIBUSConstants.BIBUS_HDR));
if (bibus != null)
        {
            if (bibus.getTracking() != null)
            {
                if (bibus.getTracking().getConversationContext() != null)
                {
                    bibus.getTracking().setConversationContext(null);
                }
            }

            return;
        }

        // Set up a new biBusHeader for the "logon" action.
        bibus = new BiBusHeader();
        bibus.setCAM(new CAM());
        bibus.getCAM().setAction(logonAs);
        bibus.setHdrSession(new HdrSession());

        FormFieldVar ffs[] = new FormFieldVar[3];

        ffs[0] = new FormFieldVar();
        ffs[0].setName("CAMUsername");
        ffs[0].setValue(user);
        ffs[0].setFormat(FormatEnum.not_encrypted);

        ffs[1] = new FormFieldVar();
        ffs[1].setName("CAMPassword");
        ffs[1].setValue(pass);
        ffs[1].setFormat(FormatEnum.not_encrypted);

        ffs[2] = new FormFieldVar();
        ffs[2].setName(CAMNamespace);
        ffs[2].setValue(name);
        ffs[2].setFormat(FormatEnum.not_encrypted);

        bibus.getHdrSession().setFormFieldVars(ffs);
        ((Stub)repService).setHeader(BIBUSConstants.BIBUS_NS, BIBUSConstants.BIBUS_HDR, bibus);
View Code

 

SDK登录cognos_第1张图片

namespace可以从Cognos Configuration中看到,如上图

转载于:https://www.cnblogs.com/yoyogis/p/4942973.html

你可能感兴趣的:(SDK登录cognos)