Hi, I have a application "A" running. It is a swing based application. I have a object say UserInfoObject which is serializable. My application "A" can launch another application say "B" in a seperate JVM. But i need to pass this UserObject as serialized string. I mean "A" will serialize UserInfoObject and should send it to "B" without storing the serialized object in a file. So i tried to send it as a System property through command line while invoking "B" application. But it didn't work. Is there anyother way of setting the serialized string of UserInfoObject as system property of serializing to file is the only way to do that?
Hari, I am not sure I am understanding what you want to do, but I will give it a shot.
First, serialization in RMI does not imply writing an object to a file, but to write it to a byte stream that is ultimately transmited through a underlying socket to the network.
Therefore, if you want to transmit a serializable object as a parameter or as a return type to or from your remote server, all you have to do is to declare it in the method signature of your remote interface.
For instance, if you wanted to transmit a String and Date is as simple as:
Then in your implementation of the remote interface use the objects:
Be careful, and consider that these serializable objects will be passed by-value by the RMI system.
Hello Edwin, Thnx for the instant reply. Both of the applications doesn't deal with RMI. Both are simple applications(GUI based). Both the application "A" and "B" should be launched in individual JVM. "A" launches "B" using Runtime.exec() method.The UserInfoObject is highly sensitive(has password) i dont want to pass it without serializing thru -D option in the command line. More over both the application will be launched in the same machine so RMI is a huge cost. Hope you understood the problem very well now.?
Regards, Hari [ October 24, 2006: Message edited by: Hari GM Prasaanth ]
If you want two independent applications, running in different virtual machines, to communicate, the common choices are either by sockets or RMI.
Now, what you want to do is simply launching another application through Runtime.exec(). Therefore I believe this question should not be for this forum and you might get better help, probably in the Java Intermediate or Advance Forums.
As far as I am concerned you cannot pass any kind of object in the command line, all you can pass are Strings. Therefore you will probably have to implement another communication mechanism. [ October 24, 2006: Message edited by: Edwin Dalorzo ]
Ernest Friedman-Hill
,
author and iconoclast
staff
The serialized data is, in general, going to contain all sorts of inconvenient characters, including quotes, dashes, spaces, and newlines, as well as 0 (ASCII nul) bytes and other fun things; therefore you'll have to encode the data to fit it into a system property. On top of that, most OSs have a limit on command-line length, so if it's a big serialized object, this won't work anyway.
But if the data is small enough, encode it using, say java.net.URLEncoder before passing it on the command line, and decode it in the new app in the same way. That ought to work.
Now that Ernest suggests this, I think that it might work if you serialize the object into a byte array and then convert it to a Base64 String and pass it as String parameter.
Since Base64 Strings contain just ASCII characters this should help to solve the problem that Ernest just mentioned. Of course, this won't prevent that the String is rejected if it is too long as was mentioned previously. [ October 24, 2006: Message edited by: Edwin Dalorzo ]
Post by:autobot
Do not set lab on fire. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards