<?xml version="1.0" encoding="utf-8"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<title>Daniel Harfleet</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/" />
<modified>2007-01-22T09:54:52Z</modified>
<tagline></tagline>
<id>tag:weblogs.macromedia.com,2008:/dharfleet//61</id>
<generator url="http://www.movabletype.org/" version="3.16">Movable Type</generator>
<copyright>Copyright (c) 2006, dharfleet</copyright>
<entry>
<title>Cairngorm on Labs</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/08/cairngorm_on_la.cfm" />
<modified>2007-01-22T09:54:52Z</modified>
<issued>2006-08-21T13:23:31Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11733</id>
<created>2006-08-21T13:23:31Z</created>
<summary type="text/plain">As many of you are aware, Cairngorm now has space at Adobe Labs. We are hoping to soon update the content on Labs in order to give people more resources to become productive with Cairgorm. We&apos;d really like to hear...</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Cairngorm</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>As many of you are aware, Cairngorm now has space at Adobe Labs. We are hoping to soon update the content on Labs in order to give people more resources to become productive with Cairgorm.</p>

<p>We'd really like to hear from you if you have any ideas or opinions on the type of thing we should be including.</p>]]>
<![CDATA[<p>Please let us know and reply to all or just directly to me (dharfleet at adobe.com) with details of what you would like to see, why you want to see it and how it would enable you or others to utilise Cairngorm. <br />
</p>]]>
</content>
</entry>
<entry>
<title>Flex Messaging in Tomcat</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/08/flex_messaging.cfm" />
<modified>2007-01-22T09:53:56Z</modified>
<issued>2006-08-09T21:46:34Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11627</id>
<created>2006-08-09T21:46:34Z</created>
<summary type="text/plain">I have noticed a number of comments on blogs recently that Flex Message Service cannot be used on Tomcat, because Tomcat does not contain JMS. This is not the case....</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Flex Data Services</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>I have noticed a number of comments on blogs recently that Flex Message Service cannot be used on Tomcat, because Tomcat does not contain JMS.<br />
This is not the case.</p>]]>
<![CDATA[<p>Flex messaging can act as a JMS client and subscribe to JMS topics, however, this does not mean that the JMS MOM needs to be within Tomcat, it just means that the Flex message adapter for JMS can connect to the MOM, which could be on a different server.</p>

<p>In addition to this, you can use the 'ActionScript Adapter' for messaging, which means that messages can be passed between Flex clients without the need of JMS, this would be a potential solution, if you did not need to integrate with any other systems via JMS.</p>]]>
</content>
</entry>
<entry>
<title>A more secure ServiceLocator</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/08/secure_service.cfm" />
<modified>2006-08-04T18:23:12Z</modified>
<issued>2006-08-04T18:22:14Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11423</id>
<created>2006-08-04T18:22:14Z</created>
<summary type="text/plain">In my coffee break guide Calling Java remote objects and handling results I mentioned the Cairngorm ServiceLocator class. Peter Martin has created a SecureDestinationLocator which is aimed at supporting custom authentication in Flex, which of course uses the J2EE security...</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Flex Data Services</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>In my coffee break guide <a href="http://weblogs.macromedia.com/dharfleet/archives/coffee_break_guides/index.cfm">Calling Java remote objects and handling results</a> I mentioned the Cairngorm ServiceLocator class. Peter Martin has created a SecureDestinationLocator which is aimed at supporting custom authentication in Flex, which of course uses the J2EE security model. It subclasses another class he has created called DestinationLocator, which   provides service location for FDMS and messaging.</p>

<p>We have used this in anger and it works well. I hope SecureDestinationLocator will make the next Cairngorm release, but in the mean time, you can get the code from Peter's <a href="http://weblogs.macromedia.com/pmartin/archives/2006/06/cairngorm_2_sec.cfm#more">Blog</a> or check out his <a href="http://www.adobe.com/events/max/sessions/ri212w.html">presentation</a> at MAX.</p>]]>

