<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Graversen &#187; grails</title>
	<atom:link href="http://graversen.org/tag/grails/feed/" rel="self" type="application/rss+xml" />
	<link>http://graversen.org</link>
	<description>Daniels comments</description>
	<lastBuildDate>Wed, 04 Apr 2012 09:47:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Creating Google wave robots in Grails</title>
		<link>http://graversen.org/2009/07/22/creating-google-wave-robots-in-grails/</link>
		<comments>http://graversen.org/2009/07/22/creating-google-wave-robots-in-grails/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 06:49:02 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[app-engine]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[wave]]></category>

		<guid isPermaLink="false">http://graversen.org/?p=168</guid>
		<description><![CDATA[Updated 17/11: A grails plugin for Wave have been released see MasteringWave for more information. I just got access to Google wave, where I would like to create a robot. A robot is a participant in the wave conversation and can do the same as everyone else in the wave. Wave robots can currently only [...]]]></description>
			<content:encoded><![CDATA[<p><b>Updated 17/11: A grails plugin for Wave have been released see <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.masteringwave.com%2F2009%2F11%2Fwave-robots-with-grails-plugin%2F&sref=rss">MasteringWave </a>for more information.</b></p>
<p>I just got access to <a href="http://redirectingat.com?id=10371X688478&xs=1&url=https%3A%2F%2Fwave.google.com%2F&sref=rss">Google wave</a>, where I would like to create a <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fcode.google.com%2Fapis%2Fwave%2Fextensions%2Frobots%2Findex.html&sref=rss">robot</a>. A robot is a participant in the wave conversation and can do the same as everyone else in the wave.  Wave robots can currently only be used by applications running on Google App-engine, so you need access to App-Engine. You can get this access <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fappengine.google.com%2F&sref=rss">here</a>.
</p>
<p>The application that I&#8217;m using is running grails, so it needs to fit into that application. When you read the robot functional specification, robots should extend AbstractRobotServlet. In grails Apps you have Controllers and no servlets, so this is a bit tricky. But really easy, when you find the trick.
</p>
<p>To create your app, you need to create a grails app, to be deployed in app-engine using the Grails <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.grails.org%2Fplugin%2Fapp-engine&sref=rss">app-engine plugin</a>. Follow the guide on the page and you should have an app running on app-engine.
</p>
<p>I&#8217;ll use the <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fcode.google.com%2Fapis%2Fwave%2Fextensions%2Frobots%2Fjava-tutorial.html&sref=rss">wave robot tutorial</a> as starting point for the app. The first thing you need is to <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fcode.google.com%2Fp%2Fwave-robot-java-client%2Fdownloads%2Flist&sref=rss">download</a> the following files and place them in the ./lib folder of your project.
</p>
<ul>
<li><span style="font-family:Courier New; font-size:10pt">wave-robot-api.jar</span><span style="font-family:Times New Roman; font-size:12pt"><br />
			</span></li>
<li><span style="font-family:Courier New; font-size:10pt">json.jar</span><span style="font-family:Times New Roman; font-size:12pt"><br />
			</span></li>
<li><span style="font-family:Courier New; font-size:10pt">jsonrpc.jar</span><span style="font-family:Times New Roman; font-size:12pt"><br />
			</span></li>
</ul>
<p>The you need to create a capabilities.xml file. This is a configuration file, telling wave what your app responds to.  capabilities.xml should be placed in the folder ./web-app/_wave/
</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:robot</span> <span style="color: #000066;">xmlns:w</span>=<span style="color: #ff0000;">&quot;http://wave.google.com/extensions/robots/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:capabilities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:capability</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;blip_submitted&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/w:capabilities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;w:version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/w:version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/w:robot<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>You can add as many capabilities as you want. Remember the version element should correspond to you application appspot version.
</p>
<p><strong>Update: For a clarification on the version numbering see <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.masteringwave.com%2F2009%2F08%2Fcapabilities-xml&sref=rss">http://www.masteringwave.com/2009/08/capabilities-xml</a></strong></p>
<p>You can add the servlet file that need to be extended. This is done by placing the file in the ./src/groovy or ./src/java in your project. If it is a groovy file, it should probably be place4d in the groovy folder. You should maintain the package path within these folders. Create the following file ./src/groovy/com/wave/ParrotyServlet.groovy. (It is not very groovy code, but it is a start)
</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.wave</span><br />
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.wave.api.*</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">class</span> ParrotyServlet <span style="color: #000000; font-weight: bold;">extends</span> &nbsp;AbstractRobotServlet <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> processEvents<span style="color: #009900;">&#40;</span>RobotMessageBundle bundle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; Wavelet wavelet <span style="color: #339933;">=</span> bundle.<span style="color: #006633;">getWavelet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>bundle.<span style="color: #006633;">wasSelfAdded</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Blip blip <span style="color: #339933;">=</span> wavelet.<span style="color: #006633;">appendBlip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextView textView <span style="color: #339933;">=</span> blip.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I'm alive!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Den%26amp%3Bq%3Dallinurl%253Aevent%2Bjava.sun.com%26amp%3BbtnI%3DI%2527m%2520Feeling%2520Lucky&sref=rss"><span style="color: #003399;">Event</span></a> e<span style="color: #339933;">:</span> bundle.<span style="color: #006633;">getEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> EventType.<span style="color: #006633;">BLIP_SUBMITTED</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Blip blip <span style="color: #339933;">=</span> wavelet.<span style="color: #006633;">appendBlip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextView textView <span style="color: #339933;">=</span> blip.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textView.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Copying: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getBlip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Then you need to add the servlet mapping this is done by installing the template. Run the following command, when you are in your project.
</p>
<p><span style="font-family:Courier New; font-size:10pt">grails install-templates<br />
</span></p>
<p>Then you can edit the file ./src/templates/war/web.xml and add the servlet and the serveletmapping. This is done with the following elements. Remember that two elements should be placed after corresponding elements; otherwise the XML is not valid.
</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Parroty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.wave.ParrotyServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Parroty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/_wave/robot/jsonrpc<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>Deploy the service, and you can test you application. Create a new wave. Add you robot with the name &lt;yourappspotname&gt;@appspot.com. Try to add a comment and you should get something like <a href="http://redirectingat.com?id=10371X688478&xs=1&url=http%3A%2F%2Fwww.screencast.com%2Fusers%2FDaniel_Graversen%2Ffolders%2FJing%2Fmedia%2Fed2f5c51-964b-4bf2-9e2c-fccd5f4d02f2&sref=rss">this screencast</a>.
</p>
<p>This is not a very functional robot, but it works. To store data you can use a service, which can be called from the servlet.</p>

<div class="skimlinks-disclosure-button"><p><script class="skimlinks_ref_script" type="text/javascript" src="http://static.skimlinks.com/api/ref.js?p=10371&amp;d=688478&amp;t=1"></script></p></div>
]]></content:encoded>
			<wfw:commentRss>http://graversen.org/2009/07/22/creating-google-wave-robots-in-grails/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

