GWT:响应无法反序列化 [英] GWT: The response could not be deserialized

查看:134
本文介绍了GWT:响应无法反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用GWT(2.4)并集成了Spring,步骤/rel =noreferrer>文章。我有从数据库中获取用户列表(Hibernate)的问题,并用它填充DataGrid。当我调用 greetingService.allUsers()方法时,出现错误( onFailure()):

I'm using GWT (2.4) with Spring integrated as in this article. I have problem with getting list of User from database (Hibernate) and populate DataGrid with it. When i call greetingService.allUsers() method, I'm getting error (onFailure()):


com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException:
响应无法反序列化

com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: The response could not be deserialized

有人帮忙吗?下面的一些代码段。完整的工作项目此处

Anybody helps with that? Below some pieces of code. Full working project is here.

  public void onModuleLoad() {
    // ...
    greetingService.allUsers(
        new AsyncCallback<List<User>>(){
            @Override
            public void onFailure(Throwable caught) {
                caught.printStackTrace();
            }
            @Override
            public void onSuccess(List<User> result) {
                GWT.log("SIZE: "+result.size());
                dataGrid.setRowData(result);
            }
        }
    );
    // ...
 }

GreetingServiceImpl

GreetingServiceImpl

@Override
public List<User> allUsers() {
    return userDAO.findAll();
}

用户

@Entity
@Table(name = "users")
public class User implements Serializable, IsSerializable {

    @Id
    private Long id;

    // only Strings and one Date
    private String login;
    private String password;
    private String firstname;
    private String lastname;
    private Date date;
}


推荐答案

我通过更新解决了我的问题 GwtRpcController 根据这个。现在反序列化运行良好,不使用任何传输对象。在$ GwtRpcController 下面。

I solved my problem by updating GwtRpcController according to this. Now deserialization works good without using any transfer object. Working GwtRpcController below.

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.ServletContextAware;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RPC;
import com.google.gwt.user.server.rpc.RPCRequest;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class GwtRpcController extends RemoteServiceServlet implements
        Controller, ServletContextAware {

    private static final long serialVersionUID = 1L;

    private ServletContext servletContext;

    private RemoteService remoteService;

    private Class remoteServiceClass;

    public ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        super.doPost(request, response);
        return null;
    }

    @Override
    public String processCall(String payload) throws SerializationException {
        try {

            RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass, this);
            onAfterRequestDeserialized(rpcRequest);

            // delegate work to the spring injected service
            return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters(), rpcRequest.getSerializationPolicy());
        } catch (IncompatibleRemoteServiceException ex) {
            getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
            return RPC.encodeResponseForFailure(null, ex);
        }
    }

    @Override
    public ServletContext getServletContext() {
        return servletContext;
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    public void setRemoteService(RemoteService remoteService) {
        this.remoteService = remoteService;
        this.remoteServiceClass = this.remoteService.getClass();
    }

}

这篇关于GWT:响应无法反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