Skip navigation
Currently Being Moderated

BlazeDS FlashDevelop RPC ArrayList

Jun 23, 2008 4:34 AM

Hi,<br /><br />I've managed to get RPC working with BlazeDS and FlashDevelop using pure actionscript 3 & rpc.swc.  Great, I can return strings & booleans from the my java objects.<br /><br />I've tried some tutes and the BlazeDS developers guide to try and create custom serialization.  But I am stuck with - ArgumentError: Error #2004: One of the parameters is invalid.  When I try to return an ArrayList?<br /><br />The developers guide says it's possible to associate the java ArrayList with mx.collections.ArrayCollection.  I've tried several methods but so far just get the above error.  <br /><br />Here's the ArrayList<IdeaRO> that I'm trying to serialize;<br /><br />package tbi.DAO;<br /><br />//import java.util.Vector;<br />import java.io.Externalizable;<br />import java.io.IOException;<br />import java.io.ObjectInput;<br />import java.io.ObjectOutput;<br /><br />/**<br /> * <br /> * @author Russell Taylor<br /> * @created 13.06.2008<br /> * <br /> * This result object contains relates to each Idea Touch Point<br /> * and can also be used the Ideas in the related scroll component<br /> *<br /> */<br />public class IdeaRO implements Externalizable {<br />     <br />     private int _id;<br />     private String _title;<br />     private String _imageUrl;<br />     private int _level;<br />     private int _plusScore;<br />     private int _minusScore;<br />     <br />     /**<br />      * BlazeDS needs this to instantiate<br />      */<br />     public IdeaRO(){<br />          <br />     }<br />     <br />     public int getId(){<br />          return _id;<br />     }<br />     <br />     public void setId(int value){<br />          this._id = value;<br />     }<br />     <br />     public String getTitle(){<br />          return _title;<br />     }<br />     <br />     public void setTitle(String value){<br />          this._title = value;<br />     }<br />     <br />     public String getImageURL(){<br />          return _imageUrl;<br />     }<br />     <br />     public void setImageURL(String value){<br />          this._imageUrl = value;<br />     }<br />     <br />     public int getLevel(){<br />          return _level;<br />     }<br />     <br />     public void setLevel(int value){<br />          this._level = value;<br />     }<br />     <br />     public int getPlusScore(){<br />          return _plusScore;<br />     }<br />     <br />     public void setPlusScore(int value){<br />          this._plusScore = value;<br />     }<br />     <br />     public int getMinusScore(){<br />          return _minusScore;<br />     }<br />     <br />     public void setMinusScore(int value){<br />          this._minusScore = value;<br />     }<br />     <br />     /**<br />     * Serializes the server state of an instance of ThirdPartyProxy<br />     * by sending a String for the name, a Map of properties<br />     * String for the description, and a floating point<br />     * integer (single precision) for the price. Notice that the inventory <br />     * identifier is not sent to external clients.<br />     */<br />    public void writeExternal(ObjectOutput out) throws IOException {<br />        // Write out the client properties from the server representation<br />        out.writeFloat(_id);<br />        out.writeObject(_title);<br />        out.writeObject(_imageUrl);<br />        out.writeFloat(_level);<br />        out.writeFloat(_minusScore);<br />        out.writeFloat(_plusScore);<br />    }<br />    <br />    /**<br />     * Deserializes the client state of an instance of ThirdPartyProxy<br />     * by reading in String for the name, a Map of properties<br />     * for the description, and <br />     * a floating point integer (single precision) for the price. <br />     */<br />    public void readExternal(ObjectInput in) throws IOException,<br />        ClassNotFoundException {<br />        // Read in the server properties from the client representation.<br />        _id = (int)in.readFloat();<br />        _title = (String)in.readObject();<br />        _imageUrl = (String)in.readObject();<br />        _level = (int)in.readFloat();<br />        _minusScore = (int)in.readFloat();<br />        _plusScore = (int)in.readFloat();<br />        <br />    }<br /><br />}<br /><br />Any help would be appreciated.<br /><br />Thanks,<br /><br />Russell
 
