Blogs

Contact us

Do you have problems with site or you want to give us a feedback? Use our mailing list.

Simple Parroty Robot Tutorial

Basic tutorial which shows how to create same robot as in Google Wave Robots: Java Tutorial . It shows how easy it is to create new robot with DailyDev Wave Robot client library. And how comfortable is the way of event dispatching.

This tutorial assumes that the reader has a basic knowledge of Google's Wave Java Client Library .

Requirements for Java 6, currently defined by Google, are valid here also. For more information read Google's Tutorial .

This tutorial also assumes that you already registered your application with Google App Engine (GAE) and has your Eclipse set and standard GAE project is created. For more information read Setting Up App Engine section from Google's Tutorial.

Libraries

To update standard GAE application into DailyDev Wave Robot Application you should add following libraries into ${project.dir}/war/WEB-INF/lib  folder.
  • wave-robot-api.jar
  • json.jar
  • jsonrpc.jar
  • dailydev-wave-robot-0.2.0.jar

First three libraries are standard Google Wave libraries . The fourth is DailyDev extension which can be downloaded from Download section of this site.

To make libraries available on classpath of the project do Refresh and add libraries through project Properties > Java Build Path > Libraries.

Event Handling

package org.dailydev.robot.parroty;

import static com.google.wave.api.EventType.*;

public class
ParrotyRobotHandler {

    @EventHandlerOperation(eventTypes = { WAVELET_SELF_ADDED })
    public void handleWaveletSelfAdded(Event event, RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();
        Blip blip = wavelet.appendBlip();
        TextView textView = blip.getDocument();
        textView.append("I'm alive!");
    }

    @EventHandlerOperation(eventTypes = { WAVELET_PARTICIPANTS_CHANGED })
    public void handleWaveletParticipantsChanged(Event event,
            RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();
        Blip blip = wavelet.appendBlip();
        TextView textView = blip.getDocument();
        textView.append("Hi, everybody!");
    }
}

Servlet Mapping

<?xml version="1.0" encoding="utf-8"?>
<web-app>

  ...

  <servlet>
    <servlet-name>robot_servlet</servlet-name>
    <servlet-class>org.dailydev.wave.robot.servlet.RobotServlet</servlet-class>
  </servlet>

  ...
   
  <servlet-mapping>
    <servlet-name>robot_servlet</servlet-name>
    <url-pattern>/_wave/robot/jsonrpc</url-pattern>
  </servlet-mapping>

  ...

</web-app>

Robot Engine Construction

package org.dailydev.robot.parroty;

public class ParrotyRobotFactory extends AbstractSingletonRobotFactory {

    @Override
    protected Object[] getHandlers(ServletConfig config) {
        return new Object[] { new ParrotyRobotHandler() };
    }
}

  ...

  <context-param>
    <param-name>robot.factory</param-name>
    <param-value>org.dailydev.robot.parroty.ParrotyRobotFactory</param-value>
  </context-param>
  <context-param>
    <param-name>robot.name</param-name>
    <param-value>Parroty Robot</param-value>
  </context-param>
  <context-param>
    <param-name>robot.version</param-name>
    <param-value>1.0</param-value>
  </context-param>
  <context-param>
    <param-name>robot.avatar</param-name>
    <param-value>/parrot.gif</param-value>
  </context-param>

  ...

Capabilities and Profile Servlet

  ...

  <servlet>
    <servlet-name>capabilities_servlet</servlet-name>
    <servlet-class>
        org.dailydev.wave.robot.servlet.CapabilitiesServlet
    </servlet-class>

  </servlet>
  <servlet>
    <servlet-name>profile_servlet</servlet-name>
    <servlet-class>org.dailydev.wave.robot.servlet.ProfileServlet</servlet-class>
  </servlet>

  ...
   
  <servlet-mapping>
    <servlet-name>capabilities_servlet</servlet-name>
    <url-pattern>/_wave/capabilities.xml</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>profile_servlet</servlet-name>
    <url-pattern>/_wave/robot/profile</url-pattern>
  </servlet-mapping>

  ...