<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Peanut Butter Thoughts</title>
	
	<link>http://pbking.com/blog</link>
	<description>Thoughts of a Flash Geek</description>
	<lastBuildDate>Tue, 25 May 2010 18:12:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ThePeanutButterThoughts" /><feedburner:info uri="thepeanutbutterthoughts" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Grails Post Complete</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/M7fuZbi-3Kg/</link>
		<comments>http://pbking.com/blog/?p=260#comments</comments>
		<pubDate>Tue, 25 May 2010 18:12:10 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[uncategorized]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=260</guid>
		<description><![CDATA[I started to do a bunch of writing about Grails and Blaze and the like. Then life got in the way. I had a lot planned but I just had too much work going on to complete the posts. I&#8217;m sorry that I left any of you hanging. Fortunately somebody else has realized the awesome [...]]]></description>
			<content:encoded><![CDATA[<p>I started to do a bunch of writing about Grails and Blaze and the like.  Then life got in the way.  I had a lot planned but I just had too much work going on to complete the posts.  I&#8217;m sorry that I left any of you hanging.</p>
<p>Fortunately somebody else has realized the awesome power the stack has and has started writing a great series on it.</p>
<p>If you are still interested in the Grails/Blaze/Flex stack then I highly reccomend you check out Sébastien Arbogast&#8217;s posts:<br />
<a href="http://sebastien-arbogast.com/2010/05/13/grailsblazedsflexiphone-full-stack-part13">Part 1</a><br />
<a href="http://sebastien-arbogast.com/2010/05/14/grailsblazedsflexiphone-full-stack-part-23">Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=260</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=260</feedburner:origLink></item>
		<item>
		<title>The Blazing Grail – Part 3</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/Nt0siQsWxgE/</link>
		<comments>http://pbking.com/blog/?p=252#comments</comments>
		<pubDate>Tue, 23 Mar 2010 18:12:26 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[blazeds]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=252</guid>
		<description><![CDATA[Now that we have a working server it&#8217;s time to lock it down! The first thing we need is the ACEGI security plugin (Spring Security). These quick-start tutorials were very helpful to get started. To install type: grails install-plugin acegi . . . grails create-auth-domains User Role Requestmap &#160;. . . grails generate-manager . . [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we have a working server it&#8217;s time to lock it down!  The first thing we need is the <a href="http://grails.org/plugin/acegi">ACEGI security plugin</a> (Spring Security).  These <a href="http://www.grails.org/AcegiSecurity+Plugin+-+Tutorials">quick-start tutorials</a> were very helpful to get started.<br />
<span id="more-252"></span><br />
To install type:</p>
<div class="dean_ch" style="white-space: nowrap;">grails install-plugin acegi<br />
. . .<br />
grails create-auth-domains User Role Requestmap<br />
&nbsp;. . .<br />
grails generate-manager<br />
. . .</div>
<p>Now that it&#8217;s installed we need to lock down our services.  <a href="http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/ch04s03.html">This is a good place</a> to understand a bit about using security with spring-blaze.</p>
<p>It took me a while to realize that for this you HAVE to code to an Interface.  That&#8217;s good practice right?  For my proof-of-concept I really didn&#8217;t care about best practices so there was no interface involved.  I finally figured it out though.</p>
<p>So lets create an interface.  I guess standard Java way is for the interface to be the &#8220;ObjectName&#8221; and the implemented version &#8220;ObjectNameImpl&#8221; or some such.  Whatever.  You&#8217;ll get the idea.</p>
<p>I now have an AmfService.groovy</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">package</span> com.<span class="me1">pbking</span></p>
<p><span class="kw2">interface</span> AmfService <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getSomeString<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getSomeOtherString<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>and an AmfServiceImpl.groovy</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="kw2">package</span> com.<span class="me1">pbking</span></p>
<p><span class="kw2">class</span> AmfServiceImpl <span class="kw2">implements</span> AmfService<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">boolean</span> transactional = <span class="kw2">true</span></p>
<p>&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getSomeString<span class="br0">&#40;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="st0">&quot;Peanut Butter is Awesome&quot;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a> getSomeOtherString<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="st0">&quot;Peanut Butter and Banana Sandwiches are the Best!&quot;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Wait . . . where did my annotations go?!  Well so far I haven&#8217;t been able to get security to work with annotations; interfaces or no.  Likely it&#8217;s just something I&#8217;m doing wrong; if you have a working example I would love to see it.  But I DID get XML configuration working so that&#8217;s what I&#8217;m showing here.</p>
<p>The next step is to define the login command in the /project/web-app/WEB-INF/flex/services-config.xml that was created in the previous post.  If you copied my XML then it should already be displayed.  If you&#8217;ve got the XML generated by the blazeds plugin then you need to modify this file so that the security node looks like this:</p>
<div class="dean_ch" style="white-space: nowrap;">
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;login-command</span> <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.security.TomcatLoginCommand&quot;</span> <span class="re0">server</span>=<span class="st0">&quot;Tomcat&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>The next change is to the flex-servlet.xml; this is where the bulk of the work is.  You&#8217;ll have to add a few things:</p>
<div class="dean_ch" style="white-space: nowrap;">
Add the security namespace to the root node:<br />
xmlns:security=&quot;http://www.springframework.org/schema/security&quot;</p>
<p>add the security schema locations:<br />
http://www.springframework.org/schema/security<br />
http://www.springframework.org/schema/security/spring-security-2.0.4.xsd</p>
<p>entry-point and bean nodes:<br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:http</span> <span class="re0">entry-point-ref</span>=<span class="st0">&quot;preAuthenticatedEntryPoint&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&quot;preAuthenticatedEntryPoint&quot;</span><br />
<span class="re0">class</span>=<span class="st0">&quot;org.springframework.security.ui.preauth.PreAuthenticatedProcessingFilterEntryPoint&quot;</span><span class="re2">/&gt;</span></span></p>
<p>some sample users:<br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:authentication-provider<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:user-service<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:user</span> <span class="re0">name</span>=<span class="st0">&quot;admin&quot;</span> <span class="re0">password</span>=<span class="st0">&quot;admin&quot;</span> <span class="re0">authorities</span>=<span class="st0">&quot;ROLE_USER, ROLE_ADMIN&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:user</span> <span class="re0">name</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">password</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">authorities</span>=<span class="st0">&quot;ROLE_USER&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security:user-service<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security:authentication-provider<span class="re2">&gt;</span></span></span></p>
<p>enable annotations (in case I figure out how to make it work):<br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:global-method-security</span> <span class="re0">secured-annotations</span>=<span class="st0">&quot;enabled&quot;</span> jsr250<span class="re0">-annotations</span>=<span class="st0">&quot;enabled&quot;</span><span class="re2">/&gt;</span></span></p>
<p>and finally we will mark the message-broker as secured:<br />
&nbsp; <span class="sc3"><span class="re1">&lt;flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flex:secured</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>If you want to just lock down the whole AMF channel and be done with it then you can do this:</p>
<div class="dean_ch" style="white-space: nowrap;">
&nbsp; <span class="sc3"><span class="re1">&lt;flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flex:secured-channel</span> <span class="re0">channel</span>=<span class="st0">&quot;my-amf&quot;</span> <span class="re0">access</span>=<span class="st0">&quot;ROLE_USER&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>Lastly I comment out the context nodes and add a bean node to represent the service class.  In that node I mark which methods need to be secured:</p>
<div class="dean_ch" style="white-space: nowrap;">
&nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&quot;amfService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;com.pbking.AmfServiceImpl&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flex:remoting-destination</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:intercept-methods<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:protect</span> <span class="re0">method</span>=<span class="st0">&quot;getSomeString&quot;</span> <span class="re0">access</span>=<span class="st0">&quot;ROLE_ADMIN&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security:intercept-methods<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211;<br />
&nbsp; &lt;context:annotation-config /&gt;</span><br />
</span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;context:component-scan</span> <span class="re0">base-package</span>=<span class="st0">&quot;com.pbking&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &#8211;&gt;<br />
&nbsp;</div>
<p>So with all of these changes my flex-servlet.xml looks like this:</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;beans</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.springframework.org/schema/beans&quot;</span><br />
&nbsp; <span class="re0">xmlns:security</span>=<span class="st0">&quot;http://www.springframework.org/schema/security&quot;</span><br />
&nbsp; <span class="re0">xmlns:flex</span>=<span class="st0">&quot;http://www.springframework.org/schema/flex&quot;</span> <span class="re0">xmlns:xsi</span>=<span class="st0">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br />
&nbsp; <span class="re0">xmlns:context</span>=<span class="st0">&quot;http://www.springframework.org/schema/context&quot;</span><br />
&nbsp; <span class="re0">xsi:schemaLocation</span>=<span class="st0">&quot;<br />
&nbsp; &nbsp; http://www.springframework.org/schema/beans<br />
&nbsp; &nbsp; http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<br />
&nbsp; &nbsp; http://www.springframework.org/schema/security<br />
&nbsp; &nbsp; http://www.springframework.org/schema/security/spring-security-2.0.4.xsd<br />
&nbsp; &nbsp; http://www.springframework.org/schema/flex<br />
&nbsp; &nbsp; http://www.springframework.org/schema/flex/spring-flex-1.0.xsd<br />
&nbsp; &nbsp; http://www.springframework.org/schema/context<br />
&nbsp; &nbsp; http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;</span><span class="re2">&gt;</span></span></p>
<p>&nbsp; <span class="sc3"><span class="re1">&lt;security:http</span> <span class="re0">entry-point-ref</span>=<span class="st0">&quot;preAuthenticatedEntryPoint&quot;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&quot;preAuthenticatedEntryPoint&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">class</span>=<span class="st0">&quot;org.springframework.security.ui.preauth.PreAuthenticatedProcessingFilterEntryPoint&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;security:authentication-provider<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:user-service<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:user</span> <span class="re0">name</span>=<span class="st0">&quot;admin&quot;</span> <span class="re0">password</span>=<span class="st0">&quot;admin&quot;</span> <span class="re0">authorities</span>=<span class="st0">&quot;ROLE_USER, ROLE_ADMIN&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:user</span> <span class="re0">name</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">password</span>=<span class="st0">&quot;user&quot;</span> <span class="re0">authorities</span>=<span class="st0">&quot;ROLE_USER&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security:user-service<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/security:authentication-provider<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; <span class="sc3"><span class="re1">&lt;security:global-method-security</span> <span class="re0">secured-annotations</span>=<span class="st0">&quot;enabled&quot;</span> jsr250<span class="re0">-annotations</span>=<span class="st0">&quot;enabled&quot;</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; <span class="sc3"><span class="re1">&lt;flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flex:secured</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&quot;amfService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;com.pbking.AmfServiceImpl&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flex:remoting-destination</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:intercept-methods<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security:protect</span> <span class="re0">method</span>=<span class="st0">&quot;getSomeString&quot;</span> <span class="re0">access</span>=<span class="st0">&quot;ROLE_ADMIN&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security:intercept-methods<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211;<br />
&nbsp; &lt;context:annotation-config /&gt;</span><br />
</span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;context:component-scan</span> <span class="re0">base-package</span>=<span class="st0">&quot;com.pbking&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &#8211;&gt;</p>
<p><span class="sc3"><span class="re1">&lt;/beans<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>And that&#8217;s it!  Your services are locked down!  I&#8217;ve updated my super-simple flex app to demonstrate that they are.  There is a button to call getSomeString (a secured method) getSomeOtherString (a wide open method) and another to login as admin (so that you can successfully call getSomeString).</p>
<p>That app now looks like this:</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;s:Application</span> <span class="re0">xmlns:fx</span>=<span class="st0">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">xmlns:s</span>=<span class="st0">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">xmlns:mx</span>=<span class="st0">&quot;library://ns.adobe.com/flex/halo&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;fx:Declarations<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;s:RemoteObject</span> <span class="re0">id</span>=<span class="st0">&quot;ro&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">endpoint</span>=<span class="st0">&quot;http://localhost:8080/blazing-ahead/messagebroker/amf&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">destination</span>=<span class="st0">&quot;amfService&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">fault</span>=<span class="st0">&quot;resultLabel.text = event.fault.faultString;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">result</span>=<span class="st0">&quot;resultLabel.text = event.result.toString();&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/fx:Declarations<span class="re2">&gt;</span></span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;s:VGroup<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">label</span>=<span class="st0">&quot;login&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;ro.channelSet.login(&#8216;admin&#8217;, &#8216;admin&#8217;);&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">label</span>=<span class="st0">&quot;getSomeString&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;ro.getSomeString();&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">label</span>=<span class="st0">&quot;getSomeOtherString&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;ro.getSomeOtherString();&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Label</span> <span class="re0">id</span>=<span class="st0">&quot;resultLabel&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/s:VGroup<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
<span class="sc3"><span class="re1">&lt;/s:Application<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>With that you should be able to fire up your server (grails run-app) and hit it with the Flex app to see the restrictions.</p>
<p>Hope that helps you out!</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=252</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=252</feedburner:origLink></item>
		<item>
		<title>The Blazing Grail – Part 2</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/blSemsebXHs/</link>
		<comments>http://pbking.com/blog/?p=238#comments</comments>
		<pubDate>Tue, 23 Mar 2010 05:07:51 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[blazeds]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=238</guid>
		<description><![CDATA[Hopefully you read the &#8220;into&#8221; to this short series.  If not go ahead.  I&#8217;ll wait . . . Ok, so to begin at the beginning, let&#8217;s create a new Grails project.  (I&#8217;m assuming you&#8217;re at least a little familiar with Grails.  If not then read the Quick Start article; that should be enough to get [...]]]></description>
			<content:encoded><![CDATA[<p>Hopefully you read the &#8220;into&#8221; to this short series.  If not <a href="http://pbking.com/blog/?p=233">go ahead</a>.  I&#8217;ll wait . . .</p>
<p>Ok, so to begin at the beginning, let&#8217;s create a new Grails project.  (I&#8217;m assuming you&#8217;re at least a little familiar with Grails.  If not then read the <a href="http://www.grails.org/Quick+Start">Quick Start article</a>; that should be enough to get you started.)</p>
<div class="dean_ch" style="white-space: nowrap;">grails create-app blazing-ahead</div>
<p>If you&#8217;re an Eclipse user (like me) then you can import this project right into Eclipse.  The <a href="http://groovy.codehaus.org/Eclipse+Plugin">groovy plugin</a> would probably be helpful and I&#8217;ve been pointed to the <a href="http://www.springsource.com/products/sts">SpringSource Tool Suite </a>(with the <a href="http://www.grails.org/STS+Integration">Grails extension</a>) as a good tool to use (it&#8217;s what I&#8217;m currently using).  <a href="http://www.flos-freeware.ch/notepad2.html">Notepad2</a> is working pretty well for me right now too though.</p>
<p>From here you could either use<a href="http://grails.org/plugin/blazeds"> Sébastien&#8217;s plugin</a> which will install a nightly snapshot of BlazeDS4 and Spring-Blaze.</p>
<div class="dean_ch" style="white-space: nowrap;">grails install-plugin blazeds</div>
<p><span id="more-238"></span><br />
This is what I suggest doing.  If you do you can <a href="#alltogether">skip</a> the next little bit where I explain how to do it by hand.  </p>
<p>If you&#8217;re familiar with setting up these libraries then this is probably redundant.  I wasn&#8217;t (I&#8217;m not a server guy remember) so I had to figure it out on my own. (<a href="http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/">This is a good read</a> to help you along).  Keep in mind that everything that follows can be accomplished by typing the above command (except you can&#8217;t pick the version of the libs that you use) so the only reason I would say to do it is to know what happens behind the scenes or to use Blaze 3 instead of 4.</p>
<p>First you&#8217;ve got to get the BlazeDS jars and drop them in your /project/libs folder.  I just downloaded the <a href="http://opensource.adobe.com/wiki/display/blazeds/Release+Builds">latest binary distro</a>, unzipped the .war and grabbed all of the included JARs and dropped them in.</p>
<p>Then I grabbed the latest release of spring-flex and likewise unpackaged it and dropped the included .jar in my libs folder.</p>
<p>Next you have to modify the web.xml file to get things setup.  But wait . . . there isn&#8217;t a web.xml file anywhere!  What to do . . .</p>
<div class="dean_ch" style="white-space: nowrap;">grails install-templates</div>
<p>That will create a /templates folder in your /project/src folder.  Inside of that you&#8217;ll find /war/web.xml which you can edit.  Grails takes this file and modifies it to create the web.xml file that actually get&#8217;s deployed.</p>
<p>To that you will need to add:</p>
<div class="dean_ch" style="white-space: nowrap;">
&#8230;<br />
<span class="sc3"><span class="re1">&lt;listener<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;listener-class<span class="re2">&gt;</span></span></span>flex.messaging.HttpFlexSession<span class="sc3"><span class="re1">&lt;/listener-class<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/listener<span class="re2">&gt;</span></span></span><br />
&#8230;<br />
<span class="sc3"><span class="re1">&lt;servlet<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;servlet-name<span class="re2">&gt;</span></span></span>flex<span class="sc3"><span class="re1">&lt;/servlet-name<span class="re2">&gt;</span></span></span> <br />
&nbsp; <span class="sc3"><span class="re1">&lt;display-name<span class="re2">&gt;</span></span></span>Spring-Flex Dispatcher Servlet<span class="sc3"><span class="re1">&lt;/display-name<span class="re2">&gt;</span></span></span> <br />
&nbsp; <span class="sc3"><span class="re1">&lt;servlet-class<span class="re2">&gt;</span></span></span>org.springframework.web.servlet.DispatcherServlet<span class="sc3"><span class="re1">&lt;/servlet-class<span class="re2">&gt;</span></span></span> <br />
&nbsp; <span class="sc3"><span class="re1">&lt;load-on-startup<span class="re2">&gt;</span></span></span>1<span class="sc3"><span class="re1">&lt;/load-on-startup<span class="re2">&gt;</span></span></span> <br />
<span class="sc3"><span class="re1">&lt;/servlet<span class="re2">&gt;</span></span></span><br />
&#8230;<br />
<span class="sc3"><span class="re1">&lt;servlet-mapping<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;servlet-name<span class="re2">&gt;</span></span></span>flex<span class="sc3"><span class="re1">&lt;/servlet-name<span class="re2">&gt;</span></span></span> <br />
&nbsp; <span class="sc3"><span class="re1">&lt;url-pattern<span class="re2">&gt;</span></span></span>/messagebroker/*<span class="sc3"><span class="re1">&lt;/url-pattern<span class="re2">&gt;</span></span></span> <br />
<span class="sc3"><span class="re1">&lt;/servlet-mapping<span class="re2">&gt;</span></span></span><br />
&#8230;<br />
&nbsp;</div>
<p>Next, to your project/web-app/WEB-INF/ folder add a flex-servlet.xml</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;beans</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.springframework.org/schema/beans&quot;</span><br />
&nbsp; <span class="re0">xmlns:flex</span>=<span class="st0">&quot;http://www.springframework.org/schema/flex&quot;</span> <br />
&nbsp; <span class="re0">xmlns:xsi</span>=<span class="st0">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br />
&nbsp; <span class="re0">xmlns:context</span>=<span class="st0">&quot;http://www.springframework.org/schema/context&quot;</span><br />
&nbsp; <span class="re0">xsi:schemaLocation</span>=<span class="st0">&quot;<br />
&nbsp; &nbsp; http://www.springframework.org/schema/beans<br />
&nbsp; &nbsp; http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<br />
&nbsp; &nbsp; http://www.springframework.org/schema/flex<br />
&nbsp; &nbsp; http://www.springframework.org/schema/flex/spring-flex-1.0.xsd<br />
&nbsp; &nbsp; http://www.springframework.org/schema/context<br />
&nbsp; &nbsp; http://www.springframework.org/schema/context/spring-context-3.0.xsd&quot;</span><span class="re2">&gt;</span></span></p>
<p>&nbsp; <span class="sc3"><span class="re1">&lt;flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;flex:remoting-service</span> <span class="re0">default-channels</span>=<span class="st0">&quot;my-amf&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/flex:message-broker<span class="re2">&gt;</span></span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;context:annotation-config</span> <span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;context:component-scan</span> <span class="re0">base-package</span>=<span class="st0">&quot;&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp;&nbsp;<br />
<span class="sc3"><span class="re1">&lt;/beans<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>Lastly create the folder /project/web-app/WEB-INF/flex and drop in a services-config.xml file that looks like this:</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;services-config<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;services</span><span class="re2">/&gt;</span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;security<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;login-command</span> <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.security.TomcatLoginCommand&quot;</span> <span class="re0">server</span>=<span class="st0">&quot;Tomcat&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/security<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;channels<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;channel-definition</span> <span class="re0">id</span>=<span class="st0">&quot;my-amf&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;mx.messaging.channels.AMFChannel&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;endpoint</span> <span class="re0">url</span>=<span class="st0">&quot;http://{server.name}:{server.port}/{context.root}/messagebroker/amf&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.endpoints.AMFEndpoint&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/channel-definition<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/channels<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;logging<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;target</span> <span class="re0">class</span>=<span class="st0">&quot;flex.messaging.log.ConsoleTarget&quot;</span> <span class="re0">level</span>=<span class="st0">&quot;Info&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;properties<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;prefix<span class="re2">&gt;</span></span></span>[BlazeDS] <span class="sc3"><span class="re1">&lt;/prefix<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;includeDate<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/includeDate<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;includeTime<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/includeTime<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;includeLevel<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/includeLevel<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;includeCategory<span class="re2">&gt;</span></span></span>false<span class="sc3"><span class="re1">&lt;/includeCategory<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/properties<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;filters<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;pattern<span class="re2">&gt;</span></span></span>Endpoint.*<span class="sc3"><span class="re1">&lt;/pattern<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;pattern<span class="re2">&gt;</span></span></span>Service.*<span class="sc3"><span class="re1">&lt;/pattern<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;pattern<span class="re2">&gt;</span></span></span>Configuration<span class="sc3"><span class="re1">&lt;/pattern<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/filters<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/logging<span class="re2">&gt;</span></span></span></p>
<p>&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;system</span><span class="re2">/&gt;</span></span></p>
<p><span class="sc3"><span class="re1">&lt;/services-config<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>And at this point you should be on par with what the plugin got you.</p>
<p><a name="alltogether"><br />
<h2>Now that we&#8217;re all together now lets move on . . .</h2>
<p></a></p>
<p>So let&#8217;s create a service that can be called.</p>
<div class="dean_ch" style="white-space: nowrap;">grails create-service com.pbking.amf</div>
<p>That will create the file /project/grails-app/services/com/pbking/AmfService.groovy  Open that file and make it look like this (or some variance):</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="kw2">package</span> com.<span class="me1">pbking</span></p>
<p><span class="co2">import org.springframework.flex.remoting.RemotingDestination;</span><br />
<span class="co2">import org.springframework.flex.remoting.RemotingInclude;</span></p>
<p>@RemotingDestination<br />
<span class="kw2">class</span> AmfService <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw4">boolean</span> transactional = <span class="kw2">true</span></p>
<p>&nbsp; &nbsp; @RemotingInclude<br />
&nbsp; &nbsp; def getSomeString<span class="br0">&#40;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="st0">&quot;Peanut Butter is Awesome&quot;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>You also have to change the /project/web-app/WEB-INF/flex-servlet.xml file to have this:</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;context:component-scan</span> <span class="re0">base-package</span>=<span class="st0">&quot;com.pbking&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp;</div>
<p>If you wanted to use XML configuration instead of annotations you could drop the @stuff in the service, get rid of the two context: nodes and instead do this in the flex-servlet.xml file:</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;bean</span> <span class="re0">id</span>=<span class="st0">&quot;amfService&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;com.pbking.AmfService&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;flex:remoting-destination</span><span class="re2">/&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;/bean<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>And . . . that&#8217;s it!  Your server is ready to connect to with your Flex client!  just type
<div class="dean_ch" style="white-space: nowrap;">grails run-app</div>
<p> to get your server fired up.  If you are using the plugin and plan to use FlashBuilder 4&#8242;s data connection plugin then you&#8217;ll have to use
<div class="dean_ch" style="white-space: nowrap;">grails run-war</div>
<p> instead.  It&#8217;s not quite ready for this so I don&#8217;t use it yet.</p>
<p>Now you just need a Flex client to do some communicatin&#8217;.  There are a dozen ways to get this connection made and I&#8217;m not about to discuss the pros and cons of each here.  I have my favorite and if you ever hire me you&#8217;ll find out what that is. ;)  But below is about the SIMPLEST Flex4 application that will do the deed.</p>
<div class="dean_ch" style="white-space: nowrap;">
<span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;s:Application</span> <span class="re0">xmlns:fx</span>=<span class="st0">&quot;http://ns.adobe.com/mxml/2009&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">xmlns:s</span>=<span class="st0">&quot;library://ns.adobe.com/flex/spark&quot;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">xmlns:mx</span>=<span class="st0">&quot;library://ns.adobe.com/flex/halo&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;fx:Declarations<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;s:RemoteObject</span> <span class="re0">id</span>=<span class="st0">&quot;ro&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">endpoint</span>=<span class="st0">&quot;http://localhost:8080/blazing-ahead-plugin/messagebroker/amf&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">destination</span>=<span class="st0">&quot;amfService&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">result</span>=<span class="st0">&quot;resultLabel.text = event.result.toString();&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/fx:Declarations<span class="re2">&gt;</span></span></span><br />
&nbsp; <br />
&nbsp; <span class="sc3"><span class="re1">&lt;s:VGroup<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Button</span> <span class="re0">label</span>=<span class="st0">&quot;call&quot;</span> <span class="re0">click</span>=<span class="st0">&quot;ro.getSomeString();&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Label</span> <span class="re0">id</span>=<span class="st0">&quot;resultLabel&quot;</span> <span class="re2">/&gt;</span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;/s:VGroup<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
<span class="sc3"><span class="re1">&lt;/s:Application<span class="re2">&gt;</span></span></span><br />
&nbsp;</div>
<p>And that, my friends, is that.  Make go forth and make some kick-ass Grails backends for your Flex applications.</p>
<p>Here are a couple of <a href='http://pbking.com/blog/wp-content/uploads/2010/03/assets.zip'>assets</a> that might save you a bit of typing (or copy-pasting as the case may be).</p>
<p>In the next post I&#8217;ll talk about where I spent most of my time  . . integrating Spring Security!</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=238</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=238</feedburner:origLink></item>
		<item>
		<title>The Blazing Grail – Part 1</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/NxdfZf_tu-Q/</link>
		<comments>http://pbking.com/blog/?p=233#comments</comments>
		<pubDate>Tue, 23 Mar 2010 03:23:46 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[blazeds]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=233</guid>
		<description><![CDATA[I&#8217;m not a server guy.  I know just enough Java to get into trouble.  I&#8217;ve paid bills writing PHP but I&#8217;ve never really felt &#8220;comfortable&#8221; with how things turned out; they worked and the client was happy so I got paid.  But I often have to have things happen &#8220;back there&#8221;.  I think rich clients [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-235" href="http://pbking.com/blog/?attachment_id=235"><img class="alignleft size-thumbnail wp-image-235" title="my blazing grail" src="http://pbking.com/blog/wp-content/uploads/2010/03/HolyGrail051_qjpreviewth-150x150.jpg" alt="" width="150" height="150" /></a>I&#8217;m not a server guy.  I know just enough Java to get into trouble.  I&#8217;ve paid bills writing PHP but I&#8217;ve never really felt &#8220;comfortable&#8221; with how things turned out; they worked and the client was happy so I got paid.  But I often have to have things happen &#8220;back there&#8221;.  I think rich clients are great; it makes sense to me (as a Rich Client Developer) to keep the logic where it happens.  But sometimes that means that that happens up there on the server and I don&#8217;t always have a JavaMan handy to take care of it for me.</p>
<p>A short time ago a friend of mine (<a href="http://www.gotoandstop.org/?p=109">Ron Haberle</a>) introduced me to <a href="http://grails.org/">Grails</a>.  And for me it sure is the holy grail.  &#8221;Convention over Configuration&#8221; makes sense to me (when, that is, I don&#8217;t have to BEAT the convention configuration into submission like using <a href="http://pbking.com/blog/?p=40">Maven with Flex projects</a>).  But for writing the simple server side logic that I&#8217;ve got to write, Grails is awesome.</p>
<p><span id="more-233"></span>Since what I do is Flash it made sense to me to get Grails setup with some kind of AMF transport.  XML worked for me out of the box but what I really wanted was AMF and some of the other niceties that those technologies offer.  The options I found readily available were the <a href="http://grails.org/plugin/flex">flex plugin</a> (originally introduced to me when I was introduced to Grails) the <a href="http://grails.org/plugin/gdsflex">GraniteDS plugin</a> and <a href="http://grails.org/plugin/flex-scaffold">Grails Flex Scaffold plugin</a>.</p>
<p>The GraniteDS plugin seemed really great.  It&#8217;s just that . . . I don&#8217;t use GraniteDS.  I&#8217;m sure it&#8217;s great technology, it&#8217;s just that I have gotten familiar with BlazeDS and until there is something that I can&#8217;t do with BlazeDS that I can do with another technology I&#8217;m just not eager to spend time learning it.  It seems solid and I tried very hard to get it to work but it just didn&#8217;t work out.</p>
<p>And the flex plugin was more of a &#8220;look what I can do!&#8221; than an actual plugin.  It was also missing an important piece: Spring-Blaze integration.  Since Grails is so Spring-driven it really makes sense to get the Blaze install as &#8220;springy&#8221; as possible.</p>
<p>The Grails Flex Scaffold plugin was definitely interesting.  But I didn&#8217;t like that it (like the others actually) expected that the Flex bits were going to live in the Groovy project.</p>
<p>Eventually I discovered a series of great posts by <a href="http://sebastien-arbogast.com">Sébastien Arbogast</a> that <a href="http://sebastien-arbogast.com/2010/01/28/grails-blazeds-4-integration-plugin/">culminated in the creation</a> of his own <a href="http://grails.org/plugin/blazeds">plugin for BlazeDS4</a>.  That helped me to understand what had to happen to get everything to work together.  It had a fresh (perhaps a bit too fresh?) version of Blaze, Spring-Flex and it was just a step away from nicely integrating Spring Security.  Another thing I liked about his approach was that his Flex project would NOT be a part of the Grails project.  That&#8217;s just not how I roll.  My Flex project is my Flex project.  My Server project is my server project.  They get together for drinks but they&#8217;re just friends; they don&#8217;t sleep together.</p>
<p>I actually ended up not using any plugins.  Nightly builds are great to play with but I actually need to build a server that&#8217;s a LITTLE more stable.  I decided to use the latest version of Blaze and Spring-Blaze library.  With a little tiny bit of customization and configuration (you can&#8217;t avoid it completely) I was also able to get Spring Security to work with my services.</p>
<p>In the next few posts I&#8217;ll let you know how I did that!  I&#8217;ve got some other things I hope to try as well as I journey through this server setup and I might get a chance to talk about those too!  There are a lot of info about these topics out there but I had to bounce all over the interwebs to get all of the information I needed.  So maybe this will help somebody else out there save an evening or two and jump right into their own projects.</p>
<p><a href="http://pbking.com/blog/?p=238">Part 2 &#8211; Setting up Grails, installing Blaze/Spring-Blaze &amp; creating a Flex Project to talk to it.</a></p>
<p>Part 3 &#8211; Installing the Spring Security Plugin and locking down the services.</p>
<p>Parts 4 through n &#8211; Facebook?, Google App Engine?</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=233</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=233</feedburner:origLink></item>
		<item>
		<title>PhxFPUG Assets</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/jb1yzjj86KQ/</link>
		<comments>http://pbking.com/blog/?p=228#comments</comments>
		<pubDate>Wed, 27 Jan 2010 23:41:36 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=228</guid>
		<description><![CDATA[If you&#8217;re coming to the Phoenix Flash Platform User Group meeting tonight (and I hope you are!) or you are there now, or maybe you heard about how cool it was then these things might be helpful for you. The two tools we&#8217;ll be talking about are RobotLegs and Swiz.  Here are the links to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re coming to the Phoenix Flash Platform User Group meeting tonight (and I hope you are!) or you are there now, or maybe you heard about how cool it was then these things might be helpful for you.</p>
<p>The two tools we&#8217;ll be talking about are RobotLegs and Swiz.  Here are the links to their respective locations on the interweb.</p>
<p><a href="http://www.robotlegs.org/">http://www.robotlegs.org/</a></p>
<p><a href="http://swizframework.org/">http://swizframework.org/</a></p>
<p>If you&#8217;re playing along then you might want to download the projects I&#8217;ll be demoing.  Please keep in mind that these projects attempt to demonstrate how these tools work; NOT NECESSARILY BEST PRACTICES.  They are only meant to give you a basic understanding of the principals.</p>
<p><a href="http://pbking.com/blog/wp-content/uploads/2010/01/fpug_projects.zip">FPUG Projects</a></p>
<p>If you just want to download the .swc files (which are included in the projects as necessary) then you can grab them here.</p>
<p><a href="http://pbking.com/blog/wp-content/uploads/2010/01/robotlegs-framework-v1.0.2.swc">RobotLegs 1.0.2</a></p>
<p><a href="http://pbking.com/blog/wp-content/uploads/2010/01/swiz-0.6.4-flex3.swc">Swiz 0.6.4</a> (for Flex 3)</p>
<p><a href="http://pbking.com/blog/wp-content/uploads/2010/01/Facebook_library_v3.4_flex.swc">Facebook AS3 lib 3.4</a></p>
<p>And if you want to &#8220;borrow&#8221; my Facebook App key and secret you can use these values (they are going to get changed after tonight and it&#8217;s a sandbox app anyway so you won&#8217;t be able to do anything fun with it anyway).</p>
<p><strong>API Key</strong>: abcdefghijlkmnopqrstuvwxyz</p>
<p><strong>Secret</strong>: nowiknowmyabcsnexttimewontyousingwithme</p>
<p>Lastly, if you care to follow along with my slides you can download those here.  You probably won&#8217;t get much without me standing in front of them being awesome, but you are welcome to them if you want &#8216;em.</p>
<p><a href="http://pbking.com/blog/wp-content/uploads/2010/01/PFUG-DI-Preso.pdf">PFUG DI Preso</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=228</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=228</feedburner:origLink></item>
		<item>
		<title>Klok – This stuff shouldn’t be free</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/7H38CKxwgDM/</link>
		<comments>http://pbking.com/blog/?p=225#comments</comments>
		<pubDate>Mon, 25 Jan 2010 21:17:23 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[uncategorized]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=225</guid>
		<description><![CDATA[I recently started testing the new version of Klok.  Klok is an Air app used to track your time.  Version 1.5 has been out for quite a while and I didn&#8217;t work without it running.  I tend to jump around my projects quite a bit and I usually have to keep track of how much [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://pbking.com/blog/wp-content/uploads/2010/01/klokgrab.png"><img class="alignleft size-medium wp-image-226" title="Klok 2" src="http://pbking.com/blog/wp-content/uploads/2010/01/klokgrab-300x214.png" alt="Klok 2" width="300" height="214" /></a>I recently started testing the new version of Klok.  <a href="http://klok.mcgraphix.com/klok/index.htm">Klok</a> is an Air app used to track your time.  <a href="http://klok.mcgraphix.com/klok/downloads.html">Version 1.5</a> has been out for quite a while and I didn&#8217;t work without it running.  I tend to jump around my projects quite a bit and I usually have to keep track of how much time I spend on which tasks, etc.  Klok has always been a great tool to let me do that.  And it&#8217;s a free application!  Version 1.5 is available now and 2.0 is under active development and has made some FANTASTIC improvements.  This thing is, it SHOULDN&#8217;T be a free application.  I really think it&#8217;s that good.  I won&#8217;t go over all of the features that make it awesome cause this is a short post and I&#8217;ve got lots of actual work to do (yes, I&#8217;m logging the time I&#8217;m spending to write this blog post).  There&#8217;s lots of great time keeping apps out there and I&#8217;ve used lots of them.  This is the one I like the best.</p>
<p>Right now you can&#8217;t <a href="http://klok.mcgraphix.com/klok/betaProgram.htm">download the 2.0 beta unless you donate to the project</a>.  So ACT NOW while the application isn&#8217;t free.  It&#8217;s totally worth it.</p>
<p>Now back to the work I get paid to do . . .</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=225</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=225</feedburner:origLink></item>
		<item>
		<title>FlashVar manager using Swiz or RobotLegs</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/0yXRb2njTbo/</link>
		<comments>http://pbking.com/blog/?p=220#comments</comments>
		<pubDate>Fri, 22 Jan 2010 20:21:44 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[robotlegs]]></category>
		<category><![CDATA[swiz]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=220</guid>
		<description><![CDATA[I use FlashVars a lot. Sometimes I need to open or launch something from my application on startup. Sometimes I just need to know some authentication credentials and that&#8217;s the way they are passed to me. Something that I have found that has made this easier for me has been to create a FlashVarManager for [...]]]></description>
			<content:encoded><![CDATA[<p>I use FlashVars a lot.  Sometimes I need to open or launch something from my application on startup.  Sometimes I just need to know some authentication credentials and that&#8217;s the way they are passed to me.  Something that I have found that has made this easier for me has been to create a FlashVarManager for my projects.</p>
<p>FlashVars are gleaned from a LoaderInfo object and it is just a dynamic Object. (loaderInfo.properties to be exact).  But you probably knew that.  Being a fan of strongly typedness I usually create some getters on my manager that will fetch a specific flashVar from the .properties object and if there isn&#8217;t one give me a default.  Since I always did this for Flex projects the most straightforward way to grab what I needed was through the Application instance.  My manager would look something like this.</p>
<div class="dean_ch" style="white-space: nowrap;">package com.<span class="me1">pbking</span>.<span class="me1">demo</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw3">public</span> <span class="kw2">class</span> FlashVarManager<br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> <span class="kw2">var</span>:_instance:FlashVarManager;<br />
&nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _flashVars:<span class="kw3">Object</span>; &nbsp; &nbsp;</p>
<p>&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> getInstance<span class="br0">&#40;</span><span class="br0">&#41;</span>:FlashVarManager<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>!_instance<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; _instance = <span class="kw2">new</span> FlashVarManager<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; _flashVars = Application<span class="br0">&#40;</span>Application.<span class="me1">application</span><span class="br0">&#41;</span>.<span class="me1">loaderInfo</span>.<span class="me1">properties</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> _instance;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">get</span> flashVars<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Object</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> _flashVars;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">get</span> specificFlashVarValue<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">String</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>flashVars<span class="br0">&#91;</span><span class="st0">&#8216;specificValue&#8217;</span><span class="br0">&#93;</span> != <span class="kw3">undefined</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> flashVars<span class="br0">&#91;</span><span class="st0">&#8216;specificValue&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;someDefaultValue&quot;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>Something like that.</p>
<p>So if ever my flashVars had to change I could just change this class.  I will often perform logic in here too; sometimes create a faux &#8220;flashVar&#8221; that is based on a number of flashVars.  I find it pretty handy.</p>
<p>But I&#8217;m trying to eliminate Singletons wherever I can.  Not necessarily Singletons in the &#8220;one instance exists&#8221; sense, but more in the .getInstance() sense.  RobotLegs and Swiz are really helping me out with that.  But how to construct my FlashVarManager with those tools?  How do you get to the loaderInfo of the app (without using the messy Application() hack)?<br />
<span id="more-220"></span><br />
Pretty simple really.  Swiz will allow you to mark a controller as an IDispatcherBean.  That means that it passes in an IEventDispatcher upon which you can dispatch events into the framework&#8217;s event bus.  Well that IEventDispatcher just happens to be a DisplayObject from which you can grab the loaderInfo.  (The exact item passed in in 0.6.4 and 1.0beta are different but the execution is the same.)  Then you just have to include that puppy in your beanmap so that it can be injected wherever it&#8217;s needed.</p>
<p>That would look something like this:</p>
<div class="dean_ch" style="white-space: nowrap;">package com.<span class="me1">pbking</span>.<span class="me1">demo</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw3">public</span> <span class="kw2">class</span> FlashVarManager <span class="kw3">implements</span> IDispatcherBean<br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> <span class="kw3">_root</span>:DisplayObject;<br />
&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">set</span> dispatcher<span class="br0">&#40;</span>newVal:IDispatcher<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">_root</span>:DisplayObject = DisplayObject<span class="br0">&#40;</span>newVal<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">get</span> flashVars<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Object</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw3">_root</span>.<span class="me1">loaderInfo</span>.<span class="me1">parameters</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
. . .<br />
&nbsp;</div>
<p>Doing the same with RobotLegs is even easier.  You can have injected into an Actor the &#8220;root display&#8221; of your context.  Pull the loaderInfo out of that and rock and roll.  Just map that class into your context and Bob&#8217;s your uncle.</p>
<div class="dean_ch" style="white-space: nowrap;">package com.<span class="me1">pbking</span>.<span class="me1">demo</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw3">public</span> <span class="kw2">class</span> FlashVarManager<br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="br0">&#91;</span>Inject<span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">var</span> contextView:DisplayObjectContainer;</p>
<p>&nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">get</span> flashVars<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">Object</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> contextView.<span class="me1">loaderInfo</span>.<span class="me1">parameters</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
. . .<br />
&nbsp;</div>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=220</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=220</feedburner:origLink></item>
		<item>
		<title>Signals may spell the death to my Commands as I know them</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/ul__JCYGJsg/</link>
		<comments>http://pbking.com/blog/?p=211#comments</comments>
		<pubDate>Wed, 20 Jan 2010 04:01:28 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[robotlegs]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=211</guid>
		<description><![CDATA[Back when I wrote my Command library I was doing a lot of calling of commands.  It actually stems from the Commands/Delegates I created for the Facebook AS3 API (which have since been removed; which I think is a shame).  Essentially the greatest benefit I got from my commands with the ability to do this: [...]]]></description>
			<content:encoded><![CDATA[<p>Back when I wrote my <a href="http://code.google.com/p/pbutils/">Command library</a> I was doing a lot of calling of commands.  It actually stems from the Commands/Delegates I created for the <a href="http://code.google.com/p/facebook-actionscript-api/">Facebook AS3 API</a> (which have since been removed; which I think is a shame).  Essentially the greatest benefit I got from my commands with the ability to do this:</p>
<div class="dean_ch" style="white-space: nowrap;">commandInstance.<span class="me1">addCallback</span><span class="br0">&#40;</span>onComplete<span class="br0">&#41;</span>;<br />
<span class="kw2">function</span> onComplete<span class="br0">&#40;</span>commandInstance:CommandClass<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span> <span class="co1">// do stuff }</span><br />
&nbsp;</div>
<p>instead of this:</p>
<div class="dean_ch" style="white-space: nowrap;">commandInstance.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, onComplete<span class="br0">&#41;</span>;<br />
<span class="kw2">function</span> onComplete<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">var</span> commandInstance:CommandClass = <span class="kw3">e</span>.<span class="kw3">target</span> as CommandClass;<br />
&nbsp; commandInstance.<span class="me1">removeEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, onComplete<span class="br0">&#41;</span>;<br />
&nbsp; <span class="co1">//NOW I can do stuff</span><br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
<p>That got rid of a lot of code for me and made me very happy.</p>
<p><strong>Boss: Jason, how many lines of code did you write today?<br />
Me: (proudly) Negative two-hundred-sixty-nine!</strong></p>
<p>Just kidding.  My boss has never asked me how many lines of code I wrote.<br />
<span id="more-211"></span><br />
But the less code I have to write the more time I get to spend blogging.  Or playing Super Mario Bros Wii.  Or closing bugs.  And the easier it is to tell what the HELL is going on.  And the less likely I&#8217;ll be to forget to remove listeners.  All good stuff right?</p>
<p>Well the benefit only worked if I was extending one of my AsyncCommand classes.  Which worked pretty well since most of the stuff that I wanted to work that way was &#8220;business logic&#8221; stuff that I stuck in a command.  I would execute and wait for the result.</p>
<p>If the result was bad then I could just check the .success property and put a little logic in the callback handler.  But wouldn&#8217;t it be cool if I could do that for all KINDS of events?  And by &#8220;events&#8221; I mean &#8220;Stuff Happening&#8221; not dispatchEvent(new Event());</p>
<p>Well <a href="http://robertpenner.com/flashblog/2009/09/my-new-as3-event-system-signals.html">Robert Penner&#8217;s <strong>Signals</strong></a> is almost exactly that.  Imagine an object that has a number of things that could happen.  Probably not hard; most of you have pretty good imaginations.  For the case of my commands it could be <em>complete</em> and <em>error</em>.  That command would then have a .completeSignal object and a .errorSignal object.  These are Signal objects to which I can subscribe.  Usage would be something like this:</p>
<div class="dean_ch" style="white-space: nowrap;">asyncCommand.<span class="me1">completeSignal</span>.<span class="kw3">add</span><span class="br0">&#40;</span>completeHandler<span class="br0">&#41;</span>;<br />
asyncCommand.<span class="me1">errorSignal</span>.<span class="kw3">add</span><span class="br0">&#40;</span>errorHandler<span class="br0">&#41;</span>;<br />
&nbsp;</div>
<p>Then when the command has finished running the completeHandler is called.  And it&#8217;s not passed an event from which I have to glean what tossed the event and type it.  it&#8217;s the strongly typed command that dispatched the signal . . . just like my addCallback() method did!</p>
<p>So I&#8217;m thinking, since being able to listen for lots of things happening is better than listening for ONE thing to happen . . . well that might just spell the end to the Peanut Butter Commands.  At the very least I think I might re-factor things to use Signals instead of my own home-grown callback handling logic.  I&#8217;m just beginning to play with Signals but I&#8217;m already very pleased with how it makes my code look.</p>
<p>I&#8217;m beginning to question the idea of calling commands directly anyway.  I mean it sure is damn handy.  I hate tossing events to get stuff to happen; it just seems like a lot more code to me.  Usually, in the software I write, the ONLY thing that cares about when a command is finished is whatever called the command in the first place.    And besides I can always let people know that a command finished (via an event or a signal) right?</p>
<p>There has been some <a href="http://groups.google.com/group/robotlegs/browse_thread/thread/a0aa9204b1d2acc4">active talk</a> on the RobotLegs group about combining the powers of the Legs and Signals.  It sounds like it&#8217;s going pretty well and I&#8217;m really interested in playing with it (once I get a bit more code written that I&#8217;m paid to write).  My distaste for Events drives me to find any solution I can to get rid of them in as many places as I can.</p>
<p>By the way, nice work Robert.</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=211</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=211</feedburner:origLink></item>
		<item>
		<title>Swiz vs RobotLegs LIVE!</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/JbY6IDFAWZo/</link>
		<comments>http://pbking.com/blog/?p=209#comments</comments>
		<pubDate>Wed, 13 Jan 2010 17:46:03 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[uncategorized]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=209</guid>
		<description><![CDATA[Since I began my DI framework journey I have used these two tools a lot.  I&#8217;ve gone back and forth and back and forth over which I like better.  Strangely, it&#8217;s usually the one I&#8217;m NOT currently using that I favor.  The things I miss always stand out when I can&#8217;t use them. Well on [...]]]></description>
			<content:encoded><![CDATA[<p>Since I began my DI framework journey I have used these two tools a lot.  I&#8217;ve gone back and forth and back and forth over which I like better.  Strangely, it&#8217;s usually the one I&#8217;m NOT currently using that I favor.  The things I miss always stand out when I can&#8217;t use them.</p>
<p>Well on Wed Jan 27th I&#8217;m going to be hashing these two frameworks out live at the <a href="http://www.gotoandstop.org/?p=120">Phoenix Flash Platform User Group</a>.  For those unfamiliar with Dependency Injection frameworks I&#8217;ll go over the basics of how to get started with both Swiz and RobotLegs and how they are the same.  It will be a &#8220;lab&#8221; session and my plan is to walk everyone who is interested through the process of building a working sample.  Check back here the day of the presentation for links and resources to help us along.  It MAY help to have a Facebook account and SOME familiarity with building Facebook apps with the AS3 API.  I&#8217;m thinking of doing that as the example apps.  What do you think?</p>
<p>Then I&#8217;m going to talk about how the two frameworks are different.  I&#8217;m going to try very hard to be impartial.  I LOVE both of these frameworks.  There are a few points about them that I&#8217;m planning to go over (besides the basics of how to set them up).</p>
<ul>
<li>What is a Context and why does it make my hair look better?</li>
<li>Will Swiz 1.0 alpha make by teeth whiter than 0.6.4?</li>
<li>What if I want to process my own MetaData?  Can any of this help me?</li>
<li>I REALLY like to use PatternX instead of Pattern42 when dealing with my views.  Can I do that?</li>
<li>Commands vs Controllers on WWF SmackDown.  Who&#8217;s logic will win?</li>
<li><a href="http://groups.google.com/group/swiz-framework/browse_thread/thread/61f2a86d57b5e7a6">Does/should a 1.0 version really matter?</a> (Yes, I want to talk about this one, but probably only AFTER the meeting once the booze has started flowing).</li>
</ul>
<p>My question to you, the concerned reader is what else should I discuss?  Are there any benefits or differences that you would like to see that I point out?  Please leave your comments here (in a timely manner) and I will do my best to get the points into the presentation.  I know there are other similar frameworks out there (Parsley is actually one I like a lot too) but these are the two I use daily and am most familiar with.  They are the ones I decided to put into my toolbox so they are the ones I will talk about.</p>
<p>I will try to tape the presentation or at least make the slides available so maybe that can help others out there who want to get started.</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=209</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=209</feedburner:origLink></item>
		<item>
		<title>Swiz vs RobotLegs</title>
		<link>http://feedproxy.google.com/~r/ThePeanutButterThoughts/~3/ZY8T1bUfJuk/</link>
		<comments>http://pbking.com/blog/?p=203#comments</comments>
		<pubDate>Wed, 04 Nov 2009 09:27:44 +0000</pubDate>
		<dc:creator>Jason Crist</dc:creator>
				<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://pbking.com/blog/?p=203</guid>
		<description><![CDATA[Recently I spent some time converting a medium-sized project first to Swiz and then to RobotLegs.  The following is my take on the two frameworks and how I chose a winner.  Right now there are definitely a lot of things I like about both frameworks, and I wish I could pick and choose the features [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I spent some time converting a medium-sized project first to <a href="http://swizframework.org/">Swiz </a>and then to <a href="http://wiki.github.com/robotlegs/robotlegs-framework">RobotLegs</a>.  The following is my take on the two frameworks and how I chose a winner.  Right now there are definitely a lot of things I like about both frameworks, and I wish I could pick and choose the features I like best.  I would call it the Peanut Butter Framework Mashup Extraordinaire.</p>
<p>I have considered giving <a href="http://mate.asfusion.com/">Mate </a>and <a href="http://www.spicefactory.org/parsley/">Parsley </a>a similar go but Swiz and RobotLegs were the two that definitely interested me the most so I&#8217;ve done them first.  I&#8217;m pretty familiar with <a href="http://opensource.adobe.com/wiki/display/cairngorm/">Cairngorm </a>and don&#8217;t personally like it.  I think I&#8217;ve read and tinkered with <a href="http://puremvc.org/">PureMVC</a> enough to know that it isn&#8217;t my ball of wax either.</p>
<p>Keep in mind that I am refactoring an EXISTING project to use these frameworks.  I am not starting a project from scratch.  If I were then I might feel differently.  Maybe.</p>
<p><strong>What is important to me?</strong></p>
<p>The most important things about a development tool, be it an IDE, a library, a repository or a framework is:</p>
<ol>
<li>How quickly can it help me get the job done?</li>
<li>How quickly can it help me add new features?</li>
<li>How quickly can it help me find and squash bugs?</li>
<li>How little code can I write to get the job done?</li>
</ol>
<p>And that&#8217;s it really.  I want to write as LITTLE easily understandable code as possible and I want to be able to easily fix it and add to it.</p>
<p><em>Don&#8217;t code it &#8217;till you need it.</em></p>
<p>For me writing code is not always a task of reuseability.  If I build something for a project then it&#8217;s for THAT project.  If I see that some piece of code could be helpful elsewhere then I will take the time to make that piece a project and allot it its own time.  By carefully choosing what gets &#8220;bumped up&#8221; into reuseability land I am able to get the job done faster and with less effort.</p>
<p>With that in mind it&#8217;s important that the framework I&#8217;m using allow me to do that; write code quickly.  That isn&#8217;t to say I&#8217;ll settle for spaghetti code just because it closes the job ticket faster.  I know I&#8217;ll also be the one adding features to this puppy and fixing bugs.  So I want it to stand the test of time.  So the framework will also need to gently guide me to do that as well.</p>
<p><strong>Map Commands vs Mediate Methods</strong></p>
<p>One difference between Swiz and RobotLegs seems to be how they handle &#8220;triggered logic&#8221;.</p>
<p>Using Swiz you define instances of Controllers in your Bean Map.  In those controllers you will have a number of methods that get called when an event is fired that Swiz captures (mediates).</p>
<p>You can use events to trigger calls to methods in RobotLegs as well but only in certain siturations (Mediator classes).  It seems to instead suggest that you map Commands to Events, a technique which I was first introduced to in Cairngorm.  The WAY this happens is different than Cairngorm, but the idea is roughly the same: When X happens this Command Class is created and executed.</p>
<p>That&#8217;s actually how the project was working before the conversion (though it was using a home-rolled solution for that).</p>
<p>Now I LOVE commands.  I really like to use <a href="http://code.google.com/p/pbutils/">my own command library</a>.  I don&#8217;t always want to have to link a command up to an event.  With my library I can play with my commands from anywhere in my code.  Generally I don&#8217;t care when a command starts, finishes, etc except from where I actually called the command.  This helps me keep my code-base as small as possible; needless custom events aren&#8217;t created when only one place cares about something happening.  When I DO find that event information is helpful elsewhere then I can just dispatch some informative events from the command itself (using whatever the framework of the day is).  With this in mind any tool that lets me to easily continue working in this manner is a win for me.</p>
<p>Using RobotLegs I&#8217;m able to map an Event to a Command.  Awesome.  I can even inject some data into it.  Cool.  But the Command needs to be an ICommand.  And I couldn&#8217;t find ICommand in the library so AFAIK the commands actually have to extend robotlegs.Command.  Not cool.  I have dozens of commands already written and tied to another library.  I could just change the Commands that need to be triggered by events but that sounds like a royal pain-in-the-ass and additional work == bad thing.</p>
<p>Using Swiz I&#8217;m not able to map the commands to events.  I don&#8217;t like that.  However I CAN create and execute the commands from the Controller.  The Controller is mapped from the same BeanMask that the model objects are mapped in and it just contains a bunch of methods that get called when events fire (defined by MetaData).  That actually gives me a little more control.  I can inject the dependencies into my existing commands if I want to.  But in my project all of my commands actually have constructor parameters.  So I just inject properties into my Controller and using that and the properties on the dispatched events I handle the execution of the commands.  It&#8217;s not incredibly elegant but it gets the job done and there isn&#8217;t much code to write or change.</p>
<p><strong>Getting Events Out There</strong></p>
<p>Bubbled events are cool right?  Sure they are technically &#8220;expensive&#8221; and there are the rare cases of apps fighting each other over bubbled events that they throw at each other.  A &#8220;Bubble Fight&#8221; I call it.  Personally I&#8217;ve never witnessed one.</p>
<p>RobotLegs is very strict about NOT relying on the DisplayObject tree as a means to move event messaging back and forth (bubbling).  Swiz lets you do just that.  Bubble an event up from any attached view and any methods assigned to that event will be called.  Easy-peasy.   That&#8217;s another win for Swiz.</p>
<p><strong>Singletons are Awesome</strong></p>
<p>No their not.</p>
<p>Fortunately both frameworks allow you to more elegantly handle Singletons and actually ALL the data that exists in a project.  Using DI (<strong>D</strong>ependency <strong>I</strong>njection) you can have objects that the framework is aware of injected right into your classes.  Both use some type of MetaData to define that.  [Autowire] is Swiz&#8217;s and [Inject] is RobotLegs, but it comes down to the same thing.</p>
<p>DI allows you to do away with the classic &#8220;Singleton&#8221; pattern.  Class.getInstance() sucks.  Even when you don&#8217;t care about reuseability it still sucks.  As far as the injecting/tagging goes I can&#8217;t say that I&#8217;ve got a preference.  But for registering these items I like Swiz better.</p>
<p>In RobotLegs you have a class that kind of &#8220;kick starts&#8221; things.  One popular place to put the items to be injected is there.  I understand, however, that you can actually do this in a number of places in a number of ways.  That sounds like trouble to me.</p>
<p>In Swiz the accepted way of doing this is in an (M)XML document; the BeanMask.  This document will define all of your &#8220;model&#8221; objects.  These are the objects that can be [Autowire]d.  That seems clean to me and I like it.  You can have multiple Bean Masks if your project gets large, but at least you&#8217;ll know where to look for stuff.</p>
<p><strong>Code from Behind vs Reach Around</strong></p>
<p>I&#8217;ve got a number of views that are small.  Small enough that I just put the necessary view logic in a &lt;Script/&gt; tag.</p>
<p>Sometimes that logic will grow and grow and I&#8217;ll just pull it out into it&#8217;s own class.  Usually I just do a code-behind.  (The MXML class extends an ActionScript class which has all the logic in it.)</p>
<p>Previously I had a &#8220;Global Event Dispatcher&#8221; that my views listened to.  Methods were called when those events were dispatched from that &#8220;Global Event Dispatcher&#8221;.</p>
<p>RobotLegs doesn&#8217;t like that.  I need to have a Mediator class for my logic.  Then I need to bind that mediator class to the view.  But not actually IN the view.  Or even in the mediator (though the mediator should have a REFERENCE to the view).  The binding takes places somewhere else.  If I don&#8217;t play by those rules then I don&#8217;t get the benefit of mediated methods for my view.</p>
<p>Swiz doesn&#8217;t care.  I can just stick [Mediate] on any public view method (&lt;Script/&gt; or code-behind) and it will work just fine.  I&#8217;m not opposed to mediator classes.  I think that is a fine (and cleaner) alternative to a code behind.  But I don&#8217;t want to HAVE to do it that way.  Unfortunately, that method DOES need to be public, which I DON&#8217;T like.  I think I can get over that, but it&#8217;s essentially an event handler.  It&#8217;s not something that anyone outside of that view needs to know about.</p>
<p><strong>Services</strong></p>
<p>Ok, I honestly didn&#8217;t put either framework through the paces when it came to working with my Services.  All of my service handling is already done in a way that is already clean and I saw no need to change that at all.  This wasn&#8217;t an important part of either framework for me.</p>
<p><strong>Best Practice vs Get &#8216;er Done</strong></p>
<p>Shaun Smith had a <a href="http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/">great piece about &#8220;why RobotLegs&#8221;</a>.  And I couldn&#8217;t help but get fired up about his reasons.  They are good ones.  But they seem like good reasons on paper, not necessarily in practice.  Like I said, if I had started this project out fresh instead of trying to port it then I might feel differently.  But when I look at all the code I would have to change/add using RobotLegs that shows me that there might be a lot of code that I shouldn&#8217;t have to write.</p>
<p>When I ported everything to Swiz it took me a couple of hours and I had things rolling.  I was able to change just a portion of my application to rely on the framework.  It worked alongside what I already had.  But it took me the better part of some valueable sleepy-time to get RobotLegs working.  And even then I still had mountains of Mediators to create before the app was truly &#8220;working&#8221;.  Don&#8217;t think I&#8217;m a hater.  I DO really like what RobotLegs is all about.  But it&#8217;s just not for me; it doesn&#8217;t fit my workflow or my coding style.</p>
<p>Swiz does.</p>
<p><strong>It&#8217;s late</strong></p>
<p>If I&#8217;ve gotten anything wrong describing the usage of either of those frameworks then please correct me.  I admit that I am a total n00b at both of these.  I tried to keep it general and relatively vague; there are plenty of other resources that explain how these things actually work much better than I could.</p>
<p>Sleepy time.</p>
]]></content:encoded>
			<wfw:commentRss>http://pbking.com/blog/?feed=rss2&amp;p=203</wfw:commentRss>
		<slash:comments>14</slash:comments>
		<feedburner:origLink>http://pbking.com/blog/?p=203</feedburner:origLink></item>
	</channel>
</rss>
