Bonjour,
J'ai mis en place une application GWT devant récupérer des données via un webservice afin de les afficher à l'écran. J'ai d'abord voulu implémenter cette méthode de manière simple avant de me rendre compte en me renseignant que je devais utiliser GWT RPC pour pouvoir utiliser ma méthode dans mon application (utilisation de librairie non utilisable côté client).
J'ai donc suivi le tutoriel sur google code mais je n'arrive pas à faire marcher l'appel à ma méthode.
Voici donc le contenu de mon fichier .gwt.xml:
Le contenu de ma classe côté serveur, ClientServiceImpl:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="UTF-8"?> <module rename-to='intranet'> <inherits name='com.google.gwt.user.User'/> <inherits name='com.google.gwt.user.theme.clean.Clean'/> <entry-point class='com.societe.web.client.Intranet'/> <source path='client'/> <source path='shared'/> </module>
Le code de ma première interface côté client, ClientService:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38 @SuppressWarnings("serial") public class ClientServiceImpl extends RemoteServiceServlet implements ClientService { public List<Client> getListeClients() { String endpoint = "http://localhost:8095/Processes/ReferentielSocieteServices.serviceagent/ReferentielSocieteEndpoint"; ReferentielSocieteEndpointBindingStub stub; GetListClientsResponseClientsClient[] clients = null; try { stub = new ReferentielSocieteEndpointBindingStub(new java.net.URL(endpoint), new Service()); GetListClientsRequest req = new GetListClientsRequest(); GetListClientsResponse resp = stub.getListClients(req); clients = resp.getClients(); } catch (AxisFault e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<Client> CLIENTS = Arrays.asList(); for (int i =0;i<clients.length;i++){ GetListClientsResponseClientsClient clientXML = clients[i]; Client client = new Client(clientXML.getCLIENT_NOM(), clientXML.getCLIENT_PHONE(), clientXML.getCLIENT_EMAIL(), clientXML.getSECTEUR_NOM(), clientXML.getCLIENT_ACTIF().toString()); CLIENTS.add(client); } return CLIENTS; } }
Le code de ma seconde interface côté client, ClientServiceAsync:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 @RemoteServiceRelativePath("clients") public interface ClientService extends RemoteService { public List<Client> getListeClients(); }
Ma classe Client (dont je récupère les données):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 public interface ClientServiceAsync { public void getListeClients(AsyncCallback<List<Client>> callback); }
Et l'appel à ma procédure dans ma classe d'entrypoint:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 public class Client { private String name; private String phone; private String mail; private String actif; private String secteur; private ClientServiceAsync clientSvc = GWT.create(ClientService.class); public Client(String name, String phone, String mail,String secteur, String actif) { this.name = name; this.phone = phone; this.mail = mail; this.secteur = secteur; this.actif = actif; } public Client(){ } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } public String getActif() { return actif; } public void setActif(String actif) { this.actif = actif; } public String getSecteur() { return secteur; } public void setSecteur(String secteur) { this.secteur = secteur; } public void getListeClientsCallback(final List<Client> list) { // Initialize the service proxy. if (clientSvc == null) { clientSvc = GWT.create(ClientService.class); } // Set up the callback object. AsyncCallback<List<Client>> callback = new AsyncCallback<List<Client>>() { public void onFailure(Throwable caught) { // TODO: Do something with errors. } public void onSuccess(List<Client> result) { for (Client client : result) { list.add(client); } } }; // Make the call to the stock price service. clientSvc.getListeClients(callback); } public List<Client> getListeClients(List<Client> clientList){ return clientList; } }
Hors, lorsque j'exécute le code en debug, je ne rentre jamais dans la méthode de la classe côté serveur (ClientServiceImpl) ni d'ailleurs dans le onSuccess de ma méthode callback.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 Client c = new Client(); c.getListeClientsCallback(list);
Qu'est ce que je fais de "mal"?
Partager