RPC上的GWT序列化

时间:2012-07-17 11:26:43

标签: java gwt serialization rpc

即使经过大量的博客,我也找不到解决这个问题的方法。

  1. 是的,我的模型(POJO)实现了Serializable(也尝试使用IsSerializable)
  2. 我之前使用RPC获得了成功,但我不知道为什么我现在收到此错误:

    com.google.gwt.user.client.rpc.StatusCodeException: 500 The call failed on the server; see server log for details
        at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
        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(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        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:213)
        at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Unknown Source)
    

  3. 服务器堆栈跟踪:

    Starting Jetty on port 8888
            [WARN] Exception while dispatching incoming RPC call
            com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract com.project.package.gwt.shared.User com.project.package.gwt.client.ProService.loginServer(java.lang.String,java.lang.String)' threw an unexpected exception: java.lang.NullPointerException
        at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
        at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
        at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
        at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
        at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
        at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
        at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
        Caused by: java.lang.NullPointerException
        at com.project.package.gwt.server.ProServiceImpl.loginServer(ProServiceImpl.java:85)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
        ... 22 more
    

    我也不能通过电线串行化字符串吗?

    显示空指针异常,因为RPC不是成功的。如果RPC成功,我希望返回一个对象

    添加源代码

    com.project.package.gwt.server.ProServiceImpl.loginServer.java
    
    public User loginServer(String uname, String password) {
    
        System.out.println("Making User Login Call to the server");
        System.out.println("Username is : "+uname+" Password is : "+password);
    
        return loginObj.validateLogin(uname, password);
    }
    

    验证登录方法,验证用户

    public User validateLogin(String username, String password) {
    
        System.out.println("Inside Server/");
        //ApplicationContext ac = new ClassPathXmlApplicationContext("jdbc-context.xml");
        ApplicationContext ac = new ClassPathXmlApplicationContext("jdbc-context.xml");
        DataSource dataSource = (DataSource) ac.getBean("dataSource");
    
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    
        System.out.println("Inside Server/Login Handler");
    
        String result = null;
        String query = "SELECT emp_name FROM emp_name = ? AND emp_password = ?";
    
        try {
            result = jdbcTemplate.queryForObject(query, String.class);
        } catch (EmptyResultDataAccessException e) {
            // TODO: handle exception#
            e.printStackTrace();
        }
    
        if (result == null) {
            System.out.println("The result of the SQL query is null");
        } else {
            System.out.println("The result of the SQL query is " + result);
            user.setUsername(result);
        }
        return user;
    }
    
    }
    

    控件不在验证登录方法内(Inside Server /不打印),这意味着我的RPC失败,因此是NPE

2 个答案:

答案 0 :(得分:3)

99%的loginObj为空。请确保它是真的。

System.out.println(loginObj == null);
return loginObj.validateLogin(uname, password);

并向我们提供ProServiceImpl.java源代码的第85行。我们能等多久?

答案 1 :(得分:0)

你有一个java.lang.NullPointerException 在com.project.package.gwt.server.ProtasServiceImpl.loginServer(ProtasServiceImpl.java:85)

您需要确定造成这种情况的原因。