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
Contributor
Posts: 13
Registered: ‎06-20-2011
My Device: Pearl 9100
My Carrier: Fido

Blackberry HttpConnection Timing Out

[ Edited ]

I am trying to grab an XML file for parsing with the following:

private void getAndParseXML( String _xmlurl ) {

    HttpConnection xmlcon = null;

    InputStream input = null;

    SAXParserFactory spf = null;

    try {

        xmlcon = (HttpConnection)Connector.open( _xmlurl, Connector.READ ); // open connection to XML source

        spf = SAXParserFactory.newInstance(); // set up xml parsers

        input = xmlcon.openInputStream(); // set up input stream

 

        SAXParser saxparser = spf.newSAXParser(); // create a new parser object

        saxparser.parse( input, this ); // parse operations start here

    }

    catch( IOException ex ) {

         System.out.println( "IOException Caught:\t" + ex.getMessage() ); // set a default item if any exception occurs with retreiving or parsing XML file

    } catch (SAXException ex) {

         System.out.println( "SAXException Caught:\t" + ex.getMessage() );

         ex.printStackTrace();

    } catch ( IllegalArgumentException ex ) {

          System.out.println( "IllegalArgumentException Caught:\t" + ex.getMessage() );

          ex.printStackTrace();

    } catch (ParserConfigurationException ex) {

         System.out.println( "ParserConfigurationException Caught:\t" + ex.getMessage() );

         ex.printStackTrace();

     } 

} // END ---------------------

 

But the I get an exception thrown saying the connection timed out after 12 seconds. This after the line "input = xmlcon.openInputStream();" is executed. If this is relevant, it is the IOException that gets caught, and determining if there is an active network connection is done before this method is called. Did I miss something?

 

EDIT: Just for clarification, this would be the first instance of a network connection in the application. Before this block of code, a simple test:

 

private boolean isConnectedToNetwork() {

         boolean isConnected = false;

         if ( (TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_TCP_CELLULAR)) ||                   (TransportInfo.isTransportTypeAvailable(TransportInfo.TRANSPORT_TCP_WIFI)) ) if ( (TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_TCP_CELLULAR)) || (TransportInfo.hasSufficientCoverage(TransportInfo.TRANSPORT_TCP_WIFI)) )

        isConnected = true;

 

        return isConnected;

} // END -----------

 

to make sure a connection would be possible, before attempting to retrieve an XML file. Also, I am targeting BB 5.0.