-1

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);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Armin
  • 351
  • 1
  • 4
  • 29

1 Answers1

2

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

GridDragon
  • 2,857
  • 2
  • 33
  • 41
  • thank you, i'll try to add a web.xml tomorrow. Is it also possible to use Annotations? – Armin Feb 06 '14 at 21:35
  • I've never done it that way. I always use and tags. To use annotations, I think you need to include the java-servlet api, which is probably something better added after it's already working. – GridDragon Feb 06 '14 at 21:42
  • ok, I changed it, but the onFailure-Method stil gets called. The caught message contains a 404 error - The requested resource is not available. – Armin Feb 07 '14 at 07:53