Archive

Archive for September, 2009

Google Wave Robots: A Pictured Java Tutorial

September 24th, 2009

This post is a reference to Google’s own Java Tutorial for Google Wave Robots with an example of robot code that performs word replacement.

In my previous post, I have also briefly explained what Google Wave is about.

What you need to run a simple Java Wave Robot.

1) Eclipse IDE + JDK 6
2) Google Wave Java Client libraries
3) Google App Engine Account

Yes, you only require 3 items but most importantly, to access Google Wave, you need a Google Wave Id.

1) Eclipse IDE + JDK 6

Download Eclipse IDE here : http://www.eclipse.org/downloads/

eclipse_download

Download JDK 6 here : http://java.sun.com/javase/downloads/index.jsp

jdk6_download

Install the Google Plugin and the App Engine SDK:

eclipse_update

Depending on the version of Eclipse IDE you downloaded, you will need to follow Google Wave’s guide to update using either one of the following URL:
http://dl.google.com/eclipse/plugin/3.5
or
http://dl.google.com/eclipse/plugin/3.4

eclipse_update_site

2) Google Wave Java Client libraries
Download the Java client libraries from http://code.google.com/p/wave-robot-java-client/downloads/list
Jar files required are :

  • wave-robot-api-.jar
  • json.jar
  • jsonrpc.jar

Save those files to your project library under \WEB-INF\lib

java_wave_client_lib

3) Code your Wave Robot

You can use Google Wave Java Tutorial source code directly if you want to, but I figure that I need to make some difference and hence thought of a simple words replacement robot.

hack1

hack2

My customization is highlighted in bold, you would want to change it with your own code.

Following is my source code of MarvyServlet (pardon me for the profanity in the source code, but this is a profanity filter robot afterall 🙂 )

package net.marvinlee.marvy;

import com.google.wave.api.*;

public class MarvyServlet extends AbstractRobotServlet {

      @Override
      public void processEvents(RobotMessageBundle bundle) {
        Wavelet wavelet = bundle.getWavelet();

        if (bundle.wasSelfAdded()) {
          Blip blip = wavelet.appendBlip();
          TextView textView = blip.getDocument();
          textView.append("I'm here to ensure you have a nice and polite wave.");
        }

        for (Event e: bundle.getEvents()) {

          if (e.getType() == EventType.WAVELET_PARTICIPANTS_CHANGED) {
            Blip blip = wavelet.appendBlip();
            TextView textView = blip.getDocument();
            textView.append("Hi, everybody! I will be censoring profanities in your conversation.");
          }

          if (e.getType() == EventType.BLIP_SUBMITTED) {
            Blip blip = e.getBlip();
            TextView textView = blip.getDocument();
            String blipText = textView.getText();
            textView.delete();
            textView.append(replaceProfanity(blipText));
          }
        }
      }

        private static String replaceProfanity(String text)
        {
            String[] vulgars = {"shit", "damn", "fark"};
            String[] vulgarReplacement = {"sh#t", "darn", "f##k"};
            String niceText = "";

            System.out.println("Input:" + text);
            for (int i=0; i< vulgars.length; i++)
            {
                String key = vulgars[i];
                if (text.indexOf(key) > 0)
                {
                    text = text.replaceAll(vulgars[i], vulgarReplacement[i]);
                    System.out.println(vulgars[i] + " replaced with " + vulgarReplacement[i] );
                }

                niceText = text;
            }

            System.out.println("Output:" + niceText);
            return niceText;
        } 

    }

capabilities.xml file under _wave

<?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:capability name="BLIP_SUBMITTED" content="true" />
  </w:capabilities>
  <w:version>1</w:version>
</w:robot>

web.xml under WEB-INF

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
    <servlet>
        <servlet-name>Marvy</servlet-name>
        <servlet-class>net.marvinlee.marvy.MarvyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Marvy</servlet-name>
        <url-pattern>/_wave/robot/jsonrpc</url-pattern>
    </servlet-mapping>
</web-app>

appengine-web.xml – marvinleebot is my application name, and is unique in Google App Engine.
If you do not have a Google App Engine yet, follow step 4) below and come back again.

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

    <!-- Configure java.util.logging -->
    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    </system-properties>

</appengine-web-app>

You can make other changes by viewing the Wave JavaDoc.

4) Deploy to Google App Engine
You will need to create an application in your Google App Engine first if you have not.

create_app_engine

You might also need to verify your account with a mobile number, just follow through the steps.
Create your app here : https://appengine.google.com/start
Your app name has to be unique so take some time to figure one or if you’re like me, just a lame bot name like marvinleebot might do the trick.

Once you’re done with your app name and created successfully, make sure that your appengine-web.xml file contains your own app name.

