Facing issue with HTTPConnectionFactory usage

Anything that isn't a bug or feature request goes here

Facing issue with HTTPConnectionFactory usage

New postby sashishk on Thu Sep 17, 2009 3:07 am

Hey Marcus,

The HTTPConnectionFactory class is wonderful implementation. I've included this into my code. I'm calling the connection factory as in below attached code:

String hitURL(String url)
{
HttpConnectionFactory factory = new HttpConnectionFactory(url, HttpConnectionFactory.TRANSPORTS_ANY);
String message = "";
while( true )
{
try
{
HttpConnection connection = factory.getNextConnection();
try
{
connection.setRequestMethod( "GET" );
InputStream input = connection.openInputStream();
.........get data from stream........
message = data fetched;
input.close();
break;
}
catch( IOException e)
{
try
{
connection.close();
}
catch(IOException e1){}
//Log the error or store it for displaying to the end user if no transports succeed
//Note you should never attempt network activity on the event thread
Dialog.alert( "Unable to perform request!!!" );
}
}
catch(NoMoreTransportsException e)
{
//There are no more transports to attempt
//Note you should never attempt network activity on the event thread
Dialog.alert( "No more transports available...."+e.toString());
break;
}
}
return message;
}

It works well but sometimes on device and simulator, when I try to make a call to internet, it gets hanged. Following are the differences w.r.t the code you have put on public domain for usage of the connection factory.
1) GET used instead on POST
2) In case of exception I have given dialog alert after closing the connection

Please suggest if the above changes can cause the app to be in hang state if I use post, or is Dialog is shown in case of exception.

How can I know if the signal strength has gone down during the course of fetching the data after the connection was established?

Thanks
-aks
sashishk
 
Posts: 3
Joined: Thu Sep 17, 2009 1:46 am

Re: Facing issue with HTTPConnectionFactory usage

New postby marwatk on Thu Sep 17, 2009 8:28 pm

Hi there,

Two issues. The simulator hang a lot during network communication. It just sucks that way. I have to do proof of concepts in the simulator and do real network testing on device, it's annoying.

Second is that you should never call network operations and UI operations from the same thread. You'll need to do all UI operations in the event thread, but doing network operations there will get your app terminated by the OS.

I'd love to help further, but I'm not really set up for that. I'd definitely suggest the main BB support forums java development site. The guys over there are awesome.
http://supportforums.blackberry.com/rim ... d=java_dev

Hope it works out for you.

-Marcus
Versatile Monkey
For more/quicker help make sure to check out the user manuals
marwatk
Lead (and only) Monkey
 
Posts: 2596
Joined: Sun Nov 02, 2008 9:20 pm

Re: Facing issue with HTTPConnectionFactory usage

New postby sashishk on Thu Sep 17, 2009 11:14 pm

Thanks Marcus.....

-aks
sashishk
 
Posts: 3
Joined: Thu Sep 17, 2009 1:46 am

Re: Facing issue with HTTPConnectionFactory usage

New postby RLord321 on Mon Sep 28, 2009 10:45 am

Hello Marcus. I'm still waiting for my new project to complete so I can revisit my old ones and include your factory. Just curious, though..Why wouldn't you always want to use TRANSPORTS_ANY when setting up the connection? I was thinking about this and the only reason I can think of is if you only want your app to run in High Speed connections like WiFi. Is this right? There shouldn't be any other downside in using TRANSPORTS_ANY other than this, right?

Thanks
RLord321
 

Re: Facing issue with HTTPConnectionFactory usage

New postby marwatk on Mon Sep 28, 2009 7:05 pm

Well, with PodTrapper, for example, most users don't want to download episodes over the cell network, but only via wifi. I can imagine other apps might run in to similar issues so I made it an option in that code. Does that make sense?

-Marcus
Versatile Monkey
For more/quicker help make sure to check out the user manuals
marwatk
Lead (and only) Monkey
 
Posts: 2596
Joined: Sun Nov 02, 2008 9:20 pm

Re: Facing issue with HTTPConnectionFactory usage

New postby RLord321 on Tue Sep 29, 2009 7:34 am

Makes perfect sense. Again, thanks for posting the HTTPConnectionFactory as I'm sure it is saving thousands of hours of development across the Blackberry community.
RLord321
 

Re: Facing issue with HTTPConnectionFactory usage

New postby Annon on Thu Dec 16, 2010 3:43 pm

THANKS to the Creator
Annon
 


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron