Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getDataAccessObject failed

 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am doing the remote test currently.
The test failed.
By carefully look at debugging information, I
know that
1) The ConnectionFactory object was successfully bind with RMI registry in server.
2) The client was able to do the lookup and find the ConnectionFactory stub.
3) The client make a request (getDataAcceeObject)to get the DataAccess object using the ConnectionFactory stub.
4) The request did reach the server side.
The ConnectionFactory did return an instance
of RemoteDataAccess object
5) Client was NOT able to get the DataAccess object.
The error message was: [I use the JDK 1.4 logging]
Mar 20, 2003 12:41:11 PM suncertify.client.Client main
SEVERE: Get DataAccess object failed:error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.io.RandomAccessFile
My DataAccess and RemoteDataAccess interfaces extends Serializable. Does anybody know the reason ?
Please help me. I am really desperate.
Thanks,
John Chien
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a SecurityManager? if so remove it.
did you rmic the RemoteObject? that is needed too. and the client will need a copy of those stubs as well.
Those are my beginning suggestions.
Mark
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My RemoteDataAccessImpl implementation is:
public class RemoteDataAccessImpl implements RemoteDataAccess, Unreferenced {
private Data data = null;
public RemoteDataAccessImpl(Data data) throws IOException {
this.data = data;
}

...........
}
My ConnectionFactoryImpl's getDataAccessObject and constructor's implementation are:
public ConnectionFactoryImpl(String port) throws RemoteException, IOException {
super();
if (port == null) {
this.port = "1099";
} else {
this.port = port;
}
String dbName = getClass().getResource("../db/db.db).getPath();
database = new Data(dbName);
}
public RemoteDataAccess getDataAccessObject() throws IOException, RemoteException {
/* The database are created at constructor */
RemoteDataAccess dataAccess = new RemoteDataAccessImpl(database);

return dataAccess;
}

I use SecurityManager in client. No securityManager is server.
Besides that I have a policy file called client.policy.
The client.policy content is:
grant {
permission java.net.SocketPermission "*:1024-65535", "connect";
};

Does anybody knows why my getDataAccessObject() failed. It seems get a reference of RandomAccessFile from Data.
Should I make DataAccess or RemoteDataAccess NOT
serializable or make the RandomAccessFile in the Data class to be transient ???

Please let me know how I can fix this issue. Thanks,
John Chien
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark:
I did use rmic to generate stub for RemoteObject.
I have not jar the files yet. Besides that, I am testing in the same machine. Thus, the inclusion of not of Stub in client is irrelavent.
The commands use to run the client and server are:
In server window:
start java -classpath classes suncertify.server.Server 1099
In client window:
java -Djava.security.policy="C:\Java2_SCJD\client.policy" -classpath classes suncertify.client.Client localhost 1099
Question:
Why should I remove the SecurityManager ? Most of the RMI books recommend to use it in client side.
I know that I am NOT using class downloading. However, it seeminly nice to keep it there to demonstrate the whole concept. Beside that, the issue seems have nothing to do with SecurityManager. The RandomAccessFile is the one that cause the trouble.
Thanks,
John Chien
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark:
I did remove the SecurityManager. The result is the same. The RandomAccessFile cause the trouble.
Thanks,
John Chien
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark:
Thank you for the response.
I search the whole forum. I found that you have
the same problem on September 15, 2001.
Nobody gaves you any help at that time.
How do you get the problem resolved ?
I found the fix for my problem:
1) I took out the extends Serializable from the DataAccess and RemoteDataAccess interface.
Because I want a reference of a server object instead of a copy of it.
2) I change my RemoteDataAccessImpl to extends UnicastRemoteObject. This really fixes the problem. How can I forget to do this ??
BANG !! BANG !! [hit my head against my table.]

Thanks,
John Chien
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, good job John. Now you are learning the best tool around is the search and how to find solutions to your problems.
That is the best lesson anyone can learn. I use it all the time.
unmarshalling always has to do with serialization. It is the process of marshalling the object to pass through a Stream, basically making it a byte array. then unmarshalling is taking the Stream, reading from it the byte array, and transforming it back into the object.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic