1

I am currently trying to use the SyncProxy library to test services of my app, in order to do load testing with JMeter. The app works fine, I am running it on localhost.

The problem comes when I try to use SyncProxy in my JUnit tests, they fail.

Here is a piece of code used in a JUnit test :

 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);

    }

 });

I am getting the following error : IOException while receiving RPC response

I used the debug mode to find where was the problem coming from. On the server side, everything goes fine until the result is sent back to the client. The result is found in the database, but I have a mysterious 500 error.

After digging, I found that this exception is thrown (in the 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

I found a lot of threads talking about the fact that your class needs to implement "isSerializable", but what I don't understand, is that I am actually running my app on localhost, and everything is working fine, including the different services.

But when it comes to run my JUnit(s), I have those errors.

krakig
  • 1,515
  • 1
  • 19
  • 33
  • 1
    Check basics: is your class `Theme` implementing Serializable? Does it have a no-arg constructor? Also what gwt version are you using? – Andrei May 29 '17 at 17:02
  • My class `Theme` is implementing Serializable. It has a no-arg constructor, and the gwt version is the 2.6 – krakig May 30 '17 at 07:14

1 Answers1

0

Looks like you've messed up paths or classpaths resources. GWT-RPC uses some generated files, called policies to implement some sort of security mechanism (i.e. disallow certain types, etc). In your case, it looks like during tests those files become misplaced or not on the classpath.

When this happens, I usually debug through RemoteServiceServlet#getSerializationPolicy (reference related to GWT 2.8.1 and not 2.6, but I think this part didn't changed much). You'll eventually end up in RemoteServiceServlet#loadSerializationPolicy where it tries to load some files, and you'll be able to see on which paths it tries to do so and why are those files missing.

Andrei
  • 1,613
  • 3
  • 16
  • 36
  • You are right. I added a breakpoint in there, and when I test a request from my app, the strongname is equal to something like "E52F7D678A782A8A4B2A35A157692026", but when I try the service from my JUnit, the strongName is null, and there is an error, which is ignored. Those policies, how can I manage to find them from both my app and my test? – krakig May 30 '17 at 07:53
  • I don't think that strong name being null is ok; You should check this first, before worrying about the files. Strong name is being read from the client's request (see `ServerSerializationStreamReader.prepareToRead`). If that ends up as null, then maybe your client is sending bad requests, or your proxy is behaving strange. Check and see where does that strong name come as null (perhaps your proxy disallows,or does things with requests with x-gwt-rpc Content Type?) – Andrei May 30 '17 at 07:59
  • Using the SyncProxy, the following header sent to the server side is null : `X-GWT-Permutation`. And then, in the `RemoteServiceServlet`, the `serializationpolicyFilePath` is equal to "/ector/null.gwt.rpc", so I have to find why is my `strongname` null. – krakig May 30 '17 at 08:10
  • Perhaps some User-Agent troubles in your tests? Maybe whatever you're using to simulate RPC client doesn't set the correct user-agent (or any), so that GWT doesn't really know which permutation to load? – Andrei May 30 '17 at 08:24
  • Actually I found this : https://github.com/jcricket/gwt-syncproxy/issues/2. The second to last comment is the problem I have I believe – krakig May 30 '17 at 08:26
  • I managed to make it work, it was a problem with the .gwt.rpc files. – krakig May 30 '17 at 16:10