Do anyone here knows flex builder?
I'm a beginner in this language. I have written a code for cloudstack api request and signature generation using hmac to authenticate the user account. here the command is 'listzones'. The output will be in xml shwing the list of zones available in the cloudstack i have installed. No error is showing while compiling. But when i run, the browser opens blank. The url is correct, ie it includes alla the commands and parameters and also the signature is genetated. I can see it in the url.But the orginal output is xml command it is not showing. the page is simply left blank. Can anyone help me?
the url generated will like as below:
The signature generated may vary each time.
The code is as follows.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:ns1="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.adobe.crypto.HMAC;
import com.adobe.crypto.SHA1;
import com.adobe.utils.StringUtil;
import flash.net.navigateToURL;
import mx.controls.Alert;
import mx.utils.Base64Encoder;
import mx.utils.StringUtil;
private var urlAPI:String;
private var commandString:String;
private var apiKey:String;
private var apiKeyString:String;
private var secretKey:String = "-kgkBuBUrGFeIC4gUvngSK_3Ypmi7fuF8XdVXIusnyyiEP2YUcG3FnPUGJGy3rp3Bw5ZNnqgS-9tIfyV1QnK1g";
private var signature:String;
private var urlRequestString:String
[Bindable]
private var encryptedString:String = "";
[Bindable]
private var encryptedByteArray:String = "";
private function generateRequest():void
{
urlAPI = "http://10.176.14.26/client/api";
commandString = "command=listZones";
apiKey = "";
apiKey = encodeURI(apiKey.toLowerCase());
apiKeyString = "apiKey=" + apiKey;
signature = generateSignature();
urlRequestString = urlAPI +"?"+commandString+"&"+apiKeyString+"&signature="+signature;// "command=listZones&apiKey=Qo9Qwfatwz9ARB328Btn9PftzL2Cf5LOWd8OFyJmiM513tpTIm-zKxJoWkWqf353Df397xcLdKXGk8_JO8nM3Q&signature=Lxx1DM40AjcXU%2FcaiK8RAP0O1hU%3D";
var urlRequestObj:URLRequest = new URLRequest(urlRequestString);
navigateToURL(urlRequestObj,"_blank");
}
private function generateSignature():String
{
var tempSignature:String = apiKey +"&"+commandString;
tempSignature = tempSignature.toLowerCase();
return hashMessage(tempSignature,secretKey);
}
private function hashMessage(message:String, secretKey:String):String
{
var algorithm:Object = SHA1;
var encoder:Base64Encoder = new Base64Encoder();
if(message.length > 0)
{
encryptedString = HMAC.hash(secretKey,message,algorithm);
var messageBytes:ByteArray = new ByteArray();
messageBytes.writeMultiByte(message,"utf-8");
encryptedByteArray = HMAC.hashBytes(getByteArray(),messageBytes,algorithm);
encoder.encode(encryptedByteArray);
}
//Alert.show(encoder.toString());
return encoder.toString();
}
private var byteArray:ByteArray;
[Bindable("dummyEventType")]
private function getByteArray():ByteArray
{
if(!byteArray)
{
byteArray = new ByteArray();
byteArray.writeMultiByte(secretKey,"utf-8");
//byteArray.
}
return byteArray;
}
]]>
</fx:Script>
<s:Button x="102" y="64" label="Button" click="generateRequest()"/>
<ns1:CloudInterfaceComp x="196" y="213">
</ns1:CloudInterfaceComp>
</s:Application>