0

i have a problem with gwt and rpc. I implementet a Service for my rpc:

@RemoteServiceRelativePath("search")
public interface SearchService extends RemoteService {
    List<Result> doSearch(String keyWords, Coordinate start, Coordinate end);
}

public interface SearchServiceAsync {
    void doSearch(String keyWords, Coordinate start, Coordinate end, AsyncCallback<List<Result>> callback);
}

public class SearchServiceImpl extends RemoteServiceServlet implements SearchService {
    private static final long serialVersionUID = 1L;
    private ISearch search = null; // interface to my database

    public List<Result> doSearch(String keyWords, Coordinate start, Coordinate end) {
        LonLat lowerLeft = new LonLat(start.getLongitude(), start.getLatitude());
        LonLat upperRight = new LonLat(end.getLongitude(), end.getLatitude());

        try {
            search = new SearchController(keyWords, lowerLeft, upperRight);
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        List<de.myPackage.model.Result> temp = null;

        try {
            temp = search.doSearch();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return map(temp);
    }

    private List<Result> map(List<de.myPackage.model.Result> results) {
       ....
    }
}

These are the needed Classes for the Callback. Dont wonder about this two classes Result and de.myPackage.model.Result. The Result Class is in the shared Folder and the de.myPackage.model.Result is the same Class but from another Module (using maven). I have to make it that complicated because in the clientside code you cant use any self coded container. For this i have the map() method in my SearchServiceImpl. It maps the de.myPackage.model.Result to Result.

Here the missing call from my View:

AsyncCallback<List<Result>> callback = new AsyncCallback<List<Result>>() {
    public void onFailure(Throwable caught) {
        System.out.println("Fail!");    
    }

    public void onSuccess(List<Result> result) {
        addToTable(result);
    }
};
searchService.doSearch(callback);

The Problem is now, that it never calls the doSearch-Method of my SearchServiceImpl because he says he cant find it and i dont know why :( Everytime i push the button which triggers the callback it says:

404 - POST /myProject/search (127.0.0.1) 1412 bytes
   Request headers
      Host: 127.0.0.1:8888
      User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
      Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
      Accept-Encoding: gzip, deflate
      Connection: keep-alive
      Referer: http://127.0.0.1:8888/index.html?gwt.codesvr=127.0.0.1:9997
      X-GWT-Permutation: HostedMode
      X-GWT-Module-Base: http://127.0.0.1:8888/myProject/
      Content-Type: text/x-gwt-rpc; charset=utf-8
      Content-Length: 334
      Pragma: no-cache
      Cache-Control: no-cache
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1412

What does that mean? I dont understand it :(

user1882812
  • 936
  • 5
  • 18
  • 41
  • What do you have in your WEB-INF/web.xml? or maybe you're using the `mergewebxml` mojo of the gwt-maven-plugin with the `scanRemoteServiceRelativePathAnnotation` parameter? – Thomas Broyer Jan 05 '13 at 13:59
  • No there is nothing in my web.xml cause i thought it will be generated automatically by maven. If not - what do i actually have to add to my web.xml? – user1882812 Jan 05 '13 at 14:14

1 Answers1

0

You're missing the servlet mapping in your WEB-INF/web.xml:

<servlet>
  <servlet-name>SearchService</servlet-name>
  <servlet-class>de.myPackage.server.SearchServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>SearchService</servlet-name>
  <url-pattern>/search</url-pattern>
</servlet-mapping>

You can either put that right in your web.xml, have it generated by the gwt-maven-plugin, or if you're using a Servlet 3.0 container (i.e. not DevMode, nor AppEngine) apply the appropriate annotation on your class.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Oh sorry, it doenst :( Server class 'de.myProject.server.SearchServiceImpl' could not be found in the web app. Same Error 404. If i use the xml part from the link you postet the pom.xml isnt parsable any more – user1882812 Jan 05 '13 at 15:33
  • How are you running your app? `mvn gwt:run` ? or from Eclipse using the Google Plugin for Eclipse? In the latter case, see https://developers.google.com/eclipse/docs/faq#gwt_with_maven – Thomas Broyer Jan 05 '13 at 15:39
  • I run it from Eclipse. Dont know how to do it on a other way ^^. For which case is the link interesting? For self editing the web.xml or for generating it through gwt`? – user1882812 Jan 05 '13 at 15:42
  • Found something in my pom.xml: org.apache.maven.plugins maven-clean-plugin 2.4.1 src/main/webapp/Application Does it hast to mean "Application"? Because i havent got a file or a directory named Application – user1882812 Jan 05 '13 at 16:02
  • Bad practice. One should never use `src/` as a target, that's what `target/` is for; in other words, one should never use `src/main/webapp` as the `-war` for GWT (DevMode or Compiler). There's no need for such configuration in your POM if you're doing things the right way. I'd suggest you start fresh from an empty POM, or use a newer and/or better archetype (the gwt-maven-plugin's archetype is *not* a good start) – Thomas Broyer Jan 05 '13 at 16:40
  • i have a target/ folder and this post: https://developers.google.com/eclipse/docs/faq#gwt_with_maven says to use src/main/webapp as the WAR folder ^^ – user1882812 Jan 05 '13 at 16:55
  • No, it says to configure the plugin with `src/main/webapp` but then choose `target/myapp-1.0-SNAPSHOT` as the `-war` folder. – Thomas Broyer Jan 05 '13 at 19:48
  • and how to choose target/myapp-1.0-SNAPSHOT as the -war folder? – user1882812 Jan 05 '13 at 19:52
  • "Right-click your project and select Run As > Web Application. The first time you do this, you'll have to select the location of the exploded WAR directory (by default it should be /target/-)." If you already have a launcher, go edit in the "Arguments" tab. – Thomas Broyer Jan 05 '13 at 23:30
  • when i do that there is an error: Working Directory does not exist but it exists – user1882812 Jan 06 '13 at 05:38