Monday, December 28, 2009

Google Wave Development - Robots in Netbeans 6.7

In this post I hope to describe how to create Google Wave robots in Netbeans 6.7. The instructions are adapted from a blog post on GAEJ Experiments regarding the use of the WADRobotFramework in Eclipse. Thanks to Romin Irani for the information on GAEJ Experiments and Jerome Baton for the WADRobotFramework.

This post assumes that you have a Google App Engine account and have Netbeans 6.7 setup to allow the deployment of Java applications to the Google App Engine. To deploy to GAE from Netbeans 6.7 you will need the GAE for NB Plugin. To check if it is setup correctly follow the tutorial here.

To begin with download the WADRobotFramework. It is a single JAR that should be copied to a directory on your machine. I used C:\Java_Utils\Wad. You will also need to download the Wave Robot Java Library from Google Code. I place all the files from this location into the directory c:\java_utils\waverobot.

Once we have all the files downloaded and copied to the correct directories I can create a new Web Project in Netbeans.

 

The project should be created with the name you want the robot to be names within Google Wave. I  have called mine CoxyDaveWaveRobot.




Ensure that Google App Engine has been selected as the Server.


Once the wizard has completed creating the project you can delete the index.jsp file as it is not required for the Wave Robot.

The next step is to add the required libraries to the project to allow us to use the WADRobotFramework and the Google Wave Robot Client.



Go to the Project Properties...Libraries panel and add each of the above libraries. Ensure that the Package checkbox is marked.

We can now start to build our Google Wave Robot. Create a new Java Class called MyAppenderRobot and once the wizard has completed add an import for org.wadael.waverobotfrmwrk.simple.BlipAppenderRobot and change the class declaration to extend BlipAppenderRobot. Netbeans will indicate that you need to 'Implement all Abstract Messages'. Use the wizard to implement the abstract methods. Replace the body of the getTextToAppend to the content shown.

public class MyAppenderRobot extends BlipAppenderRobot{

    @Override
    protected String getTextToAppend(String arg0) {
        return "I am replying to your blip!";
    }

Open the web.xml file and add the following servlet details:


        MyAppenderRobot
        coxydave.waverobot.MyAppenderRobot
    
    
        MyAppenderRobot
        /_wave/robot/jsonrpc
    

Add a new directory (_wave) to the WAR file as shown and add a new XML file called capabilities.xml




Add the following content to this file:


  
    
  
  1


Ensure the app-engine.xml file contains the following:


    coxydavewaverobot
    1


At this point you should create a Google App Engine Application with the same name as your project. This will allow Netbeans to automatically deploy the war file to this application.




Once the application has been created it should be possible to 'Build the Main project' and use the 'Deploy to
Google App Engine' on the context menu for the project.

Once the application has been deployed to the Google App Engine, my application  is accessible within Google Wave using the following email address: coxydavewaverobot@appspot.com. Yours will be the ApplicationID@appspot.com. To use the robot just add the address to a new or existing wave. The robot will say hello and then wait for someone to add a new blip. At this point it will return the message in a new reply blip.

Hopefully this was useful. If anything is unclear please leave a comment on the blog and I will respond accordingly. Thank you.



3 comments:

  1. Hello,

    Thanks for mentionning the WadRobotFramework.

    Jérôme BATON

    ReplyDelete
  2. Congratulations,

    This article is now in a google maintained list on this page :
    http://code.google.com/apis/wave/articles.html

    Jérôme

    ReplyDelete
  3. If you haven't already seen, we launched a new version of the Robots API today, and are effectively deprecating the old version, since the new one can do everything that the old one can, plus more.

    More info on the new API is in the launch blog post:

    http://googlewavedev.blogspot.com/2010/03/introducing-robots-api-v2-rise-of.html

    We have been linking to your article from the documentation "Articles" page, but we may remove the link soon, to reduce developer confusion and to encourage more use of the new API.

    We hope that you will find the time to try out this new API and port your article to utilize it, so that developers can continue learning from you. If you do port your article, please let us know so that we can highlight the resource.

    We also hope you like this new API. :)

    Thanks!

    ReplyDelete