IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GWT et Vaadin Java Discussion :

Erreur GWT Appel RPC


Sujet :

GWT et Vaadin Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de miya
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    469
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2006
    Messages : 469
    Par défaut Erreur GWT Appel RPC
    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

    Un grand merci d'avance pour votre aide ou conseil

    MyFirstService
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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();
    }
    MyFirstServiceAsync
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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);
    }
    MyData
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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;
    	}
    }
    MyFirstServiceImpl
    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
     
     
    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;
    	}
    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
     
    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 );
    web.xml
    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
     
    <?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 : 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
    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>

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Mars 2009
    Messages : 36
    Par défaut
    Il est obligatoire d'avoir un constructeur par défaut pour les objets qui transitent via RPC. Je vois que ta classe MyData n'a pas de constructeur vide.

    Est ce que tu peut afficher ton exception ainsi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public void onFailure(Throwable caught){
                     caught.printStackTrace();
                  }

  3. #3
    Membre éclairé Avatar de miya
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    469
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2006
    Messages : 469
    Par défaut
    Merci pour ta réponse.

    Voici la stacktrace :

    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
    [ERROR] com.google.gwt.user.client.rpc.StatusCodeException: <html>
    [ERROR] <head>
    [ERROR] <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    [ERROR] <title>Error 404 NOT_FOUND</title>
    [ERROR] </head>
    [ERROR] <body><h2>HTTP ERROR: 404</h2><pre>NOT_FOUND</pre>
    [ERROR] <p>RequestURI=/org.oif.start.first.Application/myFirstService</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] <br/>                                                
    [ERROR] 
    [ERROR] </body>
    [ERROR] </html>
    [ERROR] 
    [ERROR] 	at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
    [ERROR] 	at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    [ERROR] 	at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [ERROR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [ERROR] 	at java.lang.reflect.Method.invoke(Method.java:597)
    [ERROR] 	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    [ERROR] 	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    [ERROR] 	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
    [ERROR] 	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    [ERROR] 	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    [ERROR] 	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
    [ERROR] 	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    [ERROR] 	at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    [ERROR] 	at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [ERROR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [ERROR] 	at java.lang.reflect.Method.invoke(Method.java:597)
    [ERROR] 	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    [ERROR] 	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    [ERROR] 	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    [ERROR] 	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    [ERROR] 	at java.lang.Thread.run(Thread.java:637)
    url :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    http://127.0.0.1:8888/org.oif.start.first.Application/Application.html?gwt.codesvr=127.0.0.1:9997
    Une erreur côté server ? Ma servlet n'est pas appelé correctement ?

  4. #4
    Rédacteur
    Avatar de benwit
    Profil pro
    dev
    Inscrit en
    Septembre 2004
    Messages
    1 676
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Septembre 2004
    Messages : 1 676
    Par défaut
    Il faut effectivement un constructeur sans argument dans MyData mais puisque tu ne l'a pas surchargé, il existe bien.

    A mon avis, le problème vient plus de l'url de ta servlet.

    As tu essayé <url-pattern>/myFirstService</url-pattern> ?

    Montres nous ton module gwt (.gwt.xml)

  5. #5
    Membre éclairé Avatar de miya
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    469
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2006
    Messages : 469
    Par défaut
    Merci pour ta réponse.

    En effet, je ne pense pas que cela provienne du constructeur, car si on n'implémente pas de constructeur, par défaut il en génère un vide.

    J'ai testé en modifiant le lien /myFirstService, et toujours la meme stack...

    Mais en lisant le code erreur, il appelle bien :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    [ERROR] <p>RequestURI=/org.oif.start.first.Application/myFirstService</p>
    Autant pour moi, j'ai omis de mettre le module gwt :
    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
     
    <!DOCTYPE module PUBLIC "//gwt-module/" "http://google-web-toolkit.googlecode.com/svn/tags/1.6.2/distro-source/core/src/gwt-module.dtd">
    <module>
     
          <!-- Inherit the core Web Toolkit stuff.                        -->
          <inherits name='com.google.gwt.user.User'/>
     
          <!--  inherit css based theme -->
          <inherits name='com.google.gwt.user.theme.standard.Standard'/>
     
          <!-- Specify the app entry point class.                         -->
          <entry-point class='org.oif.start.first.client.Application'/>
     
          <!-- Specify the application specific style sheet.              -->
          <stylesheet src='Application.css' />
     
    	<source path="client" />
     
    </module>
    J'ai essayé avec et sans le source path.

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 12
    Par défaut
    Dans ton web.xml, le servlet-mapping doit être de cette forme là:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <servlet-mapping>
    		<servlet-name>myFirstService</servlet-name>
    		<url-pattern>/application/myFirstService</url-pattern>
    </servlet-mapping>
    le "/application" avec le a en minuscule est important.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Synchroniser l'appel RPC dans GWT
    Par sabrina_sab dans le forum GWT et Vaadin
    Réponses: 5
    Dernier message: 13/02/2013, 19h57
  2. Erreur lors d'un appel RPC en utilisant gwt-sl
    Par riadhhwajdii dans le forum GWT et Vaadin
    Réponses: 1
    Dernier message: 23/02/2011, 16h14
  3. Apllication GWT et appel RPC
    Par passion_info dans le forum GWT et Vaadin
    Réponses: 2
    Dernier message: 21/11/2010, 19h18
  4. [imprimer]erreur à l'appel de window.print()
    Par banzzai dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 29/08/2006, 10h10
  5. [FPDF] Erreur après appel d'une fonction avec include
    Par orus8 dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 04/11/2005, 10h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo