GWT RPC Fontes!

Alguém tem alguma ideia por que isso so da pau ?

NO CLIENTE :

SimpleRPC.java

package com.google.gwt.sample.simplerpc.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * Demonstrates a simple use of the RPC mechanism.
 */
public class SimpleRPC implements EntryPoint {

  public void onModuleLoad() {
    final Panel root = RootPanel.get();

    // Create the RPC client.
    SimpleRPCServiceAsync simpleRPCService = createSimpleRPCServiceAsync();

    // Collection of very simple RPC calls to "getString".
    callGetString(root, simpleRPCService);

    // A single simple call to "getMultipleStrings".
    callGetMultipleStrings(root, simpleRPCService);
  }

  /**
   * Creates a single call to <code>getMultipleStrings</code>.
   */
  private void callGetMultipleStrings(final Panel root,
      SimpleRPCServiceAsync simpleRPCService) {
    AsyncCallback<Map><Integer, String>> getMultipleStringsCallback = createGetMultipleStringsCallback(root);

    // Should print a table of key value pairs.
    List<Integer> indexes = new ArrayList<Integer>();
    indexes.add(Integer.valueOf(0));
    indexes.add(Integer.valueOf(2));
    simpleRPCService.getMultipleStrings(indexes, getMultipleStringsCallback);
  }

  /**
   * Calls <code>getString</code> three times, the first two should return
   * valid answers, the third should give back an error. <p/> Control flow will
   * continue after making each call. Later the 'callback' onSuccess or
   * onFailure method will be invoked when the RPC completes. There is no order
   * guarantee here, the three results could appear on the page in any order.
   */
  private void callGetString(final Panel root,
      SimpleRPCServiceAsync simpleRPCService) {
    // Create a callback to use.
    AsyncCallback&lt;String&gt; singleGetStringCallback = createGetStringCallback(root);

    // Should print 'Hello World'.
    simpleRPCService.getString(0, singleGetStringCallback);

    // Should print 'Bonjour monde'.
    simpleRPCService.getString(1, singleGetStringCallback);

    // Should print an IndexOutOfBoundsException.
    simpleRPCService.getString(3, singleGetStringCallback);
  }

  /**
   * Create an asynchronous callback for the &lt;code&gt;getMultipleStrings&lt;/code&gt;
   * RPC call. The same callback can be used for many RPC calls or customized
   * for a single one.
   */
  private AsyncCallback&lt;Map&gt;&lt;Integer, String&gt;&gt; createGetMultipleStringsCallback(
      final Panel root) {
    return new AsyncCallback&lt;Map&gt;&lt;Integer, String&gt;&gt;() {

      public void onFailure(Throwable caught) {
        Window.alert(&quot;error: &quot; + caught);
      }

      public void onSuccess(Map&lt;Integer, String&gt; result) {
        FlexTable t = new FlexTable();
        t.setBorderWidth(2);
        t.setHTML(0, 0, "<b>Map Key</b>");
        t.setHTML(0, 1, "<b>Map Value</b>");
        int index = 1;
        for (Entry&lt;Integer, String&gt; element : result.entrySet()) {
          Integer key = element.getKey();
          String value = element.getValue();
          t.setText(index, 0, key.toString());
          t.setText(index, 1, value);
          ++index;
        }
        root.add(new HTML("&lt;h3&gt;Result(on success)&lt;/h3&gt;"));
        root.add(t);
      }
    };
  }

  /**
   * Create an asynchronous callback for the &lt;code&gt;getString&lt;/code&gt; RPC call.
   * The same callback can be used for many RPC calls or customized for a single
   * one.
   */
  private AsyncCallback&lt;String&gt; createGetStringCallback(final Panel root) {
    return new AsyncCallback&lt;String&gt;() {
      public void onFailure(Throwable caught) {
        root.add(new HTML("&lt;h3&gt;Result (on failure) &lt;/h3&gt;"));
        root.add(new HTML("<i>" + caught.getMessage() + "</i>"));
      }

      public void onSuccess(String result) {
        root.add(new HTML("&lt;h3&gt;Result (on success) &lt;/h3&gt;" + result));
      }
    };
  }

