J.R.
J.R.

Reputation: 6049

Blackberry JDE HTTPConnection problems

So, I'm using the HTTPConnection Class, like so:

HttpConnection c = 
    (HttpConnection)Connector.open("http://147.117.66.165:8000/eggs.3gp");

Following what LOOKS like the right way to do things in the Blackberry JDE API.

However, my code crashes if I try to do just about anything with the variable 'c'.

.getType()
.getInputStream()
.getStatus()

all cause it to crash.

I can, however get the URL from it, and I can look at the variable 'c' itself to know that it did, in fact, get created.

Did I manage to create a broken Connection? Do I need to do something else to actually do things with the connection? Under what circumanstances will this happen (I know the link is good, I can use the blackberry's browser to visit it).

Am I just using HttpConnection wrong? How would I do things correctly?

Upvotes: 2

Views: 1576

Answers (4)

Richard
Richard

Reputation: 8920

The API documentation for HttpConnection suggests the first call should be to c.getResponseCode(), try that.

Upvotes: 1

DFTR
DFTR

Reputation: 869

You should find everything you need in my blog post "An HttpRequest and HttpResponse library for BB OS5+"

And for invoking media within your application you can do either a browser invokation or directly from app. You would probably be best to use the browser like so:

BrowserSession invokeHighQuality = Browser.getDefaultSession(); 
invokeHighQuality.displayPage("URL goes here");

OR you can try this:

// CHAPI invocation
            Invocation invoke = new Invocation(_data.getUrl(), null, BlackBerryContentHandler.ID_MEDIA_CONTENT_HANDLER, false,
                    null);
            try {
                Registry.getRegistry(YourAppClass.class.getName()).invoke(invoke);
            } catch (Throwable t) {

            }

Upvotes: -1

J.R.
J.R.

Reputation: 6049

I figured out what was wrong by finding some sample code that was using HttpConnection, (at least, I think I did, at least, I can access all those variables, now). Before, I wasn't ever casting it as a "Stream Connection" (the examples I saw had it cast from Connector to HTTPConnection).

StreamConnection s = null;
s = (StreamConnection)Connector.open("http://10.252.9.15/eggs.3gp");
HttpConnection c = (HttpConnection)s;                        
InputStream i = c.openInputStream();
System.out.println("~~~~~I have a connection?~~~~~~" + c);
System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
System.out.println("~~~~~I have a type?~~~~" + c.getType());
System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());
System.out.println("~~~~~I have a stream?~~~~~~" + i);
player = Manager.createPlayer(i, c.getType());

Even though the stream is now successfully being created, I'm still having problems USING it, but that might be because my connection is so slow.

Upvotes: 1

Marc Novakowski
Marc Novakowski

Reputation: 45398

What error is it throwing when it crashes? You may want to try adding the "Connector.READ_WRITE" as a second argument to your open call - even if it's just a "read only" connection like a GET, some OSes such as 4.6 will throw an exception unless you open it in read/write mode.

Upvotes: 1

Related Questions