[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

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?
0
Shweta
Asked:
Shweta
  • 7
  • 7
  • 6
  • +3
1 Solution
 
CEHJCommented:
You could send a file as a byte[]
0
 
CEHJCommented:
Another way is to use a MDB send the file in pieces and then reassemble it
0
 
ShwetaAuthor Commented:
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
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
>>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
0
 
girionisCommented:
How do you currently send the vo?
0
 
raghava_dgCommented:
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[] .
0
 
CEHJCommented:
>>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 ;-)
0
 
ShwetaAuthor Commented:
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.
0
 
girionisCommented:
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.
0
 
ShwetaAuthor Commented:
ya, may be that is what I have to do . any other suggetions welcome.
0
 
CEHJCommented:
Try to arrange things so that you're calling a method on your EJB that only sends the file bytes
0
 
girionisCommented:
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.
0
 
ShwetaAuthor Commented:
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.
0
 
girionisCommented:
Please let us know how you are getting on :)
0
 
CEHJCommented:
>>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
0
 
ShwetaAuthor Commented:
ok .  will try that
0
 
objectsCommented:
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.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
This is a multiple account problem, I guess - Shweta, raghava_dg.

http://www.experts-exchange.com/Programming/Programming_Languages/Q_21083663.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.
0
 
ShwetaAuthor Commented:
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 .
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
ShwetaAuthor Commented:
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. :)
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> anyway will contact you

*someone will contact you.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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"
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Ooh. The third comment was better.
0
 
objectsCommented:
Not really, a chunk number is unnecesary
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 7
  • 7
  • 6
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now