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
New Developer
letitbe
Posts: 11
Registered: ‎02-17-2009
Accepted Solution

stuck with http response 302

[ Edited ]

Hi all,

 

I'm currently developing an audio streaming software application. It works by first authenticating with the audio website's authentication API. Then after receiving the session information I can request for each individual audio files. Now the trick is that the url to each of the audio file is to be only requested/accessed once only, after the first access, the ticket is expired immediatelly, and then one can only access other files within the same session.

 

What I'm trying to do here is to first download and buffer each of the audio file, given the valid urls. I am using tcp connection here because the audio files can be quite large(3-5 megs). (by including ";deviceside=true" in url) The problem comes when I change the connection from ready state to open state by either opening the input stream or getting the response code. The piece of code I used is:

 

String location = url+";deviceside=true";
HttpConnection s = (HttpConnection) Connector.open(location);
System.out.println("Response Code: "+s.getResponseCode());
System.out.println("Response Message: "+s.getResponseMessage());
long length = s.getLength();
InputStream in = s.openInputStream(); //open stream

byte[] data = new byte[256];
DataBuffer db = new DataBuffer();
int chunk = 0;
while (-1 != (chunk = in.read(data))) {
db.write(data, 0, chunk);
}
in.close();
s.close();
data = db.getArray();
// data is always empty for some reason

 

The response code I get is always 302 "Found", but when i open the input stream, the stream is empty. I have tried copying the individual url's for each audio file and then paste into my firefox, the files can be downloaded without a problem. The audio file would also stream fine from File>openURL in Windows Media Player. The url of the individual audio file is of the format "http://play.audiowebsite.com/user/df98sdfdf98sdfdf98sdfdf98sdf1234.mp3". One thing I've observed is that when I try to open the url in firefox, it asks me if I want to download from http://s14.audiowebsite.com/, which to me means that it has redirected me to one of its servers.

 

How can I download these files from my application in BlackBerry. I have been trying to solve this problem for the past 5 days, and have made very little progress. I've searched every corner of this forum. This is my last resort. All helps are appreciated.

 

I'm using JDE4.7 and 8820 simulator
Message Edited by letitbe on 02-17-2009 11:48 PM
Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008

Re: stuck with http response 302

[ Edited ]

As I recall most of the really good media tools only run on linux ( these are largely thought of

as hacking tools ). This problem however is probably straight http.

If you are stuck on windoze, get cygwin and use things like wget to test your server.

Or, go to ietf.org and find out what a 302 response is supposed to mean.  Note this gets complicated

when some wireless sites do clever things like respond with cookies too etc.

 

In this case,

 

 

$ wget -O ~/xxx -S -v "http://play.audiosite.com/user/df98sdfdf98sdfdf98sdfdf98
sdf1234.mp3"
--06:58:00--  http://play.audiosite.com/user/df98sdfdf98sdfdf98sdfdf98sdf1234.mp
3
           => `/xxx'
Resolving play.audiosite.com... 63.119.44.197
Connecting to play.audiosite.com[63.119.44.197]:80... connected.
HTTP request sent, awaiting response...
 1 HTTP/1.1 302 Found
 2 Date: Wed, 18 Feb 2009 11:51:07 GMT
 3 Server: Apache/2.2.3 (CentOS)
 4 Set-Cookie: COOKIE=10.5.16.253.1234957867765295; path=/
 5 Location: http://play.audiosite.com/
 6 Content-Length: 64
 7 Vary: Accept-Encoding,User-Agent
 8 Cartoon: aalander3
 9 Connection: close
10 Content-Type: text/html; charset=UTF-8
Location: http://play.audiosite.com/ [following]
--06:58:01--  http://play.audiosite.com/
           => `/r/xxx'
Connecting to play.audiosite.com[63.119.44.197]:80... connected.
HTTP request sent, awaiting response...
 1 HTTP/1.1 200 OK
 2 Date: Wed, 18 Feb 2009 11:50:52 GMT
 3 Server: Apache/2.2.3 (CentOS)
 4 Vary: Accept-Encoding,User-Agent
 5 Cartoon: aalander5
 6 Connection: close
 7 Content-Type: text/html; charset=UTF-8

    [ <=>                                 ] 27,674        --.--K/s

06:58:01 (263.92 MB/s) - `/ho/xxx' saved [27674]


$

 

Message Edited by marchywka on 02-18-2009 06:53 AM
Please use plain text.
New Developer
letitbe
Posts: 11
Registered: ‎02-17-2009

Re: stuck with http response 302

Thanks, the problem is solved.

 

I tried your approach using wget, and saw the response header, which had the new(redirected)link. Then I searched the forum again, and saw Mark's post in http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=12731&query.id=38...

 

I then used HttpConnection.getHeaderField("Location") to get the correct link.

 

It's such a relief to have this problem solved.

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008

Re: stuck with http response 302

Do you need the cookie of other stuff?
Please use plain text.
New Developer
letitbe
Posts: 11
Registered: ‎02-17-2009

Re: stuck with http response 302

No, actually the only information stored in the header was the location. Download didn't require any additional information.
Please use plain text.