</content>
</entry>
<entry>
<title>Debugging Flex and Java at the same time</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/08/debugging_flex.cfm" />
<modified>2007-01-22T09:53:16Z</modified>
<issued>2006-08-04T17:19:22Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11418</id>
<created>2006-08-04T17:19:22Z</created>
<summary type="text/plain">Those of you are familiar with the java debugger in Eclipse will be pleased to know that Flex Builder includes a very similar debugger for debugging Flex code. In this article I will show you how to achieve end to...</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>Those of you are familiar with the java debugger in Eclipse will be pleased to know that Flex Builder includes a very similar debugger for debugging Flex code. In this article I will show you how to achieve end to end debugging, using Flex Builder, the FDS gateway logs and Eclipse java debugger connecting to JBoss by way of JPDA remote debugging.</p>]]>
<![CDATA[<p>As mentioned previously, the gateway is the component which lives on the server and is responsible for converting object instances between java and ActionScript. It can carry out deep copies and knows which java objects map to your Actionscript objects, assuming you have marked them with<br />
<pre>[RemoteClass(alias="java.package.structure.classname")]</pre></p>

<p>We can change the log level of the gateway and take a look at what it is up to.</p>

<p>In services-config.xml, change the log level from Error to Debug as below:<br />
<pre><br />
   &lt;logging&gt;<br />
      &lt;target class="flex.messaging.log.ConsoleTarget" level="Debug"&gt;<br />
</pre><br />
        <br />
You will now have to restart JBoss. Now load up the app in your browser, also have the JBoss console on your screen, enter an address into the form and submit.<br />
You will see the output of the 'request' in the console:</p>

<p>The output below occurs the first time a call is made from the client, it's just checking that the endpoint is still available, don't expect to see this every call.<br />
<pre><br />
12:16:14,805 INFO  [STDOUT] [Flex] Deserializing AMF/HTTP request<br />
Version: 3<br />
  (Message #0 targetURI=null, responseURI=/1)<br />
    (Array #0)<br />
      [0] = (Typed Object #0 'flex.messaging.messages.CommandMessage')<br />
        operation = 5<br />
        messageRefType = null<br />
        correlationId = ""<br />
        messageId = "8DA9ED25-7DA2-0175-16F8-5D4D2EF8E163"<br />
        headers = (Object #1)<br />
        timestamp = 0<br />
        body = (Object #2)<br />
        clientId = null<br />
        destination = ""<br />
        timeToLive = 0<br />
12:16:14,837 INFO  [STDOUT] [Flex] Serializing AMF/HTTP response<br />
Version: 3<br />
  (Message #0 targetURI=/1/onResult, responseURI=)<br />
    (Typed Object #0 'flex.messaging.messages.AcknowledgeMessage')<br />
      destination = null<br />
      headers = (Object #1)<br />
      correlationId = "8DA9ED25-7DA2-0175-16F8-5D4D2EF8E163"<br />
      messageId = "2FC970B5-9518-4649-21E9-ED57D3A627EC"<br />
      timestamp = 1.152616574821E12<br />
      clientId = "2FC970B5-950E-1903-993A-5EB4299C54B5"<br />
      timeToLive = 0.0<br />
      body = null<br />
</pre>     </p>

<p>Next you will see our request to the remote object:<br />
<pre><br />
12:16:14,852 INFO  [STDOUT] [Flex] Channel endpoint my-amf received request.<br />
12:16:14,868 INFO  [STDOUT] [Flex] Deserializing AMF/HTTP request<br />
Version: 3<br />
  (Message #0 targetURI=null, responseURI=/2)<br />
    (Array #0)<br />
      [0] = (Typed Object #0 'flex.messaging.messages.RemotingMessage')<br />
        operation = "addAddress"<br />
        source = null<br />
        messageId = "D9F1547F-D5A7-4C11-E53D-5D4D2ED818F1"<br />
        headers = (Object #1)<br />
          DSEndpoint = "my-amf"<br />
        timestamp = 0<br />
        body = (Array #2)<br />
          [0] = (Typed Object #3 'fdsweb.AddressVO')<br />
            line2 = "The Street"<br />
            line1 = "44"<br />
            postalCode = "EH11 9DQ"<br />
            city = "EDINBURGH"<br />
        clientId = null<br />
        destination = "addressBookDelegate"<br />
        timeToLive = 0<br />
</pre></p>

<p>Remember that the data does not get transmitted in textual format, it gets sent in binary AMF, this is just the output from the gateway logging after it has received it.</p>

<p>Next we see the gateway calling the remote object and the results from that call:</p>

<pre>
12:16:14,868 INFO  [STDOUT] [Flex] Adapter 'java-object' called 'fdsweb.AddressB
ookDelegate.addAddress(java.util.Arrays$ArrayList (Collection size:1)
  [0] = fdsweb.AddressVO
    postalCode = EH11 9DQ
    line1 = 44
    line2 = The Street
    city = EDINBURGH

<p>)'<br />
</pre><br />
<pre><br />
12:16:14,868 INFO  [STDOUT] [Flex] Result: 'java.util.Vector (Collection size:1)</p>

<p>  [0] = fdsweb.AddressVO<br />
    postalCode = EH11 9DQ<br />
    line1 = 44<br />
    line2 = The Street<br />
    city = EDINBURGH</p>

<p>)'<br />
</pre></p>

<p>And finally we see the response about to go back to the client:</p>

<pre>
12:16:14,868 INFO  [STDOUT] [Flex] Serializing AMF/HTTP response
Version: 3
  (Message #0 targetURI=/2/onResult, responseURI=)
    (Typed Object #0 'flex.messaging.messages.AcknowledgeMessage')
      destination = null
      headers = (Object #1)
      correlationId = "D9F1547F-D5A7-4C11-E53D-5D4D2ED818F1"
      messageId = "2FC97128-541C-9D37-38F6-21D302743239"
      timestamp = 1.152616574868E12
      clientId = "2FC97128-540D-3181-BC10-60C5D327A94E"
      timeToLive = 0.0
      body = (Externalizable Object #2 'flex.messaging.io.ArrayCollection')
        (Array #3)
          [0] = (Typed Object #4 'fdsweb.AddressVO')
            postalCode = "EH11 9DQ"
            line1 = "44"
            line2 = "The Street"
            city = "EDINBURGH"
</pre>

<p>The flex debugging provided in Eclipse is very similar to the java debugging and is intuitive for anyone who has ever used the java debugger. For the full details on debugging in Flex Builder, see the <a href="http://livedocs.macromedia.com/flex/2/docs/00000377.html">docs</a>, for now you are good to go if you can just set a breakpoint as in the java debugger.</p>

<p>If you want to debug the remote object running in JBoss, you can set up <a href="http://java.sun.com/products/jpda/">JPDA</a> (Java Platform Debugger Architecture). This allows Eclipse to connect to JBoss by way of sockets and exchange debugging information necessary for the java debugger.</p>

<p>Setting up JPDA in JBoss is actually very simple, all you need to do is:</p>

<p>a) stop JBoss<br />
b) copy the [jboss root]/bin/run.bat to [jboss root]/bin/run_debug.bat (Unix/Linux users change as necessary)<br />
c) in run_debug.bat, uncomment this line:<br />
<pre><br />
rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.<br />
rem set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%<br />
</pre><br />
to read this:<br />
<pre><br />
rem JPDA options. Uncomment and modify as appropriate to enable remote debugging.<br />
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%<br />
</pre><br />
d) start JBoss using your new run_debug script<br />
e) in Flexbuilder/Eclipse, click on the 'bug' icon and select 'Debug....'<br />
f) select 'Remote Java Application' and hit 'new', change the name of the configuration if you wish, change the port to 8787 (or change the connection properties to reflect those set in the run_debug script if different from above).<br />
g) click debug<br />
h) in the AddressBookDelegate source, add a breakpoint in the addAddress method<br />
i) open the app in your browser and submit an address, you may need to press 'continue' if you do not reach the breakpoint straight away.</p>

<p>From the above techniques, you should be able to set a breakpoint in the Flex code and the java code and watch the gateway debug output, this will give you end to end debugging.</p>]]>
</content>
</entry>
<entry>
<title>Passing complex parameters and results</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/08/passing_complex.cfm" />
<modified>2007-01-22T09:51:46Z</modified>
<issued>2006-08-04T17:05:34Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11417</id>
<created>2006-08-04T17:05:34Z</created>
<summary type="text/plain">In my previous coffee break guide, you saw flex integrating with java by way of passing strings, obviously if this was the only way we could pass information between flex and java, it would be pretty limited. In this post,...</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>In my previous coffee break guide, you saw flex integrating with java by way of passing strings, obviously if this was the only way we could pass information between flex and java, it would be pretty limited. In this post, I will show you how you can pass more complex objects (often called <a href="http://java.sun.com/blueprints/patterns/TransferObject.html">DTOs</a> or <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_03.html">Value Objects</a>) between flex and java. Like always I provide you the code to allow you to try it out.</p>]]>
<![CDATA[<p>In this example we will create a very simple address book for the sole purpose of demonstrating passing complex parameters.</p>

<p>Under the src/fdweb directory of your project, create a java class called AddressBookDelegate and populate it with the code <a href="http://weblogs.macromedia.com/dharfleet/src/fdsweb/AddressBookDelegate.java">here</a>, this class will be the remote object we are going to call. You will notice in the addAddress method, that we pass in an AddressVO and we pass back a List of AddressVOs, we don't have to pass back Lists, it is just satisfying the functionality we need.</p>

<p>Under your project directory, at the same level as META-INF and WEB-INF, create a folder called 'fdsweb' and inside it create a new ActionScript class using File>New>ActionScript class. Call it AddressVO.as and add the following code in:</p>

<pre>
package fdsweb
{
   [Bindable]
   [RemoteClass(alias="fdsweb.AddressVO")]
  	
   public class AddressVO
   {			
      public var line1 : String;
      public var line2 : String;
      public var city : String;
      public var postalCode : String;
	
   }
}
</pre>

<p>In a real project, this directory would probably be com.company.project.etc and is where you will hold all your ActionScript code, but today we will just have a simple package structure.</p>

<p>What the above code shows is that we have a value object (DTO) which has four attributes all of which are Strings, however, as a java developer you probably would have worked this out for yourself as AS syntax is relatively similar to Java. Notice however in ActionScript, you have to declare the package using a brace notation. The main thing to be aware of here is that we are telling the gateway (the component that does the flex-java-flex mapping) that we would like this class to map to our java class AddressVO (in java package fdsweb).</p>

<p>Next we should create the java class, just create a standard java value object, take a look <a href="http://weblogs.macromedia.com/dharfleet/src/fdsweb/AddressVO.java">here</a> if you want a sanity check. The java class does not need to be serializable, however, it must have a no-args constructor.</p>

<p>Now we just need to add in the destination which tells the gateway about the remote java object, add the following:</p>

<p><br />
to your remoting-config file, under WEB-INF/flex:<br />
<pre><br />
   &lt;destination id="addressBookDelegate"&gt;<br />
      &lt;properties&gt;<br />
         &lt;source&gt;fdsweb.AddressBookDelegate&lt;/source&gt;<br />
         &lt;scope&gt;application&lt;/scope&gt;<br />
      &lt;/properties&gt;<br />
   &lt;/destination&gt;<br />
</pre>  <br />
    </p>

<p>As mentioned earlier the flex gateway is responsible for translating java to ActionScript and ActionScript to java, it copies across the data, it can handle deep copies and does not get caught out by circular references.</p>

<p>Create a new mxml class in the project and call it AddressBookView.mxml and populate it with the source code from <a href="http://weblogs.macromedia.com/dharfleet/AddressBookView.mxml">here</a>. The mxml file contains some view related code, in this case we have a form, which is just a way of laying out some components, our form contains four text inputs and a button.</p>

<p>We also have a DataGrid, which is very similar to a JTable if you have ever coded Swing.</p>

<p>When the user inputs four lines of their address and click add, the click event is fired and the button has the handleAdd() function registered to handle click event for it. The handleAdd() function creates an empty AddressVO and populates it with the data from the text inputs in the form.</p>

<pre>
   private function handleAdd() : void
   {
      var address : AddressVO = new AddressVO();
      address.line1 = line1Input.text;
      address.line2 = line2Input.text;
      address.city = cityInput.text;
      address.postalCode = postalCodeInput.text;
		
      addressBookRO.addAddress(address);
   }
</pre>

<p>It then calls the method on the remote object (addAddress), this calls the addAddress(..) method on the java remote object, which adds the address to the address book and then sends back the contents of the address book as a List of AddressVOs. The remote object's result handler is pointing to the handleResult function, which updates our local copy of the list of addresses (we are using an ArrayCollection).<br />
<pre><br />
   private function handleResult( event : Object ) : void<br />
   {<br />
      addressList = event.result;<br />
   }<br />
</pre></p>

<p>The DataGrid mentioned earlier has a property of dataProvider set to reference the list of addresses, whenever that list changes, a 'binding event' is fired, which the DataGrid receives and re-populates itself.</p>

<pre>&lt;mx:DataGrid dataProvider="{addressList}" width="100%" height="100%" /&gt;</pre>

<p>Flex allows you to break visual components down into sub-components so that you can manage your project source more easily, in addition as a java developer, you may want to take a look at the <a href="http://labs.adobe.com/wiki/index.php/Cairngorm">Cairngorm</a> microarchitecture, which provides a set of patterns to allow you to better architect a project. </p>

<p>In the next guide, I will show you how to look at the output of the gateway to see how your object gets passed, I will also show you how you can debug your client-side flex code using the FlexBuilder debugger and show you how you can use JPDA to remote debug the java remote object. This will give you full end to end debugging.</p>]]>
</content>
</entry>
<entry>
<title>Calling Java remote objects and handling results</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/08/calling_java_re.cfm" />
<modified>2006-08-04T17:02:02Z</modified>
<issued>2006-08-04T17:00:00Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11416</id>
<created>2006-08-04T17:00:00Z</created>
<summary type="text/plain">In my previous coffee break guide we got a flex app talking to some java on the server. I&apos;m guessing you are all happy with how the java works, but a quick explanation of how we called the java and...</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>In my previous coffee break guide we got a flex app talking to some java on the server. I'm guessing you are all happy with how the java works, but a quick explanation of how we called the java and how we handled the results would be useful.</p>]]>
<![CDATA[<p>If you take a look at EchoView.mxml, there are a number of 'features' I would like to describe to you. The mxml file itself will be compiled by the flex compiler into a .swf file, which is the binary which will run in the browser ( a flash movie ). The mxml in this file is derived from an mx:Application tag, for the purposes of this discussion, think of this as the 'entry point' of the client application. You will see there is some view code, which is made up of various controls such as buttons and text inputs and some layout code, such as HBox. I will not discuss this layout code in any more detail, I'm sure you guys can figure it out, but if not, take a look at the <a href="http://livedocs.macromedia.com/flex/2/docs/00000653.html">docs</a>.</p>

<p>Next is the code which allows us to hook onto the server and make our RPC call, this is declared inside the RemoteObject tag:<br />
<pre><br />
&lt;mx:RemoteObject<br />
   id="echoRO"<br />
   destination="echoService"<br />
   fault="handleFault(event)"<br />
   result="handleResult(event)" /&gt;<br />
</pre><br />
	 <br />
The id is just our instance name for an instance of RemoteObject, the destination points to the remote destination which is configured in our remoting-config file:<br />
<pre><br />
&lt;destination id="echoService"&gt;<br />
   &lt;properties&gt;<br />
   &lt;source&gt;fdsweb.EchoService&lt;/source&gt;<br />
   &lt;scope&gt;application&lt;/scope&gt;<br />
   &lt;/properties&gt;<br />
&lt;/destination&gt;<br />
</pre><br />
The fault and result properties are in fact event handlers and they point to functions which will handle the events, as you can see, they also pass in the event as a parameter. The fault event occurs when something goes wrong, including exceptions in the server java code, i.e. our remote object. The result event (hopefully) will be called most of the time, this points to the function which will handle successful results from the remote objects. The flex gateway (the code in the WAR file) translates standard java parameters and return types to standard flex parameters and return types, as described here:</p>

<p><a href="http://livedocs.macromedia.com/flex/2/docs/00001104.html">Java to ActionScript</a><br />
<a href="http://livedocs.macromedia.com/flex/2/docs/00001103.html">ActionScript to Java</a></p>

<p><br />
On a real project, we would use the Cairngorm microarchitecture to abstract out our remote objects into a <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt5_03.html">ServiceLocator</a>, but as we are just wanting to play, lets just go with declaring the remote object in our mxml entry point file.</p>

<p>You will notice that the event handling code in the MXML file is written in action script and as such is declared in an mx:Script tag. The functions handleResult and handleFault are the same functions which we point our remote object event handlers to, handleClear describes what happens when the user clicks on the clear button (note the button has a click event handler which is pointing to this function) and finally handleSend describes what happens when the user clicks on the send button, apart from doing some trivial view stuff, this function calls the remote object:<br />
<pre><br />
echoRO.echo(message);<br />
</pre></p>

<p>any method which is exposed on the remote java object can be called by the actionscript code (subject to security), as long as it passes a compatible parameter, see the docs for type mapping. The most important thing you will need to get your head around is that you do not assign the return of the remote method from the result of the call, in other words you do not assign it in the handleSend function. Remote object calls are asynchronous, so the client continues working in parallel to the server handling the method call, the result appears as an event on the remote object, which is handled as I mentioned earlier by the 'result' or 'fault' events on the remote object, which in our case point to handleResult and handleFault functions.</p>

<p>It is important to remember that the request and the response are asynchronous, so if you made request-A and then request-B you are likely to receive response-A and response-B, however, there is no guarantee and you could receive response-B and then response-A; see <a href="http://www.adobe.com/devnet/flex/articles/flexfaq.html#itemA-31">Asynchronous Call Token</a> for a typical way of matching requests to responses if you need to.</p>

<p>As you are probably starting to work out, using the current techniques above, you would be limited to only using java parameters and return types which are mapped; fortunately however, Flex allows us to create complex objects which we can pass back and forth, often these objects are known as <a href="http://java.sun.com/blueprints/patterns/TransferObject.html">Data Transfer Objects</a> or <a href="http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_03.html">Value Objects</a>, however, ultimately they are just objects.</p>

<p>In the next coffee-break guide, I will show how you can pass your own custom object to from flex to java and also a custom object from java to flex.</p>]]>
</content>
</entry>
<entry>
<title>Integrating Java and Flex with a simple RPC example</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/07/integrating_jav.cfm" />
<modified>2007-01-22T09:50:26Z</modified>
<issued>2006-07-13T12:20:44Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11415</id>
<created>2006-07-13T12:20:44Z</created>
<summary type="text/plain">In the last coffee break guide you will recall that we set up Eclipse to allow coding of java within a flex project, you will also remember that we created a simple java class with an &apos;echo&apos; method on it....</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>In the last coffee break guide you will recall that we set up Eclipse to allow coding of java within a flex project, you will also remember that we created a simple java class with an 'echo' method on it. In this guide, we will get the flex code (i.e. the flash client) to call the java server code.</p>]]>
<![CDATA[<p>First of all you need to do a little bit of config, under WEB-INF/flex, edit remoting-config.xml, adding in:<br />
<pre><br />
   &lt;destination id="echoService"&gt;<br />
      &lt;properties&gt;<br />
         &lt;source&gt;fdsweb.EchoService&lt;/source&gt;<br />
         &lt;scope&gt;application&lt;/scope&gt;<br />
      &lt;/properties&gt;<br />
   &lt;/destination&gt;<br />
</pre></p>

<p>Inside the service tag. This allows the flex client to access the remote java class, you can read more about this in the docs, the above will work for you now.</p>

<p>Double check your class file has compiled and is under WEB-INF/classes.</p>

<p>Now you need to write a simple flex client to the java class, to save you time, I have done this, so create an empty Flex Application mxml file by doing: New&gt;MXML Application and call it EchoView, leave the layout to its default.</p>

<p>You should have an mxml file now with an empty application tag inside it. Replace all of the contents of the file with this:</p>

<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"&gt;
	
   &lt;!-- VIEW CODE --&gt;
	
   &lt;mx:Label text="Echo Service Simple RPC Example" fontSize="20" /&gt;	 
	    
   &lt;mx:Spacer height="20" /&gt;
    
   &lt;mx:TextInput id="messageInput" /&gt;
    
   &lt;mx:HBox&gt;
    			
      &lt;mx:Button label="send" click="handleSend(messageInput.text);" /&gt;
      &lt;mx:Button label="clear" click="handleClear();" visible="false" id="clear" /&gt;
		    	
   &lt;/mx:HBox&gt;

<p>   &lt;mx:Label id="resultLabel" /&gt;<br />
	<br />
	<br />
   &lt;!-- REPRESENTS THE REMOTE OBJECT --&gt;<br />
   &lt;mx:RemoteObject<br />
      id="echoRO"<br />
      destination="echoService"<br />
      fault="handleFault(event)"<br />
      result="handleResult(event)" /&gt;<br />
	<br />
	<br />
      &lt;!-- EVENT HANDLING CODE --&gt;<br />
      &lt;mx:Script&gt;&lt;![CDATA[<br />
	<br />
      import mx.controls.Alert;<br />
			<br />
      private function handleSend( message : String ) : void<br />
      {<br />
            resultLabel.text = "";<br />
            echoRO.echo(message);<br />
            clear.visible = true;<br />
      }<br />
	<br />
      private function handleClear() : void<br />
      {<br />
            resultLabel.text = "";<br />
            messageInput.text = "";<br />
            clear.visible = false;<br />
      }<br />
	<br />
      private function handleResult( event : Object ) : void<br />
      {<br />
            //resultLabel.text =  "" + event.result ;<br />
            resultLabel.text =  event.result as String ;		<br />
      }<br />
	<br />
      private function handleFault( event : Object ) : void<br />
      {<br />
            Alert.show( event.fault.faultCode + "\n" + event.fault.faultString, "fault" );<br />
      }<br />
			<br />
      ]]&gt;	&lt;/mx:Script&gt;<br />
	</p>

<p>&lt;/mx:Application&gt;<br />
</pre></p>

<p><br />
Right click on EchoView.mxml and select run as &gt; Flex Application</p>

<p>Your browser should then show <a href="http://weblogs.macromedia.com/dharfleet/EchoView.cfm" onclick="window.open('http://weblogs.macromedia.com/dharfleet/EchoView.cfm','popup','width=382,height=149,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">our flex app</a> with a text input and a button, give it a try by typing something in the text field and hitting send</p>

<p>In the next guide, I will give you a quick overview of the flex code which calls the java and handles the results.</p>]]>
</content>
</entry>
<entry>
<title>Java Development in Flex Builder</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/07/java_developmen.cfm" />
<modified>2007-01-22T09:48:24Z</modified>
<issued>2006-07-13T12:07:53Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11413</id>
<created>2006-07-13T12:07:53Z</created>
<summary type="text/plain">This coffee break guide will show you how to set up Eclipse to be able to code java inside a flex data services project working with JBoss....</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>This coffee break guide will show you how to set up Eclipse to be able to code java inside a flex data services project working with JBoss.</p>]]>
<![CDATA[<p>First of all you need to create a new project in Eclipse New>Flex>FlexProject</p>

<p>Choose to create a Flex Data Services project and compile the application on the server</p>

<p>Change the root folder to be: [jboss root]/server/default/deploy/fdsweb.war</p>

<p>Point the root URL to where you expect the fdsweb.war web app to be, my app is at http://localhost:8080/fdsweb</p>

<p>I called the project FDSWeb, make sure you untick the 'use default location' and change it to point to the fdsweb.war file under deploy in jboss</p>

<p>Don't do anything with the build path yet, just create the project and switch to the Flex Perspective.</p>

<p>You should be presented with the file FDSWeb.mxml in the editor, just add a label in for us to read when we test our configuration:   </p>

<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"&gt;
   &lt;mx:Label text="Hello World" /&gt;
&lt;/mx:Application&gt;
</pre>

<p>make sure JBoss is running and then right click on the file in the navigator and select <a href="http://weblogs.macromedia.com/dharfleet/RunAsFlexApplication.cfm" onclick="window.open('http://weblogs.macromedia.com/dharfleet/RunAsFlexApplication.cfm','popup','width=499,height=520,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">run as Flex Application</a>. </p>

<p>Now I expect that you want to try and add some java into the project, but you will notice if you try and create a java source folder that Eclipse will not let you, so you need to add the following to your .project file:</p>

<p>Under build specs you need to add:<br />
<pre><br />
&lt;buildCommand&gt;<br />
   &lt;name&gt;org.eclipse.jdt.core.javabuilder&lt;/name&gt;<br />
   &lt;arguments&gt;<br />
   &lt;/arguments&gt;<br />
&lt;/buildCommand&gt;<br />
</pre><br />
and under natures, you need to add:<br />
<pre><br />
&lt;nature&gt;org.eclipse.jdt.core.javanature&lt;/nature&gt;<br />
</pre><br />
You can now create a java class to integrate with. We will create a simple Echo service which just sends back a message with the time received on the server, this will give you full end to end 'RPC'.</p>

<p>Create a java source folder, for example src, create a package called fdsweb and a class called EchoService inside that package.<br />
<pre><br />
package fdsweb;</p>

<p>import java.text.DateFormat;<br />
import java.text.SimpleDateFormat;<br />
import java.util.Date;</p>

<p>public class EchoService<br />
{</p>

<p><br />
	public String echo( String inputMessage ) throws Exception<br />
	{</p>

<p>		StringBuffer result = new StringBuffer();<br />
		result.append("EchoService received ");<br />
		result.append(inputMessage);<br />
		result.append(" at ");<br />
		result.append(dateFormat.format(new Date()));<br />
		return result.toString();<br />
	}</p>

<p>	private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");</p>

<p><br />
}<br />
</pre></p>

<p>You will notice you get an error indicating that type java.lang.Object cannot be found (doesn't sound good ;-) ). However, this is just because you need to add the java libraries to your project.</p>

<p>project>properties>java build path&gt;Libraries&gt;<a href="http://weblogs.macromedia.com/dharfleet/JavaBuildPath.cfm" onclick="window.open('http://weblogs.macromedia.com/dharfleet/JavaBuildPath.cfm','popup','width=690,height=557,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false">add library</a>&gt;JRE System Library, also change your default output folder from bin to /FDSWeb/WEB-INF/classes in the project, click ok, etc.</p>

<p>Your java should now of compiled.</p>

<p>Ok, so we can now develop java and flex in the same project, at Adobe Consulting we do not tend to setup projects this way, we use the <a href="http://www.eclipse.org/webtools/">Web Tools</a> plugin for Eclipse, plug into our source control repository, etc. However, this approach is good enough to allow you to start playing with flex and java integration. In the next post I will show how to integrate our flex code and our java code. Cold coffee again ? Maybe you should switch to <a href="http://en.wikipedia.org/wiki/Frappuccino">frappaccinos</a> !</p>]]>
</content>
</entry>
<entry>
<title>Installing Flex Data Services on JBoss</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/07/installing_flex.cfm" />
<modified>2007-01-22T09:44:13Z</modified>
<issued>2006-07-12T08:23:37Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11412</id>
<created>2006-07-12T08:23:37Z</created>
<summary type="text/plain">The aim with this coffee break guide is to get you up and running with Flex Data Services and Flex Builder / Eclipse using JBoss as your app server....</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>The aim with this coffee break guide is to get you up and running with Flex Data Services and Flex Builder / Eclipse using JBoss as your app server.</p>]]>
<![CDATA[<p>You will need to <a href="http://www.adobe.com/cfusion/tdrc/index.cfm?product=flex">download</a> and install Flex Builder, FDS and JBoss with Tomcat embedded (I am currently using 4.0.3 SP1). I assume you can figure out these installs on your own. Once you have these installed, you need to copy the following files:</p>

<p><br />
[fds install]/resources/security/tomcat/flex-tomcat-common.jar<br />
[fds install]/resources/security/tomcat/flex-tomcat-server.jar</p>

<p>into</p>

<p>[jboss root]/server/default/lib</p>

<p><br />
Download the correct Xalan jars as described in "XPath Issues with JBoss 4.0.3 SP1", here http://www.adobe.com/support/documentation/en/flex/2/install.html#jboss</p>

<p><br />
copy [fds install]/flex.war to a temporary directory and rename it fdsweb.war</p>

<p>insert into the WAR at fdsweb.war/WEB-INF/lib the Xalan jars. I have:</p>

<p><br />
xalan.jar<br />
xercesImpl.jar<br />
xml-apis.jar</p>

<p>expand the war under the [jboss root]/server/default/deploy directory, calling the directory fdsweb.war</p>

<p>Start JBoss and go to: http://localhost:8080/fdsweb/</p>

<p>you should now see "Welcome to Adobe Flex Data Services 2! This is an empty .... "</p>

<p>In my next Coffee Break Guide, I will show you how to set up a very simple 'RPC' call between flex and java. Go drink your cold coffee !</p>

<p></p>

<p><a href="http://www.adobe.com/support/documentation/en/flex/2/install.html#jboss">JBoss Installation</a><br />
<a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=403UpgradeIssues">JBoss XPath Issues</a><br />
<a href="http://labs.jboss.com/portal/jbossas/download">JBoss Download</a><br />
<a href="http://www.adobe.com/cfusion/tdrc/index.cfm?product=flex">Flex Data Services Download</a></p>]]>
</content>
</entry>
<entry>
<title>Coffee Break Guides</title>
<link rel="alternate" type="text/html" href="http://weblogs.macromedia.com/dharfleet/archives/2006/07/coffee_break_gu.cfm" />
<modified>2006-07-11T17:52:18Z</modified>
<issued>2006-07-11T17:15:15Z</issued>
<id>tag:weblogs.macromedia.com,2006:/dharfleet//61.11410</id>
<created>2006-07-11T17:15:15Z</created>
<summary type="text/plain">As professional software engineers, we of course all read the manuals and white papers thoroughly before we attempt to cut a line of code. However, often we just don&apos;t have the time to do this, particularly when the technology is...</summary>
<author>
<name>dharfleet</name>

<email>dharflee@adobe.com</email>
</author>
<dc:subject>Coffee Break Guides</dc:subject>
<content type="text/html" mode="escaped" xml:lang="en" xml:base="http://weblogs.macromedia.com/dharfleet/">
<![CDATA[<p>As professional software engineers, we of course all read the manuals and white papers thoroughly before we attempt to cut a line of code. However, often we just don't have the time to do this, particularly when the technology is not what our organisation is currently investing in. My intention is that now and again I will post a 'coffee break guide', that will allow you to dive in at the deep end and explore Flex. These guides are really aimed at java developers, so they make assumptions that you know java and can install JBoss.</p>]]>
<![CDATA[<p>Having said that if you want to follow up on things, then there is a huge array[] of useful whitepapers, articles, tutorials, etc <a href="http://www.adobe.com/devnet/flex/">here</a>.</p>]]>
</content>
</entry>

</feed>