Answer the question
In order to leave comments, you need to log in
GWT: InvocationException on asynchronous call?
Mistake:
Unable to initiate the asynchronous service invocation (CustomService_Proxy.myMethod) -- check the network connection
package ru.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
/**
* Main entry point.
*
* @author nikita
*/
public class TestEntryPoint implements EntryPoint {
/**
* Creates a new instance of TestEntryPoint
*/
public TestEntryPoint() {
}
/**
* The entry point method, called automatically by loading a module that
* declares an implementing class as an entry-point
*/
public void onModuleLoad() {
final Label label = new Label("Hello, GWT!!!");
final Button button = new Button("Click me!");
final String y = "987654321";
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
CustomServiceAsync custservice = (CustomServiceAsync)GWT.create(CustomService.class);
ServiceDefTarget sdt = (ServiceDefTarget)custservice;
String moduleRelativeURL = "localhost:8084/WebGWTTest/CustomServiceImpl";
sdt.setServiceEntryPoint(moduleRelativeURL);
button.setText(sdt.getServiceEntryPoint());
AsyncCallback callback = new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
label.setText("Pichal\'");
label.setVisible(true);
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(Object result) {
label.setText(result.toString());
}
};
custservice.myMethod(y, callback);
}
});
RootPanel.get().add(button);
RootPanel.get().add(label);
}
}
package ru.client;
import com.google.gwt.user.client.rpc.RemoteService;
/**
*
* @author nikita
*/
public interface CustomService extends RemoteService {
public String myMethod(String s);
}
package ru.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author nikita
*/
public interface CustomServiceAsync {
public void myMethod(String s, AsyncCallback callback);
}
package ru.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import ru.client.CustomService;
/**
*
* @author nikita
*/
public class CustomServiceImpl extends RemoteServiceServlet implements CustomService {
String seriaVersionUID;
@Override
public String myMethod(String s) {
return s+"Oo";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>CustomServiceImpl</servlet-name>
<servlet-class>ru.server.CustomServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CustomServiceImpl</servlet-name>
<url-pattern>/CustomServiceImpl</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>welcomeGWT.html</welcome-file>
</welcome-file-list>
</web-app>
Answer the question
In order to leave comments, you need to log in
The code in the onClick handler is somewhat... exotic.
Be sure to go through this tutorial In short, to call a remote method, just do
CustomServiceAsync custService = GWT.create(CustomService.class);
custService.myMethod("test", new AsyncCallback<String> {
public void onFailure(Throwable caught) {
...
}
public void onSuccess(String result) {
...
}
...
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question