Books I Like

Sunday, October 11, 2009

Writing Google Wave Robots using Java on Intellij




I got my google wave invite two days back (friday night, can't be a better time). And within 4 hours I was talking with my "HelloWorldish" Robot, such is the power and ease to write and deploy a robot is.

If you use eclipse, you already are set and this is the best place to start with : http://code.google.com/apis/wave/extensions/robots/java-tutorial.html

In fact, I used the same page for the sourcecode, and the steps. Make sure, you have a google wave id before you start looking at the next steps.

Steps :-

1.Make sure you are using Java 1.6.

2. I am using Intellij Maia (9). If you are on older version install the google appengine plugin.

3. Use this plugin to generate a dummy web project. In the wizard, choose google app engine. We are not going to use either GWT/ JDO or JPA for this project, so just uncheck them.

4. You can see a "AppEngine Dev" settings to run. Run it ,and you should be able to browse the dummy page at localhost:8080

5. To write the Robot, we need few libraries. Download it from http://code.google.com/p/wave-robot-java-client/downloads/list.

6.create a lib directory inside WEB-INF and copy all these jars . Also, add servlet-api-2.4.jar or higher.

7.Make a package src/parroty.server and copy paste the ParrotyServlet code described at http://code.google.com/apis/wave/extensions/robots/java-tutorial.html

8.Make a web/_wave dir. Create a capabilties.xml file and copy paste the code


<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="http://wave.google.com/extensions/robots/1.0">
<w:capabilities>
<w:capability name="WAVELET_PARTICIPANTS_CHANGED" content="true" />
</w:capabilities>
<w:version>1</w:version>
</w:robot>


9. Register your application on appengine site.

In you appengine-web.xml file substitute your application id (instead of mine, "mytestwaveapp") :-


<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>mytestwaveapp</application>
<version>1</version>
</appengine-web-app>


10. Configure your ParrotyServlet inside the web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Parroty</servlet-name>
<servlet-class>parroty.server.ParrotyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Parroty</servlet-name>
<url-pattern>/_wave/robot/jsonrpc</url-pattern>
</servlet-mapping>
</web-app>


Go to "Tools->Upload AppEngine Application", and you are good enough to deploy this Robot.It would ask you your appengine loginid/pwd.The console would show, that everything went fine. You can confirm by accessing the capabilties.xmlfile :- http://applicationName.appspot.com/_wave/capabilities.xml

11.Well, now you are done. Use this robot as a participant for your wave and it should answer as I have shown in the picture. More Sample Robot Codes :- http://code.google.com/p/google-wave-resources/source/browse/trunk/samples/extensions/robots/java

Happy Coding ! Happy Waving !!!

6 comments:

Cables said...

Will this work with twitter? Or crush it out of existence? Looks very interesting regardless.

Anshu said...

Yes. There is already a robot for twitter available, as demostrated during google io 2009 presentation.

Googlewave-Tutorials.com said...

Thanks Anshu, nice article. I've indexed this article on GoogleWave-Tutorials.com as it's really good for those starting off and wanting to write their first Google Wave robot.

Thanks,

heilpflanzen said...

With the consumer release of Google Wave scheduled for the InfoQ had a Q&A with Google Software Engineer Dhanji Prasanna about some of its less known internals, details about how it’s being developed by the Google engineers and the best practices involved.

Anonymous said...

Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

Dissertation Help said...

it's good to see this information in your post, i was looking the same but there was not any proper resource, thanx now i have the link which i was looking for my research.

Get at Amazon