RPC RemoteServiceServlet multiple methods

103 views
Skip to first unread message

ph09

unread,
Jul 22, 2011, 9:23:35 AM7/22/11
to Google Web Toolkit
Hey,

I have got some questions about the RPC.

Is it possible to define more than one method in one
RemoteServiceServlet? And does this make any Sense?
Like this:

public class SpeicherServiceImpl extends RemoteServiceServlet
implements SpeicherService {

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public String getName(String name) {
return("Server hat folgendes empfangen: \n" + name);
}

public String getName2(String name2){
return("Test2" + name2);
}

}

I tried to call both methods. The first method was served, but the
second throw the following Exception:
[ERROR] javax.servlet.ServletContext log: SpeicherService: An
IncompatibleRemoteServiceException was thrown while processing this
call.
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException:
This application is out of date, please click the refresh button on
your browser. ( Could not locate requested method
'getName2(java.lang.String)' in interface
'de.fhdo.kuss.client.SpeicherService' )
at com.google.gwt.user.server.rpc.RPC.decodeRequest(RPC.java:310)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:
206)
at
com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:
248)
at
com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:
62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:
35)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
58)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:
94)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:351)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)

Jens

unread,
Jul 22, 2011, 9:39:00 AM7/22/11
to google-we...@googlegroups.com
Sure you can and its totally fine to do so. Just make sure that all methods are defined in the service interface and in its async interface.

The exception you have received indicates that your browser uses some old cached javascript file (so clear your cache and reload the site) or your have forgotten to put your getName2() method into the service interface.

I don't know if you already know it, but try to avoid using general interfaces in your RPC method signature (e.g. List) because GWT has to generate code for every possible implementation of these interfaces (because GWT does not know which implementation you will choose). So in case of List its better to directly use ArrayList of whatever List implementation you would like to use in the method signature.

-- J.

swapnil marghade

unread,
Jul 22, 2011, 9:53:33 AM7/22/11
to google-we...@googlegroups.com
Mostly u have forgot to declare it in SpeicherService because code u have posted in not showing @Override annotation above 2nd method. 

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/qm6CQNTA57cJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

ph09

unread,
Jul 22, 2011, 10:18:55 AM7/22/11
to Google Web Toolkit
On 22 Jul., 15:39, Jens <jens.nehlme...@gmail.com> wrote:
> Sure you can and its totally fine to do so. Just make sure that all methods
> are defined in the service interface and in its async interface.
>
> The exception you have received indicates that your browser uses some old
> cached javascript file (so clear your cache and reload the site) or your
> have forgotten to put your getName2() method into the service interface.

Thank for your help so far. I clear the cache with no effect. Maybe i
show you my other classes.
I think the service interface have to be correct. the problem might be
by calling the service?
I call both method, test1() and test2() and only test1() get served.

@RemoteServiceRelativePath("SpeicherService")
public interface SpeicherService extends RemoteService {

String getName(String name);
String getName2(String name2);


public static class Util {
private static SpeicherServiceAsync instance;
public static SpeicherServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(SpeicherService.class);
}
return instance;
}
}
}

public interface SpeicherServiceAsync {

void getName(String name, AsyncCallback<String> callback);

void getName2(String name2, AsyncCallback<String> callback);

}

public void test(String ausgabe) {
AsyncCallback<String> callback = new AsyncCallback<String>() {

@Override
public void onFailure(Throwable caught) {
System.out.println("Server Fehler");
caught.printStackTrace();
}

@Override
public void onSuccess(String result) {
Window.alert(result);
}
};

SpeicherService.Util.getInstance().getName(ausgabe, callback);
}

public void test2() {
AsyncCallback<String> callback = new AsyncCallback<String>() {

@Override
public void onFailure(Throwable caught) {
System.out.println("Server Fehler");
caught.printStackTrace();
}

@Override
public void onSuccess(String result) {
Window.alert(result);
}
};
SpeicherService.Util.getInstance().getName2("miau",callback);
}



> I don't know if you already know it, but try to avoid using general
> interfaces in your RPC method signature (e.g. List) because GWT has to
> generate code for every possible implementation of these interfaces (because
> GWT does not know which implementation you will choose). So in case of List
> its better to directly use ArrayList of whatever List implementation you
> would like to use in the method signature.

You mean something like this, or is it ok?

public static class Util {
private static SpeicherServiceAsync instance;
public static SpeicherServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(SpeicherService.class);
}
return instance;
}
}

Jens

unread,
Jul 22, 2011, 10:39:04 AM7/22/11
to google-we...@googlegroups.com
The code seems fine. Just make sure that your server code matches the client code and it should work. Really seems like a cache problem (clear browser cache, clear project, restart development mode, redeploy the application if you use an external server).


> I don't know if you already know it, but try to avoid using general
> interfaces in your RPC method signature (e.g. List) because GWT has to
> generate code for every possible implementation of these interfaces (because
> GWT does not know which implementation you will choose). So in case of List
> its better to directly use ArrayList of whatever List implementation you
> would like to use in the method signature.

You mean something like this, or is it ok?

public static class Util {
private static SpeicherServiceAsync instance;
public static SpeicherServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(SpeicherService.class);
}
return instance;
}
}

No I mean something like:

public interface MyService extends RemoteService {
  public void save(List<String> items);
  public List<String> getItems();
}

With such a service GWT will generate Serializer classes for all classes that implement List (ArrayList, LinkedList, etc) which will increase the resulting javascript code. So its better to use a concrete implementation of List, e.g.:

public interface MyService extends RemoteService {
  public void save(ArrayList<String> items);
  public ArrayList<String> getItems();
}

Its not related to the code you posted here, but I thought it would be a nice info for you because at some point in your application you may want to transfer lists of objects between client and server.

-- J.
Reply all
Reply to author
Forward
0 new messages