  /**
   * Returns an configured instance of the &lt;code&gt;SimpleRPCService&lt;/code&gt;
   * client proxy. <p/> Note that although you are creating the service
   * interface proper, you cast the result to the asynchronous version of the
   * interface. The cast is always safe because the generated proxy implements
   * the asynchronous interface automatically.
   */
  private SimpleRPCServiceAsync createSimpleRPCServiceAsync() {
    return GWT.&lt;SimpleRPCServiceAsync&gt; create(SimpleRPCService.class);
  }
}


SimpleRPCException.java

package com.google.gwt.sample.simplerpc.client;

/**
 * Simple RPC exception.
 */
public class SimpleRPCException extends Exception {

  /**
   * Constructor for &lt;code&gt;SimpleRPCException&lt;/code&gt;. Needed to support
   * serialization.
   */
  public SimpleRPCException() {
  }

  /**
   * Constructor for &lt;code&gt;SimpleRPCException&lt;/code&gt;.
   * 
   * @param message message for the &lt;code&gt;SimplePRCException&lt;/code&gt;
   */
  public SimpleRPCException(String message) {
    super(message);
  }
}

SimpleRPCService.java

package com.google.gwt.sample.simplerpc.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

import java.util.List;
import java.util.Map;

/**
 * The sample service.
 */
@RemoteServiceRelativePath(&quot;simpleRPC&quot;)
public interface SimpleRPCService extends RemoteService {
  /**
   * Returns a string from the server associated with the given index.
   * 
   * @param index index of string
   * @return the string associated with the given index
   * @throws SimpleRPCException
   */
  String getString(int index) throws SimpleRPCException;

  /**
   * Given a list of indexes, returns a map of indexes --&gt; string values.
   * 
   * @param indexes indexes to be mapped
   * @return map of indexes --&gt; string values
   */
  Map&lt;Integer, String&gt; getMultipleStrings(List&lt;Integer&gt; indexes)
      throws SimpleRPCException;
}


SimpleRPCServiceAsync.java

package com.google.gwt.sample.simplerpc.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

import java.util.List;
import java.util.Map;

/**
 * Async class associated with SimpleRPCService.
 */
public interface SimpleRPCServiceAsync {

  /**
   * Async version of &lt;code&gt;getString&lt;/code&gt;.
   */
  void getString(int index, AsyncCallback&lt;String&gt; callback);

  /**
   * Async version of &lt;code&gt;getMultipleStrings&lt;/code&gt;.
   */
  void getMultipleStrings(List&lt;Integer&gt; indexes,
      AsyncCallback&lt;Map&gt;&lt;Integer, String&gt;&gt; callback);
}

NO SERVIDOR:

SimpleRPCServiceImpl.java

package com.google.gwt.sample.simplerpc.server;

import com.google.gwt.sample.simplerpc.client.SimpleRPCException;
import com.google.gwt.sample.simplerpc.client.SimpleRPCService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The implementation of the &lt;code&gt;SimpleRPCService&lt;/code&gt; code. This code
 * only runs on the server.
 */
public class SimpleRPCServiceImpl extends RemoteServiceServlet implements
    SimpleRPCService {

  /**
   * The server strings used to supply the information to &lt;code&gt;getString&lt;/code&gt;.
   */
  private static final String[] SERVER_STRINGS = new String[] {
      "Hello World", "Bonjour monde", "Hola Español"};

  /**
   * Gets a map of strings associated with the given indexes.
   */
  public Map&lt;Integer, String&gt; getMultipleStrings(List&lt;Integer&gt; indexes)
      throws SimpleRPCException {
    Map&lt;Integer, String&gt; accum = new HashMap&lt;Integer, String&gt;();
    for (int i = 0; i &lt; indexes.size(); i++) {
      Integer key = indexes.get(i);
      String value = getString(key.intValue());
      accum.put(key, value);
    }
    return accum;
  }

  /**
   * Gets a string associated with a given index. In a real world application,
   * we would be consulting a database or some other server-side set of
   * information. Here we are just accessing a server side array.
   * 
   * @param index index of string
   * @return the string associated with the given index
   * @throws SimpleRPCException
   */
  public String getString(int index) throws SimpleRPCException {
    try {
      return SERVER_STRINGS[index];
    } catch (RuntimeException e) {
      throw new SimpleRPCException(e.getClass().getName() + &quot;:&quot;
          + e.getMessage());
    }
  }
}