javagwtsmartgwt

GWT - failure on async method call


What is the reason why the onFailure(...) method is called when I do a async method call? The console output says always "ERROR!!!!".

MyEntryPoint.java:

package com.example.smartgwtproject.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
//...

public class MyEntryPoint implements EntryPoint {
    public void onModuleLoad() {
        GreetingServiceAsync service = (GreetingServiceAsync) GWT.create(GreetingService.class);
        //...

        service.getFileList(new AsyncCallback<List<String>>(){

            @Override
            public void onFailure(Throwable caught) {
                System.out.println("ERROR!!!!");
            }

            @Override
            public void onSuccess(List<String> result) {
                System.out.println("OK!");
            }
        });
        //...
    }
}

.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module rename-to='dlaconfigcenter'>

  <inherits name='com.google.gwt.user.User'/>
  <inherits name="com.smartgwt.SmartGwt"/>

  <entry-point class='com.example.smartgwtproject.client.MyEntryPoint'/>

  <source path='client' />
  <source path='shared' >
    <include name="GreetingServiceImpl.java"/>
  </source>

</module>

GreetingService:

package com.example.smartgwtproject.client;

//...

@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
    List<String> getFileList();
}

GreetingServiceAsync:

//...

public interface GreetingServiceAsync {

    void getFileList(AsyncCallback<List<String>> callback);
}

Solution

  • The <include name="GreetingServiceImpl.java"/> should not be in the gwt.xml. The Impl class is server-side code and shouldn't be included as a GWT source. If you use any non-emulated classes such as third-party libraries like Apache Commons, you'll get compile errors.

    You might need to make some changes to your web.xml to point to the GreetingsServiceImpl class, which may be what you were trying to achieve in your gwt.xml. I'd recommend going through this tutorial to double-check your configuration. http://www.vogella.com/tutorials/GWT/article.html#server

    Assuming your configuration is working. The getFileList() method in your GreetingServiceImpl class is probably throwing an exception. That's normally what triggers the onFailure method to be called. Since your GreetingServiceImpl I can't be sure if that's what's going on or not though.

    Update

    The 404 error means GWT can't find your Impl class. There are two possibilities.

    1. Your Web Server isn't running.
    2. Your web.xml isn't configured correctly.

    If you're running in hosted mode, #1 shouldn't be the case. If you're not sure, there's more information on hosted mode here: http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html

    For #2, reference the tutorial I linked above. If you're Servlet (the Impl class) isn't mapped correctly, you'll continue to get a 404. Basically you need the Impl class in the com.example.smartgwtproject.sever package and have a corresponding record in the web.xml. It should look something like:

    <servlet> 
        <servlet-name>GreetingService</servlet-name>
        <servlet-class>com.example.smartgwtproject.sever.GreetingServiceImpl</servlet-class>
    </servlet> 
    
    <servlet-mapping> 
        <servlet-name>GreetingService</servlet-name> 
        <url-pattern>/GreetingService</url-pattern> 
    </servlet-mapping>
    

    However I can't garuntee that is correct for your set up. Again, refer to the tutorial for all the details. Tutorial Link