File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes Transfer Vector over HTTP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Transfer Vector over HTTP" Watch "Transfer Vector over HTTP" New topic
Author

Transfer Vector over HTTP

Yavor lvanov
Greenhorn

Joined: Mar 15, 2007
Posts: 14
Hi,

I need to transfer a vector over an HTTP response message. I am not sure how exactly I can achieve that. Here is a sample code I wrote where I got stuck:




If we assume the 'someURL' returns a Vector, you can notice the 'data' byte array holds it. Any ideas how to construct it out of the byte array?

Thanks!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Have you seen this?
http://www.coderanch.com/t/230700/JME/Mobile/Vecrot-Object-web-Sservice


Customer surveys are for companies who didn't pay proper attention to begin with.
Yavor lvanov
Greenhorn

Joined: Mar 15, 2007
Posts: 14
Thanks for the reply. I'm working on a RESTful application, however, I don't like the solution of streaming back a string containing several other strings, and then trying to read that on the client. For my application it's more practical to return a Vector containing a dynamic number of elements of different types. I know there is a soultion, however, I am struggling a bit with its implementation.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

REST has the advantage of small overhead and ease of implementation, but if you're looking at a heterogeneous collection of binary objects, it's more likely you'd either want Java serialized data or something like SOAP.

Java serialized data tends to be incompatible between different Java implementations, so it's usually not good to use with mobile devices.

SOAP can encapsulate all sorts of things, but of course it's fairly high overhead.
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Yavor, I think you would be pleasently suprised about how efficient and easy REST is from a mobile developers standpoint. That said, you could expand the use of the DataInput/DataOutput streams.

Lets use a vector of strings as an example. On the server side you could 1) write the number (vector size) of strings using dos.writeInt, 2) loop through the vector writing each string with dos.writeUTF. On the client site you would 1) read the number of strings with dis.readInt, 2) loop for "the number of strings" interations reading a string each iteration with dis.readUTF.

You can use similar logic to write structured data or other complex objects, but you may find REST more extensible and benefit from its platform independence.


Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transfer Vector over HTTP
 
Similar Threads
Problem with servlet running on linux.
HTTP connection thread problem to SERVLET on APACHE
Networking question from Jonathan Knudsen - Beginning J2ME..
Networking question from Jonathan Knudsen - Beginning J2ME..
Struts 2 and Java ME (HttpConnection)