GWT débutant : erreur de fichier : ATTENTION: No file found for: /test/hello
Salut à tous, je fais mes tous premiers pas avec GWT et j'essaye de faire un service qui affiche "helloworld" dans la console.
Voici la structure de mon projet :
Pour cela, j'ai les classes suivantes :
package client :
Code:
1 2 3 4 5 6 7 8 9
|
package com.test.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface MonService extends RemoteService {
public String hello() ;
} |
Code:
1 2 3 4 5 6 7 8 9 10
|
package com.test.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface MonServiceAsync {
void hello(AsyncCallback<String> callback);
} |
coté serveur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| package com.test.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.test.client.MonService;
public class MonServiceImpl extends RemoteServiceServlet implements MonService {
@Override
public String hello() {
return ("hello world ! ");
}
} |
ma classe qui implémente entry point :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| package com.test.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
public class Test implements EntryPoint {
//Pour instancier le service
private final MonServiceAsync service = GWT.create(MonService.class);
public void onModuleLoad()
{
//Voilà le service est mappé avec le serveur, on peut effectuer lappel à la méthode.
((ServiceDefTarget) service).setServiceEntryPoint (GWT.getModuleBaseURL () + "hello");
appelServiceHelloTest() ;
}
//
public void appelServiceHelloTest()
{
service.hello(new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
System.out.println("echec");
}
public void onSuccess(String result) {
System.out.println("succes" + result);
}
});
}
} |
et mon fichier test.gwt.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?xml version="1.0" encoding="UTF-8"?>
<module rename-to='test'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<servlet path="/hello" class="com.test.server.MonServiceImpl" />
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.test.client.Test'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module> |
J'obtiens l'erreur suivante :
11 oct. 2010 21:15:40 com.google.appengine.tools.development.LocalResourceFileServlet doGet
ATTENTION: No file found for: /test/hello
J'ai du mal à voir ce que je pourrai mettre, je vois bien que mon chemin est faux, mais pourtant. je pensais qu'en mettant la ligne :
Code:
<servlet path="/hello" class="com.test.server.MonServiceImpl" />
le mapping du service entre le serveur et le client était ok et que je pouvais l'appeler comme cela dans mon programme principal :
Code:
1 2
|
((ServiceDefTarget) service).setServiceEntryPoint (GWT.getModuleBaseURL () + "hello"); |
Si quelqu'un a une idée, merci d'avance, les débuts sont toujours laborieux ... :?
merci d'avance
Il faut transposer mon exemple à ton cas
Pour "RelativePathServlet" et "NomModule", tu peux mettre les chaînes de caractères que tu veux mais il faut les remplacer partout où elles apparaissent dans mon exemple sinon comment veux tu que les liens soient fait ?
Reprenons ton exemple.
Dans ton web.xml, ton NomModule, c'est "test2" et ton RelativePathServlet, c'est "monServlet"
Tu ne touches donc pas à ton web.xml.
Tu ne touches pas non plus à ton Test2.java.
Dans Test2.gwt.xml, tu mets le nom de ton module, soit :
<module rename-to="test2">
Dans MonService.java, tu mets ton chemin relatif dans l'annotation, soit :
@RemoteServiceRelativePath("monServlet")