• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Transfer Vector over HTTP

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 28706
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you seen this?
https://coderanch.com/t/230700/JME/Mobile/Vecrot-Object-web-Sservice
 
Yavor lvanov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28706
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic