Link to home
Start Free TrialLog in
Avatar of Shweta
Shweta

asked on

How to send a File, bundled in ValueObject, from Swing Client to EJB?

Hi Folks,

One suggestion/help reqrd .
My friend has a client/server architecture . Client is in Swings running in
windows and server is in EJB running in Unix .
He is making a session bean call from client to server .
Problem is he needs to send a file to server from client .
 With the existing architecture he is sending all the information from clinet to
server after filling up a value object . (for Ex value object contains all
the attributes to be sent to server.).
Now he needs to send a file to server after bundling it into Value Object .
He tried sending a File object that does not work .
What is the way he sends a File to Server bundled in the ValueObject? Or should he follow some other method?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another way is to use a MDB send the file in pieces and then reassemble it
Avatar of Shweta
Shweta

ASKER

Hi CEHJ,

 In current architecture it's a Swing Client, sending the file to a Session EJB. The file will be of huge size as it contains millions of records in it... It's a good idea to divide the file and send.. but is it not difficult to use this approach with ValueObject? I mean how to send a file chunk object in Value Object ?

Thanks,
Shweta
>>I mean how to send a file chunk object in Value Object ?

This would simply be a wrapper of byte[]. You may need a chunk number as well
How do you currently send the vo?
hi , if you send files as byte[] then there is a prob. byte[] can hold max of Integer.MAX_VALUE so if the file is large then we can not store it in a single byte[] .
>>if the file is large then we can not store it in a single byte[] .

Naturally i'm not suggesting sending the whole file in one array ;-)
Avatar of Shweta

ASKER

currently we are bundling all the infos to respective attributes and sending it to server by a session bean call. so if i add another attribute for file content in my VO and if i want to split it it is a problem. since my VO will be one nd my file contentattibute is inside my VO.
As already suggested add a byte[] instance variable and asign the bytes there. Then send the vo with the byte[] variable. Repeat more times if the byte array can't hold all the info of your value object. YOu will just need a few more trips to the server and back.
Avatar of Shweta

ASKER

ya, may be that is what I have to do . any other suggetions welcome.
Try to arrange things so that you're calling a method on your EJB that only sends the file bytes
You could always open a SocketChannel or a Socket and send the whole file (without wrapping it up in a vo) byte by byte or in a buffer. But this will require additional code in both the server and client side.
Avatar of Shweta

ASKER

yes i may have consider that option of sending byte[] in a batches. in this case one more thing i need to makesure is that i receive all the packets.. anyways i will consider this approach . all of you thanks for helping.
Please let us know how you are getting on :)
>>in this case one more thing i need to makesure is that i receive all the packets.. anyways i will consider this approach

That's why i suggested sending a packet number as well earlier:

>>You may need a chunk number as well
Avatar of Shweta

ASKER

ok .  will try that
you don't actually need a packet number, all the blocks will get delivered. You just need to include an indicator into your protocol to indicate the last block.
This is a multiple account problem, I guess - Shweta, raghava_dg.

https://www.experts-exchange.com/questions/21083663/sending-file-to-server.html

Shweta/ Raghava - whatever your name is - this is illegal as per the member agreement. Pls post back clarifying on this page if you're using two accounts or not, or I will tell the moderators.
Avatar of Shweta

ASKER

nop , my frnd asked this qtn to me . so i posted this qtn here . if u think logically there is no point in posting the same qtn to the group with 2 id's . coz the solutions given by the members will be same for both qtn .
I definitely see a logical point there - that is to use the points from both accounts - that is what some people do when they run out of question-points. The question which you've posted is exactly the same as the one posted by Raghava - word to word.
Avatar of Shweta

ASKER

did u noticed one more logical point? . if a person is using 2 accounts and if he posts same qtn frm 2 accounts he end up giving points in both accounts for same qtn. :)
Well, if you had understood what I meant - he gives points from 2 accounts, not from one. And that is not a loss. Anyway, I guess anyway will contact you.
>> anyway will contact you

*someone will contact you.
That would not work because:

>> The file will be of huge size as it contains millions of records in it...

Accept his third comment:

"This would simply be a wrapper of byte[]. You may need a chunk number as well"
Ooh. The third comment was better.
Not really, a chunk number is unnecesary
Yeah, but the chunk number thing is just an idea in that comment as he uses 'you "may"'. Also:

>> This would simply be a wrapper of byte[]

Another one also says:

>> Naturally i'm not suggesting sending the whole file in one array ;-)

The first comment which was accepted definitely does not suit the situation because a mere byte[] array is not enough for this case, as mentioned by the asker ;-) so I thought accepting the other comment would be better.