Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 27
Registered: ‎08-26-2009
My Device: Not Specified
Accepted Solution

Best way to send data

Hello,

 

This is more of a server side question, but I wanted to what see what the BB "best practice" is, and how the experts are handling this scenario. 

 

I am planning to use servlets to serve data via HTTP to my BB application.  I need to retrieve a list of images plus the associated name, description, dates, etc.  To sent an image from the servlet, I know I can just send it as a byte array and the BB can read it from http input stream.  What about sending the image and the data? How can I separate the bytes of the image from the bytes of the data. Can I send a collection consisting of images and associated data? 

 

What is the best way to approach this?

 

Thanks,

-T

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Best way to send data

[ Edited ]

In my experience, I get the data as one operation, which includes the URL's to the images.

 

I then queue up separate GET requests (from the client) for each image.

 

This allows me to run the image downloads "in background" while I display the list, the update the view when the image data is retrieved.

 

 

Developer
Posts: 27
Registered: ‎08-26-2009
My Device: Not Specified

Re: Best way to send data

[ Edited ]

Thanks RexDoug, for your feedback.

 

What would you suggest as a data transfer method?  Would it be a better to send it as a stream of XML or a stream of delimited string? 

 

-Edit-

Would you suggest that data be transferred via a serialized object?

 

Thanks,

-T

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Best way to send data

I agree with RexDoug's general approach.

 

Regarding how you package your data, are you talking about the image or your data or both?

 

I don't actually think there is a right answer to your question, and you will get different answers from different people on this forum.  marchywka for example woul dprobably suggest sending delimited strings, whereas i prefer XML, though the overhead can be quite hig.  I beleive that JSON is much more efficient in terms of payload compared with overhead.  Serialising an object could work, but I think XML and JSON are more flexible than that and delimited stream. 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Best way to send data

[ Edited ]

I would answer the question by asking "what does your server-side infrastructure look like?"

 

If it's dot-net, then you are probably going to want to take the path of least resistance and use JSR 172 or KSOAP.

 

If you have more flexibility on the server, I would recommend XML or JSON (as Peter says). JSON is going to be more compact, but the BB JSON tools are a little sparse.

 

On the other hand, the SAX parser libraries on the BB are pretty good for XML.

 

I would say that in every project I ever worked on, I worked around the foibles of the server infrastructure, rather than the other way around.

  

 

Developer
Posts: 27
Registered: ‎08-26-2009
My Device: Not Specified

Re: Best way to send data

I was referring to packaging the data.  As for the image, I assume I can just stream it as a byte array (unless there is a better approach?). 

 

Thank you both Peter and RexDoug for your feedback!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Best way to send data

[ Edited ]

Excellent answer RexDoug, which I could have put it that well.

 

Re image data, byte array, is fine.  However if you are attempting to send it as XML data or as POST data, then you will probably need Base64 encoding, then I think there are some characters that need to be escaped for XML or you need URL encoding for the same reason.  Sorry not an area on I am strong on, I just do what the Server boys tell me to do.....