Author Topic: How to use the XML-RPC with CF or Javascript  (Read 6985 times)

seraph

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
    • Email
How to use the XML-RPC with CF or Javascript
« on: January 14, 2009, 08:38:54 »
Hi guys,

Im a junior web developer working with ColdFusion8 and javascript. What Im trying to do for my company is replace the current wallboard monitor with my custom one with other information the call center agents need. The problem is that I cant seem to find any documentation for the XML-RPC implementation for ColdFusion or Javascript, so I have almost no idea on how to go about it. For now I managed to get the information from the wallboard using CFHTTP and stripping out what I need from it, but Im sure it would be alot less taxing if I use the XML-RPC to get only the information I require. What I've tried to do was first to get the specific table that I want from the queuemetrics-1.4.7/qm/qm_export_table.do?X.RealTimeDO.RTRiassunto address, but keeps telling me that my session is expired. I tried inputing the username and password in the CFHTTP tag but that didnt work. I then tried appending it to url as a url variable like queuemetrics-1.4.7/qm/qm_export_table.do?X.RealTimeDO.RTRiassunto&user="robot"&pass="something" but that still didnt work. I then tried to use javascript to get the XML, but that wasnt very successful as I could barely find any tutorials for using the xmlhttp.send() method properly. So  basically, could anybody help me out here? Ideally, I would really appreciate it if somebody could post a sample code of how to do this in either ColdFusion or Javascript, but even small things like pointing out if the url Im trying to get the data from is incorrect, whether I can login by appending the &user="robot"&password="something" to the url, or even what kind of method I would use to get the data like if I should use cfinvoke instead of cfhttp etc. Please help me, all comments are much appreciated.

Thanks.

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: How to use the XML-RPC with CF or Javascript
« Reply #1 on: January 14, 2009, 15:24:23 »
I came across this JavaScript library: http://code.google.com/p/json-xml-rpc/

I was able to port the sample script to it, it's pretty easy.

Code: [Select]
<html>
<head>
<title>javascript_client.html</title>
<script src="rpc.js"></script>
</head>
<body>

<h1>QueueMetrics JavaScript XML-RPC example </h1>
<hr>

<script>
var server = "/DAILY/xmlrpc.do";

function run() {

        try {
             var service = new rpc.ServiceProxy( server, {
                        asynchronous:false,
                        protocol: "XML-RPC",
                        methods: ["QM.stats"]
  } );

res = service.QM.stats( "q1", "robot", "robot","", "",
"2005-10-10.10:23:12", "2009-10-10.10:23:10","",
[ "KoDO.DiscCauses", "CallDistrDO.AnsDistrPerDay" ]
);

                document.getElementById("RESULT").innerHTML = plotBlocks(res);

        } catch(e) {
                alert("Error raised: " + e);
        }

}


function plotBlocks( hmBlocks ) {

        s = "";

        for (var i in hmBlocks) {
                s += "<h2>Block: " + i + "</h2>";
                s += plotBlock( hmBlocks[i] );
        }

        return s;
}

function plotBlock( arBlock ) {
        s = "";
        for ( r =0; r < arBlock.length; r++ ) {
                s += "<tr>";
                for ( c = 0; c < arBlock[r].length; c++ ) {
                        s += "<td>" + arBlock[r][c] + "</td>";
                }
                s += "</tr>";
        }
        return "<table border=1>"  + s + "</table>";
}


</script>

<input type="button" value="Click me!" onclick="run();" >

<div id="RESULT"></div>

</body>
</html>



This example requires the file rpc.js that comes from the client side
of the JSON-XML-RPC JavaScript library (see here: http://code.google.com/p/json-xml-rpc/ ).

Please note that the following file should be served on the same webserver as the QueueMetrics app it's going to access, or it will be denied access by the browser.

Please edit the file to set up access preferences.

We are going to include this example in QM as well.

seraph

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
    • Email
Re: How to use the XML-RPC with CF or Javascript
« Reply #2 on: January 15, 2009, 09:11:50 »
Thanks you soo much. I cant integrate it right now because the server running Queuemetrics is different to the one powering my custom wallboard, but my boss said he'll look at the code and try to do it on the Queuemetrics server.

Thanks Again!

torontob

  • Full Member
  • ***
  • Posts: 155
  • Karma: 0
    • View Profile
Re: How to use the XML-RPC with CF or Javascript
« Reply #3 on: December 26, 2010, 22:06:39 »
Hello,

I am trying the exact example and I am getting error:

Error raised: Error: Malformed XML document.

Has there been any major changes between the version this code was made for and the current 1.6.3.0 that I have installed right now?

Also, there is no port indication in the current Java file. How can a port 8099 for example be defined?

Thanks,



QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: How to use the XML-RPC with CF or Javascript
« Reply #4 on: January 10, 2011, 13:48:33 »
You just need to point it to the QM instance.

Scott B

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
    • View Profile
Re: How to use the XML-RPC with CF or Javascript
« Reply #5 on: February 26, 2011, 20:08:30 »
What does the sample script above do? Are there any commented examples I can look at? My javascript is a little bit .. meh. I suppose that's my problem, not yours  :D

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: How to use the XML-RPC with CF or Javascript
« Reply #6 on: February 28, 2011, 09:28:03 »
It will basically print out the realtime page in a way that's less pretty but easier for a program to access :)