GWT / Java - Possible to make RPC calls when doing "run as web application" in Eclipse (with GWT plugin)?
I'm fairly new to GWT and seemed to be making a lot of progress but now making an RPC call has me completely stumped. I have followed a few tutorials and, as far as I can tell, am doing things correctly. However, my Asynch callback method is always triggering the one I have set for the event of failure. I am wondering if RPC calls should work when doing "run as web application" in Eclipse (with GWT plugin). Also, to confirm, my application does run fine with the exception of this so there are no build errors.
Its kind of a lot to post here but I am including the different parts of what I am using to make the RPC call in case it may help me get this solved.
This is being called within a controller method:
RPCService rpc = GWT.create(RPCService.class);
//new RPCService();
rpc.testRPC("Hello", callback);
with the Asynch method being:
AsyncCallback callback = new AsyncCallback()
{
public void onFailure(Throwable caught)
{
display.setTestRPC("failed");
}
public void onSuccess(Object result)
{
开发者_如何学编程 display.setTestRPC("success");
}
};
Then the actual RPC classes / interfaces:
RPCInterfaceAsync
package org.ediscovery.gwt.client.rpc;
import com.google.gwt.user.client.rpc.RemoteService;
public interface RPCInterface extends RemoteService
{
public String testRPC(String message);
}
RPCService
package org.ediscovery.gwt.client.rpc;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface RPCInterfaceAsync
{
public void testRPC(String message, AsyncCallback callback);
}
SERVERSIDE: RPCImpl:
package org.ediscovery.gwt.server.service;
import java.text.DateFormat;
import java.util.Date;
import org.ediscovery.gwt.client.rpc.RPCInterface;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class RPCImpl extends RemoteServiceServlet implements RPCInterface
{
private static final long serialVersionUID = 1L;
public String testRPC(String message)
{
Date now = new Date();
String dtm = DateFormat.getTimeInstance(DateFormat.MEDIUM).format(now);
return "Got the message '" + message +"' at " + dtm;
}
}
Relevant part of web.xml:
<servlet>
<servlet-name>RPCImpl</servlet-name>
<servlet-class>org.ediscovery.gwt.server.service.RPCImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RPCImpl</servlet-name>
<url-pattern>/HelloGoodByeMVP.html/rpc</url-pattern>
</servlet-mapping>
You have forgotten to add RemoteServiceRelativePath annotation to your RPCInterface..
精彩评论