Ryan,
I just wrote this laszlo class, it's based on Laslzo's ajax.lzx class. It uses flash's XML.sendAndLoad to post raw xml to the backend in SOLO mode.

This class is more of a Laszlo to XML bridge, but so far it's working great with a few bugs.

This may give you a starting point.

-Daniel

Ryan Nowakowski wrote:
I have a flash application that I'm migrating to OL.  It currently uses
flash's XMLSocket to keep a persistent connection to our server.  Then
our flash app and server communicate via a custom protocol on that
connection.  How do I replicate that functionality in OL?

<canvas debug="true" proxied="false" height="400">

    <include href="./xmlhttprequest.lzx"/>

    <XMLRequest name="remote" />

    <view id="data">
      <method event="oninit">
       <![CDATA[
        var username_txt = 'test';
        var password_txt = 'pass';
        var login_str = "<lad><login username=\""+username_txt+"\" 
password=\""+password_txt+"\" /></lad>";
        remote.open('http://10.254.254.110/services/v2/progressive/loader/');
        remote.send(login_str);

        Debug.write('Status Code' + remote.getStatusCode());
       ]]>
      </method>
    </view>

</canvas>
<?xml version="1.0" encoding="UTF-8"?>
<library>	
  <!-- Implements SOLO XMLHttpRequest using XML.sendAndLoad 
       based on lps/components/rpc/ajax.lzx
  -->
  <class name="XMLRequest" extends="node">

    <!-- Remote server http://localhost/services/controller/action/ -->
    <attribute name="server" value="null" type="string" />

    <!-- XML we want to post the server, string or Laszlo DataSet -->
    <attribute name="content" value="null" />

    <!-- An XML object created with the XML constructor from Flash ActionScript 
         This will be used to store the RAW XML data we want to POST
         to the server
    -->
    <!-- @keywords private -->
    <attribute name="contentStore" value="null" />

    <!-- Action Script object to store XML response from server -->
    <!-- @keywords private -->
    <attribute name="responseStore" value="null" />
 
    <!-- Canvas level Laszlo dataset name -->
    <!-- Used when converting from AS object to Laszlo dataset -->
    <attribute name="datasetName" value="dsxmlRequest" type="string" />

    <!--- @keywords private -->
    <attribute name="dataset" value="null" />

    <!--- statusCode Numeric code returned XML ActionScript, 0,1,2,3,4,5,6,7,8,9,10,11,12 -->
    <attribute name="statusCode" value="null" type="number" />

    <!--- statusMessage String message of statusCode -->
    <attribute name="statusMessage" value="null" type="string" />

    <!-- Bytes loaded from server -->
    <attribute name="bytesLoaded" value="null" type="number" />

    <!-- Total Bytes loaded from Server -->
    <attribute name="totalBytesLoaded" value="null" type="number" />

    <!-- Discards text nodes that contain only white space -->
    <attribute name="ignoreWhiteSpace" value="true" type="string" />

    <event name="onstatusCode"/>
    <event name="onbytesLoaded"/>

    <method event="oninit">
      <![CDATA[
        if(this.dataset == null) 
        {
          this.dataset = new LzDataset(canvas,{name:this.datasetName});
        }
        else
        {
          this.dataset = new LzDataset(this);
        }

        if(this.contentStore == null)
        {
          this.contentStore = new XML();
        }

        if(this.responseStore == null)
        {
          this.responseStore = new XML();
        }
        Debug.write('Start');
      ]]>
    </method>

   <method name="setStatusCode" args="code">
     <![CDATA[
       Debug.write('Start set StatusCode' + code);
       if(!isinited) 
       {
         this.statusCode = code;
         return;
       }

       if(this.statusCode == code)
       {
         return;
       }

       switch(code)
       {
         case 0 :
           this.statusCode = 0;
           this.statusMessage = 'No error; parse was completed successfully.';
         break;
         case 2 :
           this.statusCode = 2;
           this.statusMessage = 'A CDATA section was not properly terminated.';
         break;
         case 3 :
           this.statusCode = 3;
           this.statusMessage = 'The XML declaration was not properly terminated.';
         break;
         case 4 :
           this.statusCode = 4;
           this.statusMessage = 'The DOCTYPE declaration was not properly terminated.';
         break;
         case 5 :
           this.statusCode = 5;
           this.statusMessage = 'A comment was not properly terminated.';
         break;
         case 6 :
           this.statusCode = 6;
           this.statusMessage = 'An XML element was malformed.';
         break;
         case 7 :
           this.statusCode = 7;
           this.statusMessage = 'Out of memory.';
         break;
         case 8 :
           this.statusCode = 8;
           this.statusMessage = 'An attribute value was not properly terminated.';
         break;
         case 9 :
           this.statusCode = 9;
           this.statusMessage = 'A start tag was not matched with an end tag.';
         break;
         case 10 :
           this.statusCode = 10;
           this.statusMessage = 'An end tag was encountered without a matching start tag.';
         break;
         case 11 :
           this.statusCode = 11;
           this.statusMessage = 'Missing URL';
         break;
         default :
           this.statusCode(1);
           this.statusMessage = 'An unknown error has occurred.';
           Debug.write('Set Status Switch default');
         break;
       }

       if(onstatusCode) 
       {
         onstatusCode.sendEvent();
       }

     ]]>
   </method>

   <method name="setBytesLoaded" args="bytes">
     <![CDATA[
       if(!isinited)
       {
         this.bytesLoaded = bytes;
         return;
       }

       if(this.bytesLoaded == bytes)
       {
         return;
       }

       this.bytesLoaded = bytes;

       if(onbytesLoaded)
       {
         onbytesLoaded.sendEvent();
       }

     ]]>
   </method>

   <method name="getStatusCode">
     return this.statusCode;
   </method>

   <method name="getStatusMessage">
     return this.statusMessage;
   </method>

   <method name="getTotalBytesLoaded">
     return this.totalBytesLoaded;
   </method>

   <method name="destroy">
     this.dataset.destroy();
   </method>

   <method name="open" args="url">
     <![CDATA[
       if(url == null)
       {
         this.setStatusCode(11);
         return;
       }
       this.server = url;
       this.setStatusCode(0);
     ]]>
   </method>

   <method name="send" args="content">
     <![CDATA[
       if(content != null)
       {
         if(typeof(content) == 'string')
         {
           this.contentStore.parseXML(content);
         }
         else
         {
           this.contentStore.parseXML(content.serialize());
         }

         this.setStatusCode(this.contentStore.status);

         if(this.getStatusCode() == 0)
         {
           // Hack to have access to the parent class from within the XML class instance
           this.responseStore["response"] = this;

           this.responseStore.ignoreWhite = this.ignoreWhiteSpace;
           this.responseStore.onLoad = responseLoader
           contentStore.sendAndLoad(this.server,this.responseStore);
         }
       }
     ]]>
   </method>

   <method name="responseLoader" args="success">
     <![CDATA[
       if(success)
       {
         this.response.setStatusCode(this.response.responseStore.status);
         var dp = this.response.dataset.getPointer();
         var element = LzDataNode.stringToLzData(this.response.responseStore.toString());
         dp.p.appendChild(element);
       }
       else
       {
         this.response.setStatusCode(this.response.responseStore.status);
       }
     ]]>
   </method>
  </class>
</library>

Reply via email to