Getting 500 error from RPC call

70 views
Skip to first unread message

Neil Aggarwal

unread,
Dec 17, 2024, 6:44:06 PM (5 days ago) Dec 17
to google-we...@googlegroups.com
Now, when I call my service, I am getting this error:
500 500 The call failed on the server; see server log for details

Here is the code in my service:
public Puzzle getPuzzle(String category) {
try {
Puzzle puzzle =
(Puzzle)FileUtil.deSerialize(PathUtil.PUZZLES_DIR+"/DiagonalSlitherlink/Ch
allenging/DiagonalSlitherlink-00001-3.ser");
LogManager.getLogger(getClass()).warn("Loaded puzzle "+puzzle);
return puzzle;
} catch( Exception e ) {
LogManager.getLogger(getClass()).error(e);
return null;
}
}

My server log has this:
WARN: Loaded puzzle
com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle@3f8ef4a0

The only code after that line is the return.

Does GWT not like that I am returning a subclass which is referenced by a
superclass reference?

Thank you,
Neil

--
Neil Aggarwal, (972) 834-1565, http://www.propfinancing.com
We offer 30 year loans on single family houses!

Neil Aggarwal

unread,
Dec 17, 2024, 11:49:40 PM (4 days ago) Dec 17
to google-we...@googlegroups.com
It does not seem related to the reference being a superclass.

I added a second servlet which uses a reference to
RectangularWithDiagonalsPuzzle
directly.

@WebServlet(urlPatterns="/DiagonalSlitherlink/GetDiagonalSlitherlink")
public class GetDiagonalSlitherlinkImpl extends RemoteServiceServlet
implements GetDiagonalSlitherlink {
private static final long serialVersionUID = 1L;

public RectangularWithDiagonalsPuzzle getPuzzle(String category) {
try {
RectangularWithDiagonalsPuzzle puzzle =
(RectangularWithDiagonalsPuzzle)FileUtil.deSerialize(PathUtil.PUZZLES_DIR+
"/DiagonalSlitherlink/Challenging/DiagonalSlitherlink-00001-3.ser");
LogManager.getLogger(getClass()).warn("In DiagonalSlitherlinkImpl,
Loaded puzzle "+puzzle);
return puzzle;
} catch( Exception e ) {
LogManager.getLogger(getClass()).error(e);
return null;
}
}
}

And I see this in the server log:

WARN: In DiagonalSlitherlinkImpl, Loaded puzzle
com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle@76c929a9

Thank you,
Neil

--
Neil Aggarwal, (972) 834-1565, http://www.propfinancing.com
We offer 30 year loans on single family houses!

Jens

unread,
Dec 18, 2024, 7:33:12 AM (4 days ago) Dec 18
to GWT Users
What is the exception logged on the server that caused the HTTP 500 error?

Generally your classes and their field references must implement Serializable, have a default constructor (can be private) and should not have final fields. Is that the case for RectangularWithDiagonalsPuzzle and its super classes?

-- J.

Neil Aggarwal

unread,
Dec 18, 2024, 11:20:43 AM (4 days ago) Dec 18
to google-we...@googlegroups.com

> What is the exception logged on the server that caused the HTTP 500 error?

 

That is the problem.  I am not seeing any error on the server.

 

>  should not have final fields

 

I did not realize this limitation.  I am pretty sure there are some.

Looking at the docs, I will add transient to them.

Colin Alworth

unread,
Dec 18, 2024, 11:25:17 AM (4 days ago) Dec 18
to GWT Users
If there was a serialization error, it would be written out using your servlet container's own logging system - but your own service call could have had an error too and be written via your `LogManager.getLogger(getClass()).error(e); `. Can you confirm with your debugger that the call is being made correctly, and serializing properly? It might also make sense to deliberately throw an exception (both within and outside of your try/catch) and see where that log ends up.

Note that final fields are supported in gwt-rpc, but you need to set rpc.XserializeFinalFields to true in your .gwt.xml file:
  <set-property name="rpc.XserializeFinalFields" value="true" />

Neil Aggarwal

unread,
Dec 18, 2024, 11:55:58 AM (4 days ago) Dec 18
to google-we...@googlegroups.com

Looking at the final comment in

https://github.com/gwtproject/gwt/issues/1062#issuecomment-210347324

 

It says GWT RPC is being deprecated. 

 

Is that true?

Colin Alworth

unread,
Dec 18, 2024, 12:00:25 PM (4 days ago) Dec 18
to GWT Users
That is a very old comment, by a former Googler who didn't follow through on the various porting things that were proposed.

It also is incorrect, porting gwt-rpc to work with annotation processors is finished with the "hard parts", and is has been deployed to production for many years. It isn't perfect for all use cases, but the hard parts weren't as big of a deal as they were suspected to be.

And, it was wrong as written - final support was added a year and a half before it was written, see https://github.com/gwtproject/gwt/commit/580db4248fc38f9721d0a920cabfc2b17e10d73f.

Neil Aggarwal

unread,
Dec 18, 2024, 12:04:49 PM (4 days ago) Dec 18
to google-we...@googlegroups.com

OK, that is good to know.  It might be a good idea to add a follow-up
on that comment which clarifies that GWT RPC is not deprecated.

Colin Alworth

unread,
Dec 18, 2024, 12:05:33 PM (4 days ago) Dec 18
to GWT Users
Forgot to link the updated project: https://github.com/Vertispan/gwt-rpc/

Neil Aggarwal

unread,
Dec 18, 2024, 12:55:11 PM (4 days ago) Dec 18
to google-we...@googlegroups.com

> If there was a serialization error, it would be written out using your servlet container's own logging system

 

You are correct, it is a serialization error and it was in a different log.

 

Here is the error message:

 

Exception while dispatching incoming RPC call

com.google.gwt.user.client.rpc.SerializationException:

Type 'com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle' 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 = com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle@703902c0

 

That is a bit cryptic and does not give details on which field was causing the problem.

 

I am pretty sure I am not going to be the only person who is trying to learn
GWT and runs into it.  Can we add a warning to the GWT compiler which alerts
the user that they have a final field which could cause a problem?

Neil Aggarwal

unread,
Dec 18, 2024, 1:35:39 PM (4 days ago) Dec 18
to google-we...@googlegroups.com

> Note that final fields are supported in gwt-rpc, but you need to set rpc.XserializeFinalFields to true in your .gwt.xml file:

>   <set-property name="rpc.XserializeFinalFields" value="true" />

 

I set that property, but I am still getting this serialization error:

 

Exception while dispatching incoming RPC call

com.google.gwt.user.client.rpc.SerializationException:

Type 'com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle' 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 = com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle@23a80ce8

 

Is there a way to find out more specifically what GWT RPC does not like about
my class?

Neil Aggarwal

unread,
Dec 18, 2024, 4:48:49 PM (4 days ago) Dec 18
to google-we...@googlegroups.com

I wrote a very simple class:

 

package com._3dmathpuzzles.slitherlink;

 

import java.io.Serializable;

 

public class TestPuzzle implements Serializable {

  private static final long serialVersionUID = 1L;

 

  /** Constructor */

  public TestPuzzle() {

    super();

  }

}

 

And updated my RPC call to use it and I still get this:

 

Exception while dispatching incoming RPC call

com.google.gwt.user.client.rpc.SerializationException:

Type 'com._3dmathpuzzles.slitherlink.TestPuzzle' 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 =

com._3dmathpuzzles.slitherlink.TestPuzzle@40a58058

 

I am not sure what to do about this.  My class implements Serializable
and has a no-arg constructor.

Colin Alworth

unread,
Dec 18, 2024, 4:57:55 PM (4 days ago) Dec 18
to GWT Users
You're triggering the LegacySerializationPolicy... we should make that clearer when it happens.

This occurs when your <hash>.gwt.rpc policy file wasn't present on the server (or wasnt at the expected path). Legacy serialization is much more strict in what it will accept.

Generated policy files ensure that the server and client agree on what can be serialized. This file is generated into the same directory as your .nocache.js file, and should be available on the server if running in production. If running with super dev mode and a separate server, you can direct the server to download the current policy file from SDM by specifying system property gwt.codeserver.port with the localhost port to the SDM server. Be sure to reload the server application or hot reload classes if they change, so that the server side classes match the client (and the client's policy file).

Neil Aggarwal

unread,
Dec 18, 2024, 5:45:23 PM (4 days ago) Dec 18
to google-we...@googlegroups.com
You're triggering the LegacySerializationPolicy... we should make that clearer when it happens.

This occurs when your <hash>.gwt.rpc policy file wasn't present on the server (or wasnt at the expected path). Legacy serialization is much more strict in what it will accept.

I saw a warning about that in the log but not know what it meant. 
I am serving the client side files from Apache and the server side files from Tomcat so they are separate.

Where does the server side code expect the .gwt.rpc file to be?

Colin Alworth

unread,
Dec 18, 2024, 9:11:35 PM (4 days ago) Dec 18
to GWT Users
The server expects the client to tell it where the file should be, and the client reports that the file should be in the same directory as its .nocache.js file - we call that the "base directory" of a gwt application.

RemoteServiceServlet.getSerializationPolicy is responsible for looking this up, based on the incoming request, and the expected name of the generated file (according to the client). If using SDM and a port provided as I mentioned, this method will defer to getCodeServerPolicyUrl() if no policy file was found on the server itself. Otherwise, you'll see the warning you mentioned.

Neil Aggarwal

unread,
Dec 18, 2024, 11:06:41 PM (3 days ago) Dec 18
to google-we...@googlegroups.com

I see this in the log:

 

com._3dmathpuzzles.play.server.GetPuzzleServiceImpl: ERROR: The module path requested, /play/DiagonalSlitherlink/, is not in the same web application as this servlet, /3dmp.  Your module may not be properly configured or your client and server code maybe out of date.

 

Looking at the source code for RemoteServiceServlet, I see that it wants the module path to start with the
webapp context, but it does not match in my setup.

 

Is there a way to override the behavior, maybe load it manually or
something?

 

I see a method putCachedSerializationPolicy but it is private.

Neil Aggarwal

unread,
Dec 18, 2024, 11:22:01 PM (3 days ago) Dec 18
to google-we...@googlegroups.com

> The server expects the client to tell it where the file should be, and the client reports that the file should

> be in the same directory as its .nocache.js file

> we call that the "base directory" of a gwt application.

 

I decided to stop fighting with GWT and moved the module from Apache
to Tomcat.  The test RPC started working once I did that.

 

I changed the code to try to retrieve my DiagonalSlitherlink puzzle, but it
it is giving me an error.  I am investigating.

 

Thanks for the help!

Jens

unread,
Dec 19, 2024, 4:22:13 PM (3 days ago) Dec 19
to GWT Users

I decided to stop fighting with GWT and moved the module from Apache
to Tomcat.  The test RPC started working once I did that.

Given your error message it seems that you use Apache to access your application via /play but your server application is deployed on context root /3dmp. The default implementation to lookup the policy file checks if /play starts with /3dmp so it can strip of the common path prefix and have a relative path on the server to loookup the file. 

Because you have different paths from client and server perspective that check fails and you have to override RemoteServiceServlet.doGetSerializationPolicy() to load the file yourself.

Directly accessing the app via Tomcat or reconfiguring Apache (or the context root of your server app) to make the path stay the same would make it work without overriding the method above.

-- J.



 

Neil Aggarwal

unread,
Dec 19, 2024, 5:19:05 PM (3 days ago) Dec 19
to google-we...@googlegroups.com

> Given your error message it seems that you use Apache to access your application via /play but your

> server application is deployed on context root /3dmp

 

Yes, that is exactly what was causing GWT to be unhappy.

I moved the GWT module into Tomcat and now it is much happier.

 

Thank you,

Reply all
Reply to author
Forward
0 new messages