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 :(
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.