Cognos Mashup Service CORS错误

时间:2018-04-05 18:19:28

标签: web web-applications cors xmlhttprequest cognos

所以我试图通过这里给出的示例来使Cognos Mashup Service工作:https://www.ibm.com/communities/analytics/cognos-analytics-blog/how-to-use-ibm-10-2-2-cognos-mashup-service-cms-samples-in-ibm-cognos-analytics-11/

使用内部浏览器在Eclipse中运行时,应用程序实际上运行正常。但是,当我将默认的eclipse浏览器从内部更改为外部,如Firefox或Chrome时,我在连接时遇到CORS Access错误到Cognos 11:

阻止跨源请求:同源策略禁止在https://placeholder/ibmcognos/bi/v1/disp/rds/pagedReportData/report/i72BCF4B83AFE430F9A7F4721DF093FAB?fmt=HTMLFragment&selection=List1&rowLimit=2读取远程资源。 (原因:CORS标题'Access-Control-Allow-Origin'缺失)

根据我的理解,我需要将以下内容添加到我的服务器配置文件中:

<Location />
order allow,deny
allow from all
Header set Access-Control-Allow-Origin "*"
</Location> 

但是,这只会导致404错误的无限循环。 那么我做错了什么,为什么内部eclipse浏览器有效?这是我的简单web应用程序html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Generic Authentication Sample</title>
<script>

var myNameSpace=null;
var myUserName=null;
var myPassword=null;

try {
  var objXHR = new XMLHttpRequest();
  } catch (e) {
    try {
        alert('Msxml2.XMLHTTP');
      var objXHR = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
      try {
          alert('Microsoft.XMLHTTP')
        var objXHR = new ActiveXObject('Microsoft.XMLHTTP');
      } catch (e) {
        alert('XMLHttpRequest not supported'); }
      }
  }      

 function doReport()
 {

    myNameSpace=document.getElementById("nameSpace").value;
    myUserName=document.getElementById("userName").value;
    myPassword=document.getElementById("password").value;
    var myReportID=document.getElementById("storeID").value;

    var myFrag = document.getElementById("fragment");

    if(myNameSpace==""||myUserName==""||myPassword=="")
    {
        myFrag.innerHTML="";
        myFrag.innerHTML= "<HTML><BODY><b>Please enter Authentication information ....</b></BODY></HTML>";
        return;
    }

    if(myReportID=="")
    {
        myFrag.innerHTML="";
        myFrag.innerHTML= "<HTML><BODY><b>Please enter the Report ID ....</b></BODY></HTML>";
        return;
    }

    var url = parent.settings.document.getElementById("serverURL").value + "/bi/v1/disp/rds/pagedReportData/report/" + document.getElementById("storeID").value;
    window.status = "Loading Report. Please wait....";
    var frag = document.getElementById("fragment");
    frag.innerHTML= "<HTML><BODY>Loading Report. Please wait....</BODY></HTML>";
    try
    {
        objXHR.open("GET", url, true);
        objXHR.onreadystatechange = callBack;
        objXHR.send(null);
    }
    catch (e)
    {
        alert("Error occurs when doing report.\r\n"+ e);
    }

 }

function doLogon()
{

    var xmlData =
      "xmlData=<auth:credentials xmlns:auth='http://developer.cognos.com/schemas/ccs/auth/types/1'>"
      +"<auth:credentialElements><auth:name>CAMNamespace</auth:name>"
      +"<auth:value><auth:actualValue>"+myNameSpace+"</auth:actualValue></auth:value></auth:credentialElements>"
      +"<auth:credentialElements><auth:name>CAMUsername</auth:name>"
      +"<auth:value><auth:actualValue>"+myUserName+"</auth:actualValue></auth:value></auth:credentialElements>"
      +"<auth:credentialElements><auth:name>CAMPassword</auth:name>"
      +"<auth:value><auth:actualValue>"+myPassword+"</auth:actualValue></auth:value></auth:credentialElements>"
      +"</auth:credentials>";

    try
    {

        var url = parent.settings.document.getElementById("serverURL").value + "/bi/v1/disp/rds/auth/logon";
        objXHR.open("POST", url, false);
        objXHR.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        objXHR.setRequestHeader("Content-length",xmlData.length);
        objXHR.setRequestHeader("Connection","close");
        objXHR.send(xmlData);

        if(objXHR.status == 200)
        {

            // Processes the response from the CMS Authentication service.
            // If we recieve an "accountInfo" element back, we have successfully logged in.
            var accountInfo = objXHR.responseXML.getElementsByTagName("auth:accountInfo");

            if (accountInfo.length > 0)
            {   
                objXHR = new XMLHttpRequest(); //each request can only be opened once
                doReport();
            }
            else
            {
                //Otherwise, prompt error message
                alert("Error occurs when doing logon. Please check input credentials.");
                return;
            }
        }
        else
        {
            var url =  parent.settings.document.getElementById("serverURL").value + "/bi/v1/disp/rds/auth/logon";   
            alert(url);
            showError(objXHR.responseText);
            window.status = "Done";
        }
    }
    catch (e)
    {
        alert("Error occurs when doing logon.\r\n"+e);
    }

}