Replies
  • Currently Being Moderated
    Jun 23, 2008 5:17 AM   in reply to (Russell_C_Taylor)
    Make sure mx.collections.ArrayList is linked into your SWF so that it is
    available at runtime. You just need to import this class and make a
    reference to it somewhere so that it gets compiled into the SWF.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2008 6:42 AM   in reply to (Russell_C_Taylor)
    Importing something is not enough, you need to make a reference to it by<br />using the type for a variable, method signature, whatever... e.g. try<br />adding a dummy variable:<br /> <br />private static var dep:IdeaRO;<br /><br />________________________________<br /><br />From: Russell C Taylor [mailto:member@adobeforums.com] <br />Sent: Monday, June 23, 2008 9:33 AM<br />To: blazeds-gettingstarted@adobeforums.com<br />Subject: Re: BlazeDS FlashDevelop RPC ArrayList<br /><br /><br />A new message was posted by Russell C Taylor in <br /><br />Configuration and Getting Started Discussion --<br />  BlazeDS FlashDevelop RPC ArrayList<br /><br />Thanks for the quick response :) <br /><br />I have mx.collection.ArrayList included (Flex 2 source framwork<br />globalpath). But I think I'm missing a trick. I've read that LCDS has<br />problems serializing a custom ArrayList and returns null? My ArrayList<br />is in java is a standard arraylist of custom objects. ie.<br />ArrayList<IdeaRO>. <br /><br />Here's my test connection class in case I'm doing something wrong; <br /><br />package dao <br />{ <br />import flash.net.NetConnection; <br />import flash.net.Responder; <br />import flash.net.ObjectEncoding; <br />import flash.events.*; <br />import flash.text.*; <br />import flash.display.*; <br />import xml.XMLProxyModel; <br />import mx.collections.ArrayList; <br />import dao.IdeaRO; <br /><br />/** <br />* ... <br />* @author Russell Taylor <br />*/ <br />public class ConnectionHelper extends Sprite <br />{ <br />private var gateway:String = XMLProxyModel.getInstance().amfChannel; <br />private var con:NetConnection; <br />private var responder:Responder; <br />private var tf:TextField; <br /><br />public function ConnectionHelper() <br />{ <br /><br />responder = new Responder(onResult, onFault); <br /><br />con = new NetConnection(); <br />NetConnection.defaultObjectEncoding = ObjectEncoding.AMF3; <br /><br />con.addEventListener(NetStatusEvent.NET_STATUS, onStatus); <br />con.addEventListener(SecurityErrorEvent.SECURITY_ERROR,<br />securityErrorHandler); <br /><br />con.connect(gateway); <br /><br /><br /><br />con.call("tbi.getSphinxArray", responder); <br /><br />} <br /><br />private function onStatus(event:NetStatusEvent = null):void <br />{ <br />traceField("NetStatus="+String(event.info.code)); <br />} <br /><br />private function securityErrorHandler(event:SecurityErrorEvent =<br />null):void <br />{ <br />traceField("Security Error=" + event); <br />} <br /><br />private function onResult(result:Object):void <br />{ <br />var resultSet:ArrayList = ArrayList(result); <br />traceField("Result=" + String(resultSet)); <br /><br />} <br /><br />private function onFault(fault:Object=null):void <br />{ <br />traceField("Fault="+String(fault.message)); <br />} <br /><br />private function traceField(txt:String):void <br />{ <br />if(tf == null){ <br />tf = new TextField(); <br />tf.background = true; <br />tf.backgroundColor = 0xFFFFFF; <br />tf.width = 500; <br />tf.height = 500; <br />addChild(tf); <br />} <br />tf.appendText(txt); <br />} <br /><br />} <br /><br />} <br /><br />Can anyone see any glaring mistakes? <br /><br />Thanks. <br /><br /><br />________________________________<br /><br />View/reply at BlazeDS FlashDevelop RPC ArrayList<br /><a href=http://www.adobeforums.com/webx?13@@.59b59dad/1> <br />Replies by email are OK.<br />Use the unsubscribe<br /><a href=http://www.adobeforums.com/webx?280@@.59b59dad!folder=.3c061a84>   form<br />to cancel your email subscription.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2008 8:04 AM   in reply to (Russell_C_Taylor)
    <DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2>Oh sorry, I thought you were talking about <br />flex.messaging.io.ArrayList (Server) / mx.collections.ArrayList <br />(Client).</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2>You're just asking about the standard java.util.ArrayList <br />collection class. In that case, these are being returned as <br />flex.messaging.io.ArrayCollection instances by default, the equivalent for that <br />class on the client is mx.collections.ArrayCollection. </FONT></SPAN><SPAN <br />class=918365815-23062008><FONT face=Arial color=#0000ff size=2>So.... you would <br />need to ensure mx.collections.ArrayCollection is linked into your SWF in the <br />manner described earlier.</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2>Or.... you can change the BlazeDS endpoint <br />serialization setting "legacy-collection" to true to get it to return <br />ActionScript Arrays for Java Collections. See:</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2><A <br />href="http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.htm l?content=serialize_data_3.html">http://livedocs.adobe.com/blazeds/1/b lazeds_devguide/help.html?content=serialize_data_3.html</A></FONT></SP AN></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2>i.e.</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2></FONT></SPAN> </DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff size=2>        <br />&lt;channel-definition id="my-amf" <br />class="mx.messaging.channels.AMFChannel"&gt;<BR>            <br />&lt;endpoint url="<A <br />href="http://{server.name}:{server.port}/{context.root}/messagebrok er/amf">http://{server.name}:{server.port}/{context.root}/messagebroke r/amf</A>" <br />class="flex.messaging.endpoints.AMFEndpoint"/&gt;<BR>            <br />&lt;properties&gt;<BR>                <br />&lt;polling-enabled&gt;false&lt;/polling-enabled&gt;</FONT></SPAN>< /DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff <br />size=2>                &lt;serialization&gt;</FONT></SPAN></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff <br />size=2>                    <br />&lt;legacy-collection&gt;true&lt;/legacy-collection&gt;</FONT></SPA N></DIV><br /><DIV dir=ltr align=left><SPAN class=918365815-23062008><FONT face=Arial <br />color=#0000ff <br />size=2>                <br />&lt;/serialization&gt;<BR>            <br />&lt;/properties&gt;<BR>        <br />&lt;/channel-definition&gt;<BR></DIV></FONT></SPAN><BR><br /><DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><br /><HR tabIndex=-1><br /><FONT face=Tahoma size=2><B>From:</B> Russell C Taylor <br />[mailto:member@adobeforums.com] <BR><B>Sent:</B> Monday, June 23, 2008 11:38 <br />AM<BR><B>To:</B> blazeds-gettingstarted@adobeforums.com<BR><B>Subject:</B> Re: <br />BlazeDS FlashDevelop RPC ArrayList<BR></FONT><BR></DIV><br /><DIV></DIV>A new message was posted by Russell C Taylor in <br /><BR><BR><B>Configuration and Getting Started Discussion</B> <br />--<BR>  BlazeDS FlashDevelop RPC ArrayList<BR><BR>Here's the method <br />that creates the ArrayList I wish to parse to the client. <BR><BR>/** <BR>* <br />Search results method parses the HashMap <BR>* and returns a result list <br />collection <BR>* <BR>* @param ids HashMap&lt;String, int[]&gt; <BR>* <BR>* <br />@return List collection of results <BR>*/ <BR>public static <br />ArrayList&lt;IdeaRO&gt; getSphinxArray(HashMap&lt;String, int[]&gt; ids) throws <br />SQLException{ <BR>ArrayList&lt;IdeaRO&gt; list = new ArrayList&lt;IdeaRO&gt;(); <br /><BR>Connection c = null; <BR><BR>try{ <BR>c = ConnectionHelper.getConnection(); <br /><BR>Statement s = c.createStatement(); <BR>for (Iterator&lt;Map.Entry&lt;String, <br />int[]&gt;&gt; entry=ids.entrySet().iterator(); entry.hasNext();){ <br /><BR>Map.Entry&lt;String, int[]&gt; key = (Map.Entry&lt;String, <br />int[]&gt;)entry.next(); <BR>for(int id:key.getValue()){ <BR>ResultSet rs = <br />s.executeQuery("SELECT `tbi_db_test`.`post`.`title`, `tbi_db_test`.`link`.`url`, <br />`tbi_db_test`.`levelindicator`.`level`, <br />`tbi_db_test`.`scorerelation`.`score_plus`, <br />`tbi_db_test`.`scorerelation`.`score_minus` FROM `tbi_db_test`.`post` JOIN <br />tbi_db_test.link ON tbi_db_test.post.post_id=tbi_db_test.link.post_id_fk JOIN <br />tbi_db_test.levelindicator ON <br />tbi_db_test.post.post_id=tbi_db_test.levelindicator.post_id_fk JOIN <br />tbi_db_test.scorerelation ON <br />tbi_db_test.post.post_id=tbi_db_test.scorerelation.post_id_fk WHERE <br />tbi_db_test.post.post_id="+(int)id); <BR>while(rs.next()){ <BR>IdeaRO result = <br />new IdeaRO(); <BR>result.setId((int)id); <br /><BR>result.setTitle(rs.getString("title")); <br /><BR>result.setImageURL(rs.getString("url")); <br /><BR>result.setLevel(rs.getInt("level")); <br /><BR>result.setPlusScore(rs.getInt("score_plus")); <br /><BR>result.setMinusScore(rs.getInt("score_minus")); <BR>list.add(result); <BR>} <br /><BR>} <BR>} <BR>}finally{ <BR>c.close(); <BR>} <BR><BR>return list; <BR>}; <br /><BR><BR><br /><HR align=left width=200><br />View/reply at <A href="http://www.adobeforums.com/webx?13@@.59b59dad/5">BlazeDS <br />FlashDevelop RPC ArrayList</A><BR>Replies by email are OK.<BR>Use the <A <br />href="http://www.adobeforums.com/webx?280@@.59b59dad!folder=.3c061a 84">unsubscribe</A> <br />form to cancel your email subscription.<BR><BR>
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2008 8:23 AM   in reply to (Russell_C_Taylor)
    (Resending in plain text)...<br /><br /><br />Oh sorry, I thought you were talking about flex.messaging.io.ArrayList<br />(Server) / mx.collections.ArrayList (Client).<br /> <br />You're just asking about the standard java.util.ArrayList collection<br />class. In that case, these are being returned as<br />flex.messaging.io.ArrayCollection instances by default, the equivalent<br />for that class on the client is mx.collections.ArrayCollection. So....<br />you would need to ensure mx.collections.ArrayCollection is linked into<br />your SWF in the manner described earlier.<br /> <br />Or.... you can change the BlazeDS endpoint serialization setting<br />"legacy-collection" to true to get it to return ActionScript Arrays for<br />Java Collections. See:<br /> <br />http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?cont ent=s<br />erialize_data_3.html<br /> <br />i.e.<br /> <br />        <channel-definition id="my-amf"<br />class="mx.messaging.channels.AMFChannel"><br />            <endpoint<br />url="http://{server.name}:{server.port}/{context.root}/messagebroke r/amf<br />" class="flex.messaging.endpoints.AMFEndpoint"/><br />            <properties><br />                <polling-enabled>false</polling-enabled><br />                <serialization><br />                    <legacy-collection>true</legacy-collection><br />                </serialization><br />            </properties><br />        </channel-definition><br /><br /><br /><br /><br />------------------------------------------------------------------- -----<br />--------<br />From: Russell C Taylor [mailto:member@adobeforums.com] <br />Sent: Monday, June 23, 2008 11:38 AM<br />To: blazeds-gettingstarted@adobeforums.com<br />Subject: Re: BlazeDS FlashDevelop RPC ArrayList<br /><br /><br />A new message was posted by Russell C Taylor in <br /><br />Configuration and Getting Started Discussion --<br />  BlazeDS FlashDevelop RPC ArrayList<br /><br />Here's the method that creates the ArrayList I wish to parse to the<br />client. <br /><br />/** <br />* Search results method parses the HashMap <br />* and returns a result list collection <br />* <br />* @param ids HashMap<String, int[]> <br />* <br />* @return List collection of results <br />*/ <br />public static ArrayList<IdeaRO> getSphinxArray(HashMap<String, int[]><br />ids) throws SQLException{ <br />ArrayList<IdeaRO> list = new ArrayList<IdeaRO>(); <br />Connection c = null; <br /><br />try{ <br />c = ConnectionHelper.getConnection(); <br />Statement s = c.createStatement(); <br />for (Iterator<Map.Entry<String, int[]>> entry=ids.entrySet().iterator();<br />entry.hasNext();){ <br />Map.Entry<String, int[]> key = (Map.Entry<String, int[]>)entry.next(); <br />for(int id:key.getValue()){ <br />ResultSet rs = s.executeQuery("SELECT `tbi_db_test`.`post`.`title`,<br />`tbi_db_test`.`link`.`url`, `tbi_db_test`.`levelindicator`.`level`,<br />`tbi_db_test`.`scorerelation`.`score_plus`,<br />`tbi_db_test`.`scorerelation`.`score_minus` FROM `tbi_db_test`.`post`<br />JOIN tbi_db_test.link ON<br />tbi_db_test.post.post_id=tbi_db_test.link.post_id_fk JOIN<br />tbi_db_test.levelindicator ON<br />tbi_db_test.post.post_id=tbi_db_test.levelindicator.post_id_fk JOIN<br />tbi_db_test.scorerelation ON<br />tbi_db_test.post.post_id=tbi_db_test.scorerelation.post_id_fk WHERE<br />tbi_db_test.post.post_id="+(int)id); <br />while(rs.next()){ <br />IdeaRO result = new IdeaRO(); <br />result.setId((int)id); <br />result.setTitle(rs.getString("title")); <br />result.setImageURL(rs.getString("url")); <br />result.setLevel(rs.getInt("level")); <br />result.setPlusScore(rs.getInt("score_plus")); <br />result.setMinusScore(rs.getInt("score_minus")); <br />list.add(result); <br />} <br />} <br />} <br />}finally{ <br />c.close(); <br />} <br /><br />return list; <br />}; <br /><br /><br />------------------------------------------------------------------- -----<br />--------<br />View/reply at BlazeDS FlashDevelop RPC ArrayList<br />Replies by email are OK.<br />Use the unsubscribe form to cancel your email subscription.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 23, 2008 5:20 PM   in reply to (Russell_C_Taylor)
    It seems non-AMF 3 focused write methods don't trace debug output (they
    just delegate to the standard Java implementation from
    java.io.DataOutput).


    http://opensource.adobe.com/svn/opensource/blazeds/branches/3.0.x/modu le
    s/core/src/java/flex/messaging/io/amf/AbstractAmfOutput.java
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)