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: 1,621
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido
Accepted Solution

what is wrong with my http code?

I'm having problem with the following code on the Bold 9700.  The code works on the simulator and other devices but some users are having problems.  It appears nothing is returned when getting the html page.

 

 

    static String get_page(String url)
    {
        
        StreamConnection s = null;
        InputStream input = null;

        try
        {

            s = (StreamConnection)Connector.open(url);
            
            input = s.openInputStream();
            byte[] data = new byte[4096];
            int len;
            StringBuffer raw = new StringBuffer();
            long startTime = System.currentTimeMillis();
            
            while ( -1 != (len = input.read(data)) )
            {
                   
                if (len > 0) {
                    raw.append(new String(data, 0, len));
                }
            
                // check for timeout waiting for server; or
                // what if page never closes...
                if (System.currentTimeMillis() - startTime >  30000)
                {
                    s.close();
                    return("ERR2");
                }
            }
            s.close();
        
            
            return(raw.toString());
        }
        catch (Exception e)
        {
            return("ERR3");
        }

        
        finally
        {
            try
            {
                if (input != null)
                    input.close();
            }
            catch (Exception e)
            {
            }
        }  
    }

 

 Are there any settings in the Options app need to be set? eg: TCP/IP

 

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

Re: what is wrong with my http code?

What connection parameters are you adding to you URL?

 

 

Developer
Posts: 1,621
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: what is wrong with my http code?

I dont use any.  Just the following as an example

 

http://m.yahoo.com/w/ygo-weather/search.bp?action=submit&yset-t=c&.intl=CA&.lang=en-ca&q=new+york

 

what parameters do i need to add? thx

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

Re: what is wrong with my http code?

You code does not look particularly robust to me.  For example, you do not check the http response code.  I suggest that you review the httpdemo sample for more robust code, especially the fetch method.  I would also make sure you log the URL and the response data you receive.

 

In addition, I suggest you review the following, which I believe will explain why you can't use assume that networking code that is working on the Simulator means it is going to work on the device:

 

http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-c...

Developer
Posts: 1,621
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: what is wrong with my http code?

thanks. peter_strange.

 

if  the app is not connecting to the server or downloading the html page what good does it do by getting the http response code? I have looked at the httpdemo app.  there isnt any different except the demo checks for the reponse code.

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

Re: what is wrong with my http code?

The information given previously on this Thread did not actually tell us that the app was not connecting to the server, all we knew was that the html page was not being downloaded.  So for example, the http call could have been returning a Http 500 code and no data.  It seems to be that would have given the same symptoms.  A more robust piece of code that checked the response code would have ruled out that possibility.   

 

Now that we know that the Server is not being hit, then I agree, you need to look elsewhere for the cause of the problem. 

 

But I would still make that comment in an attempt to help you develop the best possible code in your BlackBerry application. 

 

Anyway, the Thread I pointed you at in the second part of my response should help you understand what is actually going wrong, what you might change, and what you need to tell us to help you with this. 

Developer
Posts: 1,621
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: what is wrong with my http code?

Peter_strange:  I recompiled the rim httpdemo sample app with JDE 4.7 and sent it to the user and they are having the same problem.  It returns http error 500.  the user is located in UK

 

Interestingly if the user copy and paste the same link into the Browser app it works fine.

 

The app also works fine in the sim

 

any suggestions? thanks

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

Re: what is wrong with my http code?

The Thread I pointed you at and the various 'required reading' material, describes how different network paths are chosen by changing the connection suffix of the URL used.  The standard demo does not add a suffix, so will by default, choose BES connection.  Unless of course the carrier has provided a different default for a non BIS device, for example I understand that Vodafone UK will send it via WAP.

 

Depending on the connection suffix/default processing, the request will routed through a number of 'gateways' such as the BES/MDS or the carrier WAP gateway.  So one of these could be giving the 500. 

 

Assuming it does actually make it to your Server (I presume this is a URL that you control), then the 500 comes from your Web processing.  This could for example, be because your processing expects certain headers in the http request that are not provided.  Or, that the request has been routed by some gateway that changes the headers in a way that your web server is not expecting. 

 

Having the same URL work on the Browser is unfortunately, not much of a test because it can be routed via a communication method that you don't use (for example, on Vodafone BIS devices I think the default Browser will use BIS-B) and, in addition, it could supply some headers for the http connection that you do not supply. 

 

The point really is that there are a lot of places that this code could break.  And there are number of variables including what connection method is being used (and in the case of Vodafone, have actually forced it to use it), what carrier is being used and what headers have been supplied. 

 

But I think the first thing you should do is find out who is giving you the 500.  If you can trace the request to your own Server, so much the better.  If you can't, in the headers that come back with the 500, you should some Server information.  Dump them out., dump out the connection suffix you are using and if possible, get the log records from around the time this was done (that will confirm the connection method actually used).  

 

I would also search this forum for information on issues people have had with carriers.  I know there is some information about Vodafone UK.  I believe there is something about at least one other carrier.

 

Sorry, comms on BB is not that easy.....

Developer
Posts: 1,621
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: what is wrong with my http code?

ok. thanks