我使用GWT RPC时出错

时间:2011-01-08 10:04:27

标签: gwt gwt-rpc asynccallback

当我使用RPC时,我遇到了Eclipse的问题。 如果我使用单个方法调用它的方向正确,但如果我添加一个新方法来处理服务器,我会收到以下错误:

com.google.gwt.core.client.JavaScriptException: (null): null
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeBoolean(ModuleSpace.java:184)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeBoolean(JavaScriptHost.java:35)
    at com.google.gwt.user.client.rpc.impl.RpcStatsContext.isStatsAvailable(RpcStatsContext.java)
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:221)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:619)

我可以在异步调用中获得更多服务吗?我哪里错了?

这是我的实现MyService:

package de.vogella.gwt.helloworld.client;

import com.google.gwt.user.client.rpc.RemoteService;

public interface MyService extends RemoteService {
    //chiamo i metodi presenti sul server

    public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann);

    public void setWeb(String userCorrect,String query, String titolo,String snippet,String url);
}

MyServiceAsync中

package de.vogella.gwt.helloworld.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface MyServiceAsync {

    void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann,AsyncCallback<Void> callback);

    void setWeb(String userCorrect,String query, String titolo,String snippet,String url, AsyncCallback<Void> callback);
}

RPCService:

package de.vogella.gwt.helloworld.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.FlexTable;

public class RPCService implements MyServiceAsync {
     MyServiceAsync service = (MyServiceAsync) GWT.create(MyService.class);
     ServiceDefTarget endpoint = (ServiceDefTarget) service;


        public RPCService()
        {
            endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "rpc");

        }


        public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann,AsyncCallback callback)
        {
            service.creaXML(nickname, pass, email2, gio, mes, ann, callback);
        }

        public void setWeb(String userCorrect,String query, String titolo,String snippet,String url,AsyncCallback callback) {

            service.setWeb(userCorrect,query, titolo,snippet,url,callback);

        }
}

MyServiceImpl

package de.vogella.gwt.helloworld.server;

import java.io.*;

import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import de.vogella.gwt.helloworld.client.MyService;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.NodeList;

public class MyServiceImpl extends RemoteServiceServlet implements MyService {
    //metodo che inserisce il nuovo iscritto
    public void creaXML(String nickname,String pass,String email2,String gio,String mes, String ann){
        .......
    }

    public void setWeb(String userCorrect,String query, String titolo,String snippet,String url) {
        .....
    }

在客户端的应用程序中我做

RPCService rpc2 = New RPCService()
rpc2.setWeb(..,...,...,...,callback);

RPCService rpc = New RPCService()
rpc.creaXML(..,...,...,...,callback); (in other posizions in the code...)

和..

AsyncCallback callback = new AsyncCallback()
{
    public void onFailure(Throwable caught)
    {
        Window.alert("Failure!");
    }

    public void onSuccess(Object result)
    {

        Window.alert("Successoooooo");


    }
}; 

Web.xml中:

<?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>

  <!-- Servlets -->

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>De_vogella_gwt_helloworld.html</welcome-file>
  </welcome-file-list>

  <servlet>
  <servlet-name>rPCImpl</servlet-name>
  <servlet-class>de.vogella.gwt.helloworld.server.MyServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
   <servlet-name>rPCImpl</servlet-name>
   <url-pattern>/de_vogella_gwt_helloworld/rpc</url-pattern>
 </servlet-mapping>

</web-app>

谢谢大家的关注

塞贝

2 个答案:

答案 0 :(得分:5)

您似乎以一种奇怪的方式调用您的RPC服务。

GWT网页中有一个tutorial,显示了应该如何做到这一点。

编辑:

在GWT错误数据库中报告的

This bug可能与您的问题有关(堆栈跟踪非常相似)。还可以找到有关该错误的一些信息here

答案 1 :(得分:1)

我丢失了通行证,我重新创建了帐户...我看到你的主板...我的浏览器网站出现问题...如果我使用Internet Explorer它工作正常,但如果我使用Firefox(我的预定浏览器)抛出异常(但编译正常)。我还没有找到任何可以解决的问题......