Bonsoir,
Je tente de mettre en place un appel RPC, sous eclipse. Ceci est vraiment la base, je vous met le code.
Je rentre toujours dans la méthode onFailure ... impossible de récupérer un objet, je désespère depuis 9h ce matin 8O
Un grand merci d'avance pour votre aide ou conseil
MyFirstService
MyFirstServiceAsyncCode:
1
2
3
4
5
6
7
8
9
10 package org.oif.start.first.client; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @RemoteServiceRelativePath("myFirstService") public interface MyFirstService extends RemoteService { MyData sendDataString(); }
MyDataCode:
1
2
3
4
5
6 package org.oif.start.first.client; import com.google.gwt.user.client.rpc.AsyncCallback; public interface MyFirstServiceAsync { void sendDataString(AsyncCallback<MyData> callback); }
MyFirstServiceImplCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.oif.start.first.client; import java.io.Serializable; public class MyData implements Serializable { private static final long serialVersionUID = -5595653975005095078L; private String nom; public void setNom(String texte){ this.nom = texte; } public String getNom(){ return this.nom; } }
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.oif.start.first.server; import org.oif.start.first.client.MyData; import org.oif.start.first.client.MyFirstService; import com.google.gwt.user.server.rpc.RemoteServiceServlet; public class MyFirstServiceImpl extends RemoteServiceServlet implements MyFirstService { private static final long serialVersionUID = 7351913872227377902L; public MyData sendDataString(){ MyData mt = new MyData(); mt.setNom("Hello World"); return mt; }
web.xmlCode:
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 org.oif.start.first.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; public class Application implements EntryPoint{ private final MyFirstServiceAsync myFirstService = GWT.create(MyFirstService.class); /** * This is the entry point method. */ public void onModuleLoad(){ AsyncCallback<MyData> callback = new AsyncCallback<MyData>(){ public void onSuccess(MyData result){ Window.alert("ok sa marche : " + result); System.out.println("success"); } public void onFailure(Throwable caught){ Window.alert("erreur rpc"); System.out.println("fail"); } }; myFirstService.sendDataString(callback); Label label = new Label ("Hello World"); RootPanel.get().add( label );
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>GWT-Maven-Archetype</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <session-config> <session-timeout>30</session-timeout> </session-config> <servlet> <servlet-name>myFirstService</servlet-name> <servlet-class>org.oif.start.first.server.MyFirstServiceImpl</servlet-class> </servlet> <servlet-mapping> <servlet-name>myFirstService</servlet-name> <url-pattern>/org.oif.start.first.Application/myFirstService</url-pattern> </servlet-mapping> </web-app>
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
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
89
90
91
92
93
94
95
96
97 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <!-- POM generated by gwt-maven-plugin archetype --> <modelVersion>4.0.0</modelVersion> <groupId>org.oif.start</groupId> <artifactId>first</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <properties> <!-- convenience to define GWT version in one place --> <gwt.version>2.0.2</gwt.version> <!-- tell the compiler we can use 1.5 --> <maven.compiler.source>1.5</maven.compiler.source> <maven.compiler.target>1.5</maven.compiler.target> </properties> <dependencies> <!-- GWT dependencies (from central repo) --> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-servlet</artifactId> <version>${gwt.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>com.google.gwt</groupId> <artifactId>gwt-user</artifactId> <version>${gwt.version}</version> <scope>provided</scope> </dependency> <!-- test --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> </dependencies> <build> <outputDirectory>war/WEB-INF/classes</outputDirectory> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> <version>1.2</version> <executions> <execution> <goals> <goal>compile</goal> <!-- <goal>generateAsync</goal>--> <goal>test</goal> </goals> </execution> </executions> <configuration> <runTarget>org.oif.start.first.Application/Application.html</runTarget> </configuration> </plugin> <!-- If you want to use the target/web.xml file mergewebxml produces, tell the war plugin to use it. Also, exclude what you want from the final artifact here. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>target/web.xml</webXml> <warSourceExcludes>.gwt-tmp/**</warSourceExcludes> </configuration> </plugin> --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <!-- <source>${maven.compiler.source}</source> <target>${maven.compiler.target}</target> --> </configuration> </plugin> </plugins> </build> </project>