Forums Register Login

Passing System property

+Pie Number of slices to send: Send
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?

Thanks in Advance,
Regards,
Hari
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Hari --

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.
+Pie Number of slices to send: Send
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 ]
Do not set lab on fire. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 962 times.
Similar Threads
Sending serialized object with JavaMail
Why Object needs to be serialized while sending it over network
accessing property file in servlet
synchronization of serialized object between application instances
Converting Object to String
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:12:07.