<application><your_app_name_here></application>

When you’re ready, just hit the Deploy App Engine Project button.

eclipse_google_plugin

Submit your App Engine Account Email and Password.

deploy_app_engine

5) Test your Wave Robot

As I’ve mentioned earlier, the single most important thing for it to work is to have a Google Wave Id.

If you have one, you can login Wave Sandbox at http://wavesandbox.com/.

wave_sandbox_login

If you do not have a Google Wave Id yet, request one here.

Create a new wave, and then add the bot you have created by adding a participant : <your_app_name>@appspot.com

This is how the bot looks like and how my marvinleebot worked (click to enlarge). I was using a test Wave Id from Nazroll.

wave_sandbox

You can also monitor your bot/app from your App Engine dashboard.
app_engine

Google, Java, Open Source , , , , ,

The digital tidal wave – Google Wave

September 16th, 2009

google_wave_logoWhat’s Google Wave?

Hmm.. looks like I have been covering a lot on Google stuff lately and ‘Google’ is the largest word in my tag cloud now.

But with the rate of cool stuff coming out from Google, I couldn’t stop myself. 😛

Google Wave, as defined by Google, is a new model for communication and collaboration on the web, coming later this year. What the heck does that means anyway?

It is still in developer preview stage, and not open for public use yet, just like the initial stages of GMail.

google_wave_preview

Lucky for me though, this time I get to have a developer preview access, thanks to my participation in Google Technology User Group, KL. More on GTUG later.

I have attached a lengthy video of the initial wave announcement + demonstration at the bottom of this post. It takes more than an hour to finish, but if you’re into innovation, it’s well worth it.

To me, I see that Google Wave addresses some problems in our current email usage. This includes an email thread which started with the first email of questions that goes back and forth between a few people, adding more and more colours to highlight the part of new reply and also trying to figure out the sequence of replies. Familiar?

Google Wave has a client or a browser based interface like your email software that lists conversations. Each topic is a wave and every reply is a blip.

google_wave_sandbox

Users can playback the wave in sequence or by frame to see how the conversation started up to the current point and also easily embed photos or videos.

It supports programs named Wave Robots, Gadgets and Embed API. Don’t let those names intimidate you, they are just programs for the conversational tool.

Robots are programs that can be added into a wave and become a tool in the wave. It is an automated participant, programmed to do things that can be done by participant, only that it is a Robot.

Gadgets are programs that can be added into the wave, something like miniature objects that can provide cool and dynamic contents. At this point of time, I would like to say it’s something like OpenSocial gadgets but ironically it doesn’t support OpenSocial API yet. Most of the gadgets are games.

google_wave_gadgets

Embed API is working the other way, where developers can put Google Wave into their website instead of putting their program into Wave. An example for this is extension to blog commenting system, where wave users can comment with their Google Wave accounts.

I don’t think it as a super duper cool technology that will change our lives as much as Google Search does, but gradually it might change how people communicate more than just plain email and instant messaging.

The video of the Google Wave keynote presentation in Google IO:

Google Wave will progress from developer preview to beta version starting September 30th. Another 100,000 wave accounts will be given on top of those having developer preview access.

If you’re interested with Google Wave technology, request for your access here. I heard those who will report bugs and submit feedback will get their accounts sooner.

I joined the GTUG KL 2nd Wave hackathon session last weekend and created a simple Wave Robot with Java. I’ll be posting about my experience of that soon, so stay tuned. GTUGs are user groups for people who are interested in Google’s developer technology. GTUG KL is the group in Kuala Lumpur, Malaysia. Follow GTUG KL on facebook, and join the upcoming events. There might be cool lightning talks about cool Google stuff or even hackathon sessions for developers.

Google, Internet, Technology , , , ,

Eclipse Day 2009 video presentations

September 14th, 2009

Eclipse Day is not the day the solar eclipse happened.

Eclipse Day 2009 is a full day event for developers to learn about different Eclipse projects and related technologies in Googleplex.

Being a Java Developer, Eclipse is one of the best Java IDE around, and in fact some developer uses Eclipse exclusively.

For non-developers who doesn’t know Eclipse, it is a tool for you to do programming and the tool itself is open source, meaning people can actually read the code on how the program runs, or even build additional tools for it.

Eclipse has grown a lot since founded in 2001, with numerous plugins for various technologies including OSGi, Android, and Google related apps like Google App Engine (GAE), Google Web Toolkit (GWT) and even the upcoming Google Wave (well you can do it on GAE Java ).

Some of the videos recorded from the Eclipse Day 2009.



For the full video listing, visit Google’s Open Source blog.

Google, Open Source, Software , , , , , ,