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<String> 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 <code>getMultipleStrings</code>
* RPC call. The same callback can be used for many RPC calls or customized
* for a single one.
*/
private AsyncCallback<Map><Integer, String>> createGetMultipleStringsCallback(
final Panel root) {
return new AsyncCallback<Map><Integer, String>>() {
public void onFailure(Throwable caught) {
Window.alert("error: " + caught);
}
public void onSuccess(Map<Integer, String> 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<Integer, String> 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("<h3>Result(on success)</h3>"));
root.add(t);
}
};
}
/**
* Create an asynchronous callback for the <code>getString</code> RPC call.
* The same callback can be used for many RPC calls or customized for a single
* one.
*/
private AsyncCallback<String> createGetStringCallback(final Panel root) {
return new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
root.add(new HTML("<h3>Result (on failure) </h3>"));
root.add(new HTML("<i>" + caught.getMessage() + "</i>"));
}
public void onSuccess(String result) {
root.add(new HTML("<h3>Result (on success) </h3>" + result));
}
};
}
/**
* Returns an configured instance of the <code>SimpleRPCService</code>
* 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.<SimpleRPCServiceAsync> create(SimpleRPCService.class);
}
}
SimpleRPCException.java
package com.google.gwt.sample.simplerpc.client;
/**
* Simple RPC exception.
*/
public class SimpleRPCException extends Exception {
/**
* Constructor for <code>SimpleRPCException</code>. Needed to support
* serialization.
*/
public SimpleRPCException() {
}
/**
* Constructor for <code>SimpleRPCException</code>.
*
* @param message message for the <code>SimplePRCException</code>
*/
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("simpleRPC")
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 --> string values.
*
* @param indexes indexes to be mapped
* @return map of indexes --> string values
*/
Map<Integer, String> getMultipleStrings(List<Integer> 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 <code>getString</code>.
*/
void getString(int index, AsyncCallback<String> callback);
/**
* Async version of <code>getMultipleStrings</code>.
*/
void getMultipleStrings(List<Integer> indexes,
AsyncCallback<Map><Integer, String>> 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 <code>SimpleRPCService</code> code. This code
* only runs on the server.
*/
public class SimpleRPCServiceImpl extends RemoteServiceServlet implements
SimpleRPCService {
/**
* The server strings used to supply the information to <code>getString</code>.
*/
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<Integer, String> getMultipleStrings(List<Integer> indexes)
throws SimpleRPCException {
Map<Integer, String> accum = new HashMap<Integer, String>();
for (int i = 0; i < 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() + ":"
+ e.getMessage());
}
}
}