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
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

XML DOM perser and HttpConnection Problem again again and again..

[ Edited ]

Following code i am using for network connection : 

public static String getConnectionString()
    {
                    
        String connectionString = null;                
                              
        if(DeviceInfo.isSimulator())
        {
            connectionString = ";deviceside=true";
            
        }       
        // Wifi is the preferred transmission method
        else if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
        {            
            connectionString = ";interface=wifi";
        }
                       
        else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT)
        {
        	String carrierUid = getCarrierBIBSUid();
            if(carrierUid == null) 
            {
    
                connectionString = ";deviceside=true";
            }
            else 
            {
                   
                connectionString = ";deviceside=false;connectionUID="+carrierUid + ";ConnectionType=***-***";
            }
        }
        
        else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS)
        {         
            connectionString = ";deviceside=false";
        }
      
        else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
        {
        	connectionString = ";deviceside=true";
        }
      
        else
        {         
            connectionString = ";deviceside=true";
        }
        return connectionString;
    }

 

public HttpConnection getInputStream(String url)
	{	
		url = url+ Urls.getConnectionString();		
		
		HttpConnection httpConnection = null;		
			
		try 
		{
			 httpConnection = (HttpConnection) Connector.open(url);
		}
		catch (Exception e)
		{
			return null;
		}
		return httpConnection;		
	}

 I am using DOM parser for parsing purpose following is the code:

public boolean parseData(final HttpConnection httpConnection)
	{	
		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
	    DocumentBuilder docBuilder;
	    InputStream is = null;
		try
		{
			docBuilderFactory.setCoalescing(true);
			docBuilder = docBuilderFactory.newDocumentBuilder();
			is = httpConnection.openInputStream();			
			doc = docBuilder.parse(is);
	        doc.getDocumentElement().normalize();
	        docBuilder.isValidating();
	        return true;
		}
		catch(Exception ex) 
		{			
			return false;
		}		
		finally
		{
			try
			{
				if(is!=null)
				{
					is.close();
				}
				if(httpConnection!=null)
				{
					httpConnection.close();
				}
			}
			catch(Exception ex)
			{
				
			}
		}
		
	}	

 The above code works fine iin OS 7 and 7.1. But In os 5 and 6 sometimes it works..sometimes connection is not established. My app is posted on appworld for sale. Its supporting OS 5,6,7. I have tested my app on all those OS both on simulators and real devices. Everything is working fine on my side. But getting bad reviews : "doesnt work,network error". I am just f**ked up with it . :smileysad: :smileysad: please someone help.

Please use plain text.
Developer
sandeepkumar03
Posts: 117
Registered: ‎02-12-2009
My Device: Not Specified

Re: XML DOM perser and HttpConnection Problem again again and again..

See if this link helps you for Network issues. There are different modes of connection, sometimes if both Cellular, Wifi data connection is ON, We faced issue on non touch simulators like 8520

 

http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-O...

 

Regards,

Sandeep

 

 

Please use plain text.
Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520
My Carrier: Ufone

Re: XML DOM perser and HttpConnection Problem again again and again..

Hi, I am using following class for getting the connection string,

 

import net.rim.device.api.servicebook.ServiceBook;
import net.rim.device.api.servicebook.ServiceRecord;
import net.rim.device.api.system.CoverageInfo;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.WLANInfo;

public class ConnString {
public synchronized static String getConnectionString() {
String connectionString = null;

if (DeviceInfo.isSimulator()) {
connectionString = ";deviceside=true";
}
// Wifi is the preferred transmission method
else if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {

connectionString = ";interface=wifi";
}
// Is the carrier network the only way to connect?
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
String carrierUid = getCarrierBIBSUid();

if (carrierUid == null) {
// Has carrier coverage, but not BIBS. So use the carrier's TCP network
connectionString = ";deviceside=true";

}
// Check for an MDS connection instead (BlackBerry Enterprise Server)
else if ((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
connectionString = ";deviceside=false";
}
// If there is no connection available abort to avoid hassling the user unnecessarily
else if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE) {
connectionString = "none";
}
// In theory, all bases are covered by now so this shouldn't be reachable.But hey, just in case ...
else {
connectionString = ";deviceside=true";
}
return connectionString;
}

private synchronized static String getCarrierBIBSUid() {
ServiceRecord[] records = ServiceBook.getSB().getRecords();
int currentRecord;

for (currentRecord = 0; currentRecord < records.length; currentRecord++) {
if (records[currentRecord].getCid().toLowerCase().equals("ippp")) {
if (records[currentRecord].getName().toLowerCase()
.indexOf("bibs") >= 0) {
return records[currentRecord].getUid();
}
}
}
return null;
}
}

 

