Had to get my hands dirty to figure this one out. Here's how I got
around these exceptions.
1. First, on the client side. Instead of calling
testService.sendTestData(new TestData(), sendTestDataCallback); I
did the following:
String content = ServiceUtils.marshallTestServiceObject(new
TestData());
testService.sendTestData(content, sendTestDataCallback);
where marshallTestService looks like this:
public static String marshallTestServiceObject(Object obj) {
String content = null;
SerializationStreamFactory factory = GWT.create(TestService.class);
SerializationStreamWriter writer = factory.createStreamWriter();
try {
writer.writeObject(obj);
content = writer.toString();
} catch (SerializationException se) {
content = null;
}
return content;
}
That successfully sent the object to the server side.
2. On the server side I had to create my own
AbstractSerializationStreamReader and call it as follows:
CustomSerializationStreamReader reader = new
CustomSerializationStreamReader(
Thread.currentThread().getContextClassLoader(), null);
try {
reader.prepareToRead(content);
TestData testData = (TestData)reader.readObject();
// viola, I have the testData instance
} catch (SerializationException se) {
se.printStackTrace();
}
Before I created a custom string reader I tried to use the
ServerSerializableStreamReader. This did not work because of the
following line of code:
Constructor<?> constructor =
instanceClass.getDeclaredConstructor();
That line of code essentially makes the following call:
System.getSecurityManager() .checkMemberAccess(TestData.class.getDeclaredConstructor().getClass(),
Member.DECLARED);
Unfortunately, when Tomcat is running with a security manager,
this call causes an AccessControlException because we can only see
Member.PUBLIC. So...Long story short. My
CustomSerializableStreamReader simply calls Constructor.newInstance(),
which does the trick. I know that my default ctor exists and is
public so this worked for me.
I hope somebody is able to find this useful. Especially if you run
your app on GoDaddy and need reflection.
-Eric