function showError(msg)
{
    var frag = document.getElementById("fragment");
    frag.innerHTML= "Complete";
    frag.style.visibility = "hidden";
    frag = document.getElementById("error")
    frag.innerHTML= msg;
    frag.style.visibility = "visible";
}

function doLogoff()
{
    try
    {
        objXHR.open("POST", parent.settings.document.getElementById("serverURL").value + "/bi/v1/disp/rds/auth/logoff", false);
        objXHR.send(null);
        checkLogoffStatus();
    }
    catch (e)
    {
        alert("Error occurs when doing logoff.\r\n"+e);
    }
}

function checkLogoffStatus()
{
    if(objXHR.readyState == 4 && objXHR.status == 200)
    {
        window.status = "Successfully log off IBM Cognos Service.";
        alert("Successfully log off IBM Cognos Service.");
    }
    else
    {
        var frag = document.getElementById("fragment");
        frag.innerHTML = objXHR.responseText;
        alert("HTTP ERROR " + objXHR.status + ": " + objXHR.statusText);
        window.status = "Done";
    }
}   

function callBack()
{
    if (objXHR.readyState == 4)
    {

        if (objXHR.status == 200)
        {
            var frag = document.getElementById("fragment");
            frag.innerHTML = objXHR.responseText;
            window.status = "Done";

        }
        else if (objXHR.status == 403)
        {
            doLogon();
        }
        else
        {
            alert("CALLBACK HTTP ERROR " + objXHR.status);
            window.status = "Done";
        }
    }
}


</script>
</head>
<body style="font-family: Verdana, Arial, Sans-Serif; font-weight: normal"><br />
<table align="center" width="95%"
    style="border-bottom-style: solid; border-top-style: solid; border-left-color: #004080; border-top-color: #004080; border-right-color: #004080; border-left-style: solid; border-right-style: solid; border-bottom-color: #004080; border-bottom-width: thin; border-right-width: thin; border-left-width: thin; border-top-width: thin">
    <thead>
        <tr>
            <td
                style="text-align: center; color: #FFFFFF; font-weight: bold; background-color: #0080C0">CMS
            Authentication Sample</td>
        </tr>
    </thead>
    <tr>
      <td>
        <table width="100%">
          <td align="left" width="60%">
            Name Space:&nbsp;&nbsp;<input type="text" size="40", id="nameSpace" value="PLACEHOLDER"><br><br>
            &nbsp;&nbsp;User Name:&nbsp;&nbsp;<input type="text" size="40", id="userName" value="PLACEHOLDER"><br><br>
            &nbsp;&nbsp;&nbsp;&nbsp;Password:&nbsp;&nbsp;<input type="password" size="40", id="password" value="PLACEHOLDER"><br><br>
            &nbsp;&nbsp;&nbsp;&nbsp;Report ID:&nbsp;&nbsp;<input size="40" id="storeID" value="PLACEHOLDER"><br><br>
          </td>
          <td align="left" width="40%">
            <input type="submit" value="Report Output" onClick="doReport()"><br><br>
            <input type="submit" id="logoff" value="Logoff from IBM Cognos Server" onclick="doLogoff()"><br>
          </td>
        </table>
      </td>
    </tr>
    <tr>
      <td
        style="border-top-style: dashed; border-top-color: #000000; border-top-width: medium; border-bottom-style: dashed; border-bottom-width: medium; border-bottom-color: #000000"
            height="100%">
        <DIV id="fragment" style="height: 100%; width: 100%">Your report will appear here</DIV>
      </td>
    </tr>
</table>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

原因配置浏览器和Web服务器不允许CORS请求。

现代设计的浏览器和Web服务器发生此问题,与IBM Cognos产品无关。

这可以通过将请求的资源移动到同一个域或通过在Web服务器和浏览器中启用CORS =跨源资源共享来修复IE / IIS在浏览器/ Web服务器链中启用此功能,如果这在此处工作。

有关服务器和客户端的详细信息,请参阅:http://enable-cors.org

对于浏览器,请检查浏览器支持网站,因为这很可能是内部设置。

关于CORS的一般信息:

http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

参考:http://www-01.ibm.com/support/docview.wss?uid=swg21698830