Javascript to connect to OBIEE presentation
server to access few web service methods and present a table format with
the results from the web services.
<script type="text/javascript">
function getText(obj){
var t = "";
if (obj) //IE use .text, others .textContent
t = obj.text ? obj.text : obj.textContent;
return (t);
}
function callWebService()
{
var url = "";
var username = "prodney";
var password = "Admin123";
var xmlDoc = null;
var soapheader = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><soapenv:Body>";
var soapfooter = "</soapenv:Body></soapenv:Envelope>";
//var divResults = document.getElementById('listresultarea');
if (window.XMLHttpRequest){
xmlDoc = new XMLHttpRequest(); //Newer browsers
} else if (window.ActiveXObject) { //IE 5, 6
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlDoc){
//logon and obtain sessionID
xmlDoc.open("POST", url + "saw.dll?SoapImpl=nQSessionService",false);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("SOAPAction", "#logon");
xmlDoc.send(soapheader+ "<logon xmlns='urn://oracle.bi.webservices/v6'><name>"+username+"</name><password>"+password+"</password></logon>"+ soapfooter);
var sessionID = getText(xmlDoc.responseXML.getElementsByTagName('sawsoap:sessionID').item(0));
if (!sessionID){
//divResults.innerHTML += "Unable to connect to OBIEE server using the credentials provided";
document.writeln("Unable to connect to OBIEE server using the credentials provided");
return;
}
//get list of users
xmlDoc.open("POST", url + "saw.dll?SoapImpl=securityService",false);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("SOAPAction", "#getAccounts");
xmlDoc.send(soapheader
+ "<getAccounts xmlns='urn://oracle.bi.webservices/v6'><account><name>*</name><accountType>4</accountType><guid></guid></account><sessionID>"
+ sessionID + "</sessionID></getAccounts>"
+ soapfooter);
var userList = xmlDoc.responseXML.getElementsByTagName('sawsoap:name');
if (!userList){
//divResults.innerHTML += "Unable to retrieve users list";
document.writeln("Unable to retrieve users list");
return;
}
//divResults.innerHTML += "<table border=1><tr><th>User Name</th><th>Role/Group Name</th></tr>";
document.writeln("<table border=1><tr><th>User Name</th><th>Role/Group Name</th></tr>");
var user=null;
var grp=null;
//alert(userList.length);
for (i=0;i<userList.length;i++){
user=userList.item(i);
//get list of users
xmlDoc.open("POST", url + "saw.dll?SoapImpl=securityService",false);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("SOAPAction", "#getGroups");
xmlDoc.send(soapheader
+ "<getGroups xmlns='urn://oracle.bi.webservices/v6'><member><name>"
+ getText(user) + "</name><accountType>0</accountType><guid></guid></member><expandGroups>false</expandGroups><sessionID>"
+ sessionID + "</sessionID></getGroups>"
+ soapfooter);
var grpList = xmlDoc.responseXML.getElementsByTagName('sawsoap:name');
var usrString=getText(user);
var grpString="";
if (grpList){
for (g=0;g<grpList.length;g++){
grp = grpList.item(g);
grpString += getText(grp) + "<br/>";
}
//divResults.innerHTML +="<tr><td>"+usrString+"</td><td>"+grpString+"</td></tr>";
document.writeln("<tr><td>"+usrString+"</td><td>"+grpString+"</td></tr>");
}
}
} else {
//divResults.innerHTML +="Unable to create XMLHttpRequest object";
document.writeln("Unable to create XMLHttpRequest object");
}
//divResults.innerHTML += "</table>";
document.writeln("</table>");
}
callWebService();
</script>
<script type="text/javascript">
function getText(obj){
var t = "";
if (obj) //IE use .text, others .textContent
t = obj.text ? obj.text : obj.textContent;
return (t);
}
function callWebService()
{
var url = "";
var username = "prodney";
var password = "Admin123";
var xmlDoc = null;
var soapheader = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><soapenv:Body>";
var soapfooter = "</soapenv:Body></soapenv:Envelope>";
//var divResults = document.getElementById('listresultarea');
if (window.XMLHttpRequest){
xmlDoc = new XMLHttpRequest(); //Newer browsers
} else if (window.ActiveXObject) { //IE 5, 6
xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlDoc){
//logon and obtain sessionID
xmlDoc.open("POST", url + "saw.dll?SoapImpl=nQSessionService",false);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("SOAPAction", "#logon");
xmlDoc.send(soapheader+ "<logon xmlns='urn://oracle.bi.webservices/v6'><name>"+username+"</name><password>"+password+"</password></logon>"+ soapfooter);
var sessionID = getText(xmlDoc.responseXML.getElementsByTagName('sawsoap:sessionID').item(0));
if (!sessionID){
//divResults.innerHTML += "Unable to connect to OBIEE server using the credentials provided";
document.writeln("Unable to connect to OBIEE server using the credentials provided");
return;
}
//get list of users
xmlDoc.open("POST", url + "saw.dll?SoapImpl=securityService",false);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("SOAPAction", "#getAccounts");
xmlDoc.send(soapheader
+ "<getAccounts xmlns='urn://oracle.bi.webservices/v6'><account><name>*</name><accountType>4</accountType><guid></guid></account><sessionID>"
+ sessionID + "</sessionID></getAccounts>"
+ soapfooter);
var userList = xmlDoc.responseXML.getElementsByTagName('sawsoap:name');
if (!userList){
//divResults.innerHTML += "Unable to retrieve users list";
document.writeln("Unable to retrieve users list");
return;
}
//divResults.innerHTML += "<table border=1><tr><th>User Name</th><th>Role/Group Name</th></tr>";
document.writeln("<table border=1><tr><th>User Name</th><th>Role/Group Name</th></tr>");
var user=null;
var grp=null;
//alert(userList.length);
for (i=0;i<userList.length;i++){
user=userList.item(i);
//get list of users
xmlDoc.open("POST", url + "saw.dll?SoapImpl=securityService",false);
xmlDoc.setRequestHeader("Content-Type", "text/xml");
xmlDoc.setRequestHeader("SOAPAction", "#getGroups");
xmlDoc.send(soapheader
+ "<getGroups xmlns='urn://oracle.bi.webservices/v6'><member><name>"
+ getText(user) + "</name><accountType>0</accountType><guid></guid></member><expandGroups>false</expandGroups><sessionID>"
+ sessionID + "</sessionID></getGroups>"
+ soapfooter);
var grpList = xmlDoc.responseXML.getElementsByTagName('sawsoap:name');
var usrString=getText(user);
var grpString="";
if (grpList){
for (g=0;g<grpList.length;g++){
grp = grpList.item(g);
grpString += getText(grp) + "<br/>";
}
//divResults.innerHTML +="<tr><td>"+usrString+"</td><td>"+grpString+"</td></tr>";
document.writeln("<tr><td>"+usrString+"</td><td>"+grpString+"</td></tr>");
}
}
} else {
//divResults.innerHTML +="Unable to create XMLHttpRequest object";
document.writeln("Unable to create XMLHttpRequest object");
}
//divResults.innerHTML += "</table>";
document.writeln("</table>");
}
callWebService();
</script>
Good post!
ReplyDeleteHow can obtain the user's description?
Thanks
very nice like that
ReplyDeletephp development
Hi Abdul,
ReplyDeleteI am getting the follwing error
Unable to connect to OBIEE server using the credentials provided
Can you pls letme know how to resolve
May be the session id getting is null. Try giving xmlDoc.responseXML.getElementsByTagName('sessionID').item(0) instead of "sawsoap:sessionID"
Delete