N
N
Nikiti42013-11-22 00:39:18
JavaScript
Nikiti4, 2013-11-22 00:39:18

GWT: InvocationException on asynchronous call?

Mistake:

Unable to initiate the asynchronous service invocation (CustomService_Proxy.myMethod) -- check the network connection


I click on the button, an error occurs. did this TestEntryPoint example :

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);
    }
}


custom service:
package ru.client;

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

/**
 *
 * @author nikita
 */
public interface CustomService extends RemoteService {
    public String myMethod(String s);
}


CustomServiceAsync:
package ru.client;

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

/**
 *
 * @author nikita
 */
public interface CustomServiceAsync {
    public void myMethod(String s, AsyncCallback callback);
}


CustomServiceImpl:
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";
    }
    
   
}


web.xml:
<?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

1 answer(s)
A
aerial, 2014-01-16
@aerial

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) {
          ...
      }
...
})

The method will be called relative to the base URL.
PS Yes, and the tutorial dates back to 2008, a lot has changed since then :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question