GWT:RPC 失败(StatusCodeException)

Posted

技术标签:

【中文标题】GWT:RPC 失败(StatusCodeException)【英文标题】:GWT: RPC Failure (StatusCodeException) 【发布时间】:2011-07-26 09:41:54 【问题描述】:

在我的项目中,实现了一个 RPC 接口来在 GWT 和服务器之间进行通信,如下所述:

http://code.google.com/webtoolkit/doc/1.6/DevGuideServerCommunication.html

所有现有方法都可以正常调用,但最近我引入了一个新方法,调用它时会导致 RPC 失败:

com.google.gwt.user.client.rpc.StatusCodeException: The call failed on the server; see server log for details
    at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
    at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:254)
    at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:226)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:217)
    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:592)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.moz.MethodDispatch.invoke(MethodDispatch.java:80)
    at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
    at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1428)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
    at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:720)
    at com.google.gwt.dev.GWTShell.run(GWTShell.java:593)
    at com.google.gwt.dev.GWTShell.main(GWTShell.java:357)

(在托管模式下运行时会显示此异常堆栈跟踪)。

这是我所做的更改:

    我用新方法扩展了我的服务接口:

    @RemoteServiceRelativePath("myservice") 公共接口 MyService 扩展 RemoteService // ... Boolean isSomethingValid(String paramToCheck);

    我实现了我的方法:

    公共类 PMyServiceImpl 扩展 GWTSpringController 实现 MyService // ...

    public Boolean isSomethingValid(String paramToCheck) 
      // do something ...
    
    

    我在异步接口中添加了方法定义:

    公共接口 MyServiceAsync // ... void isSomethingValid(String paramToCheck, AsyncCallback 回调);

就是这样。我错过了什么吗?任何提示为什么会发生 RPC 失败?在我的服务器日志中,我可以看到以下异常:

[7/26/11 11:48:16:618 CEST] 0000004a WebApp        A   SRVE0181I: [myapplication.war] [/istoolset] [Servlet.LOG]: Exception while dispatching incoming RPC call: com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.Boolean com.ubs.istoolset.front.fet.gwt.businessmodel.client.service.MyService.isSomethingValid(java.lang.String)' threw an unexpected exception: java.lang.NullPointerException
        at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:360)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:546)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:164)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)
        at com.ubs.istoolset.gwt.framework.rpc.GWTSpringController.handleRequest(GWTSpringController.java:48)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:859)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1146)
        at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:593)
        at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:534)
        at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
        at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:764)
        at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
        at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:133)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:450)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:508)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:296)
        at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:270)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
        at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
        at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
        at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
        at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
Caused by: java.lang.NullPointerException
        at com.ubs.istoolset.front.fet.gwt.businessmodel.server.MyServiceImpl.isSomethingValid(MyServiceImpl.java:1906)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:618)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
        ... 27 more

非常感谢任何帮助,谢谢!

【问题讨论】:

【参考方案1】:

我不熟悉 com.ubs 命名空间(那是您的代码吗?),但是您的堆栈跟踪(服务器端)中的这个 NullPointerException 是一个问题:

Caused by: java.lang.NullPointerException
        at     com.ubs.istoolset.front.fet.gwt.businessmodel.server.MyServiceImpl.isSomethingValid(MyServiceImpl.java:1906)

那里发生了什么?

【讨论】:

以上是关于GWT:RPC 失败(StatusCodeException)的主要内容,如果未能解决你的问题,请参考以下文章

GWT - GAE 的 RPC 失败 - 在本地工作的问候示例

GWT RPC 调用失败

GWT RPC 失败调用

GWT RPC:使用其他服务实现的方法失败

如何在客户端到达 OnFailure() 之前处理 RPC 失败错误?在 GWT

GWT RPC 失败,没有错误也没有异常