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
chico95
Posts: 23
Registered: ‎09-16-2008
My Device: Not Specified

Making a direct TCP call - Getting APN nulls

Hello,

 

Through my app I am making a call to a remote server URL.  However I get the following in my debug window in the JDE:

 

tarting App
Started App(122)
Foreground App(122)
FocusHistory: Focus lost; App Home Screen; Component net.rim.device.api.ui.MediaController


Refreshing connection on send
Running refresh
Local port: 19780


FocusHistory: Focus gained; App App; Component App.HelloScreen$2


APN: 'rim.net.gprs'
APN username: 'null'
APN password: 'null'
Connection does not exist


Detected information for 1 GPAK connection(s)
FocusHistory: Focus gained; App App; Com ....

 

Any idea why I am getting the APN errors?  I suspect that is the cause...  Ps I am using the simulator with MDS right now.

 

Thanks,

 

Chirag

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Making a direct TCP call - Getting APN nulls

Silly questions probably, but we have to rule out the obvious. 

 

What connection suffix are you using for your URL?

Is the MDS actually starting?

 

I presume you have seen this?

What Is - Different ways to make an HTTP or socket connection
DB-00396

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

Please use plain text.
New Developer
chico95
Posts: 23
Registered: ‎09-16-2008
My Device: Not Specified

Re: Making a direct TCP call - Getting APN nulls

[ Edited ]

Hi,

 

I think I am making a direct call... below is the code snippet:

 

StreamConnection s = null;
                   
                    try
                    {
                        s = (StreamConnection)Connector.open(SAMPLE_HTTPS_PAGE);
                        HttpConnection httpConn = (HttpConnection)s;

                        int status = httpConn.getResponseCode();
                       
                        if (status == HttpConnection.HTTP_OK)
                        {
                            // Is this html?
                            String ctype = httpConn.getHeaderField(HEADER_CONTENTTYPE);
                            boolean htmlContent = (ctype != null && ctype.equals(CONTENTTYPE_TEXTHTML));

                            InputStream input = s.openInputStream();

 

if (status == HttpConnection.HTTP_OK)
                        {
                            // Is this html?
                            String ctype = httpConn.getHeaderField(HEADER_CONTENTTYPE);
                            boolean htmlContent = (ctype != null && ctype.equals(CONTENTTYPE_TEXTHTML));

                            InputStream input = s.openInputStream();

                            byte[] data = new byte[256];
                            int len = 0;
                            int size = 0;
                            StringBuffer raw = new StringBuffer();
                           
                            while ( -1 != (len = input.read(data)) )
                            {
                                raw.append(new String(data, 0, len));
                                size += len;
                            }
                           
                            raw.insert(0, "bytes received]\n");
                            raw.insert(0, size);
                            raw.insert(0, '[');
                            String content = raw.toString();
                           
                            if ( htmlContent )
                            {
                               add(new RichTextField(raw.toString()));
                               //content = prepareData(raw.toString());
                            }
                           
                            // The long operation is the parsing above, after the parsing is complete, shutdown
                            // the status thread before setting the text (since both threads modify the content
                            // pane, we want to make sure we don't have the status thread overwriting our data).
                           // stopStatusThread();
                           // updateContent(content);
                            input.close();
                        }
                        else
                        {
                           
                           add(new RichTextField("response code = " + status));
                        }
                       
                        s.close();

                    }
                    catch (IOException e)
                    {
                        System.err.println(e.toString());
                        add(new RichTextField(e.toString()));
                        //updateContent(e.toString());
                    }

Message Edited by chico95 on 10-05-2008 11:43 PM
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Making a direct TCP call - Getting APN nulls

As the article I pointed you at says, the method of call is determined by the suffix of the URL you are using. In this code your URL is

SAMPLE_HTTPS_PAGE

We are going to need to know the contents of that URL to determine the connection type.

 

Are you doing this on the SImulator?  If so, I would suggest you start up the appropriate MDS Simulator.

 

Can you use the Browser on the device to get to the page you are trying to get?

Please use plain text.
New Developer
chico95
Posts: 23
Registered: ‎09-16-2008
My Device: Not Specified

Re: Making a direct TCP call - Getting APN nulls

Hi,


Sorry, I missed putting that info in.  

 

Yes I am doing this on the simulator and the MDS is working correctly, because I can actually get to websites browsing through the simulator, so i'm pretty sure the internet connection is working.

 

Here is the STRING:

 

String SAMPLE_HTTPS_PAGE = "http://www.google.com";

 

And here is the error in the debug window:

 

FocusHistory: Focus lost; App Home Screen; Component net.rim.device.api.ui.MediaController
Refreshing connection on send
Running refresh
Local port: 19780
APN: 'rim.net.gprs'
APN username: 'null'
APN password: 'null'
FocusHistory: Focus gained; App App; Component App.HelloScreen$2
Connection does not exist
Detected information for 1 GPAK connection(s)
FocusHistory: Focus gained; App App; Component net.rim.device.api.ui.component.RichTextField

 

Thanks,

 

Chirag
Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,685
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Making a direct TCP call - Getting APN nulls

Are you getting an exception from within the application?  If so what is it and what line is throwning it?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
chico95
Posts: 23
Registered: ‎09-16-2008
My Device: Not Specified

Re: Making a direct TCP call - Getting APN nulls

Hi,

 

I have a try catch clause:...In the exception handling I just throw it to the screen, but I'm not getting any exceptions reported by the application.  The only info that I get is in the JDE debug window which lets me know a connection was attempted and failed, then the focus is given back to the application, without and exception thrown.  I put some filler Add new richtextfield, into the catch clause, but it doesn't seem like that line is executed.

 

catch (IOException e)
                    {
                        System.err.println(e.toString());
                        add(new RichTextField("Got here in exception!"));
                        add(new RichTextField(e.toString()));
                        //updateContent(e.toString());
                    }

 

Thanks,

 

Chirag
Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,685
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: Making a direct TCP call - Getting APN nulls

Are you creating the connection in its own thread?  Please note that connections should not be made on the main event thread.

 

If this is the case, then the code in your catch block will fail since it is trying to update a screen from outside of the main event thread.  Please see this link for a sample.

 

How to - Update a screen on the Main Event Thread
Article Number: DB-00136

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Contributor
silver_mirror
Posts: 3
Registered: ‎04-28-2010
My Device: -

Re: Making a direct TCP call - Getting APN nulls

ok, now it works, but  when I get the application installed, the problems show up again. Could someone tell me what this is and the solution?  BTW,  the internet connection on device is works fine.

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Making a direct TCP call - Getting APN nulls

Have you done any debugging on device?  What exception are you seeing?  Does the device have APN information (specific to the carrier involved) set correctly in the Options --> TCP?

Please use plain text.