我使用 GWT RPC 时出错

发布于 2024-10-11 10:27:13 字数 7440 浏览 2 评论 0原文

当我使用 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>

谢谢大家的关注

Sebe

I have a problem with Eclipse when I use an RPC..
If I use a single method call it's all in the right direction but if I add a new method to handle the server I get the following error:

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)

Can I have more services in an asynchronous call right? Where am I wrong?

This is my implementation 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) {
        .....
    }

In the app in client-side I do

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

and

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

and..

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>

Thank you all for your attention

Sebe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗酒趁年少 2024-10-18 10:27:13

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

GWT 网页中有一个教程,展示了这应该如何完毕。

编辑:

此错误 GWT bugs 数据库中报告的可能与您的问题有关(堆栈跟踪非常相似)。有关该错误的一些信息也可以在此处找到。

You seem to be invoking your RPC services in a strange way.

There is a tutorial in GWT web page showing how this should be done.

EDIT:

This bug reported in GWT bugs database may be related to your problem (the stack trace is very similar). Some information about the bug can be also found here.

伪装你 2024-10-18 10:27:13

我丢失了我的通行证,我重新创建了帐户...我看到了你的板...这是我的浏览器网络的问题...如果我使用 Internet Explorer,它工作正常,但如果我使用 Firefox(我的预定浏览器)会抛出异常(但它编译得很好)。我还没有找到任何可以修复它的东西......

I lost my pass and I recreate the account... I see your board..it's a problem with my browser web... If I use Internet Explorer it work fine, but If I use Firefox (my predefinite browser) throw the exception (but It compile fine). I have not found anything that I can fix it...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文