and then I use the connectionString as follow,

 

if (ConnString.getConnectionString().equals("none")) {
Status.show("No Connectivity Available!");
} else {
// Code to establish connection
}

 

This is working fine for me. If the Connection string returned is none then means there is no connection available, else I can establish the connection without any problem. You have to also check that your application have all the necessary permissions to work smoothly. 

 

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

Re: XML DOM parser and HttpConnection Problem again again and again..

[ Edited ]

Your connection string code seems to have been derived from some code I have seen on my travels on the internet.  Where I have seen it and been able, I have commented on it, because as far as I know, some of  the connection strings that this code will give are not actually valid.

 

Here is a KB article that describes those that are valid:

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-make-an-HTTP-or-socket-con...

 

The network Legacy code that RIM provided in the KB article you have been pointed at, is intended for use in OS levels pre OS 5.0.  In OS 5.0 RIM introduced the ConnectionFactory.  This basically does the same job - it will decide what the device supports and what connection it can make.  Since your app only supports OS 5.0 and above, the best solution is to rework your code to use ConnectionFactory.  I really recommend it.  Don't patch in changes to set your connection String.  Use ConnectionFactory.

 

That said, I have one more big comment. 

 

I am hoping that this is not your production code, but is a cut down version for the forum. 

 

If it is your real code, can I strongly suggest that you include some logging and debugging in here.  Something that will give the opportunity to users to send you an email, containing the appropriate logging information, when you have this, or any other sort of problem.  Putting an application on App World that does not allow the users to report problems is just asking for bad reviews.  Users will have problems.  Users will use your app with WiFi and Wireless turned off.  Users will use you app after moving to a different country and will forget they have data roaming turned off.  If you don't make it easy for them to report problems and give you the information that you need to resolve it, you will never be able to resolve the reasons that you got the bad reviews.. 

 

You will find some code to help with this in one of the tutorials here:

http://supportforums.blackberry.com/t5/Java-Development/Tutorials-for-new-developers-Part-1/m-p/1621...

Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: XML DOM perser and HttpConnection Problem again again and again..

[ Edited ]

Connection using ConnectionFactory was giving me trouble in OS 7. It was running totally fine in OS 5 and OS 6. Thats why i decided to go with this basic code.And yes the above code is derived from R&D over the web. I have created the methods from different tutorials and code samples that i read.

Providing "FeedBack" option will be the key. Thanks for this suggestion. 

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

Re: XML DOM perser and HttpConnection Problem again again and again..

Have you raised your issues with COnnectionFactory on the forum?  Did I comment on it?  I apologies if I have given you a wrong steer at any point.....

Please use plain text.
Contributor
adnanyaseen
Posts: 17
Registered: ‎06-01-2012
My Device: 8520
My Carrier: Ufone

Re: XML DOM perser and HttpConnection Problem again again and again..

I am also not very experienced and just developed an application myself recently by reading tutorials, documentation.  Is it a good Idea that you use ConnectionFactory for OS 5 and 6 and use the posted code for OS version by detecting the OS version, DeviceInfo.getPlatformVersion();

 

Bad Idea?

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

Re: XML DOM parser and HttpConnection Problem again again and again..

In my opinion, ConnectionFactory is the best option for all applications targeted for OS 5.0 and above.  I would like to understand why it did not work for the OP for OS 7 devices. 

Please use plain text.
Developer
JoVinz
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: XML DOM perser and HttpConnection Problem again again and again..

[ Edited ]

@Peter I didn't post ConnectionFactory issue on forum. I was just searching the forum. So many people are against using ConnectionFactory. Anyways i am trying with ConnectionFactory now.

In case of ConnectionFactory on OS 7, I debug through the code which was returning connection null,not each and every time especially i faced issue on device bold 9790 and some other devices.

@adnanyaseen its a good idea. Will try this out.
 

 Thanks.

 

Please use plain text.