1

我目前正在尝试使用该SyncProxy库来测试我的应用程序的服务,以便使用 JMeter 进行负载测试。该应用程序运行良好,我在本地主机上运行它。

当我尝试在我的 JUnit 测试中使用 SyncProxy 时,问题就出现了,它们失败了。

这是 JUnit 测试中使用的一段代码:

 ThemeServiceAsync themeServiceAsync = (ThemeServiceAsync) SyncProxy
          .newProxyInstance(ThemeServiceAsync.class, MODULE_BASE_URL, GET_THEMES_SERVICE_NAME);

 themeServiceAsync.getListTheme(codeEfs, codeSI, noStr, statut, new AsyncCallback<List<Theme>> (){

    @Override
    public void onFailure(Throwable arg0) {
        // TODO Auto-generated method stub
        System.out.println(arg0);
    }


    @Override
    public void onSuccess(List<Theme> result) {
        // TODO Auto-generated method stub
        System.out.println(result);

    }

 });

我收到以下错误:IOException while receiving RPC response

我使用调试模式来查找问题出在哪里。在服务器端,一切正常,直到结果被发送回客户端。结果在数据库中找到,但我有一个神秘的500错误。

经过挖掘,我发现抛出了这个异常(在AbstractRemoteServiceServlet):

com.google.gwt.user.client.rpc.SerializationException: Type 'net.gicm.ector.shared.beans.Theme' was not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' and did not have a custom field serializer.
For security purposes, this type will not be serialized.: instance = net.gicm.ector.shared.beans.Theme@1b7cb71

我发现很多线程都在谈论您的类需要实现“isSerializable”这一事实,但我不明白的是,我实际上是在 localhost 上运行我的应用程序,并且一切正常,包括不同的服务。

但是在运行我的 JUnit 时,我遇到了这些错误。

4

1 回答 1

0

看起来你搞砸了路径或类路径资源。GWT-RPC 使用一些生成的文件,称为策略来实现某种安全机制(即禁止某些类型等)。在您的情况下,看起来在测试期间这些文件被放错地方或不在类路径上。

发生这种情况时,我通常调试通过RemoteServiceServlet#getSerializationPolicy(参考 GWT 2.8.1 而不是 2.6,但我认为这部分并没有太大变化)。您最终将RemoteServiceServlet#loadSerializationPolicy到达它尝试加载某些文件的位置,并且您将能够看到它尝试在哪些路径上加载以及为什么这些文件丢失。

于 2017-05-30T07:29:33.453 回答