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 Contributor
tridibmanna
Posts: 9
Registered: ‎11-17-2010
My Device: Not Specified

Sudden app freeze during data upload.

Hello all fellow members,

 

Well I have developed an app running on OS 5 through which users can take 10 photos, add some details and upload those to a server. The app functions perfectly in the simulator but when running on a real device(Bold 9000), it uploads 6-8 photos and just freezes. There is an inbuilt logger in the app which would log exceptions, but after force exiting the frozen app it is seen that the logger has not logged anything after showing the record of the last image(that was successfully uploaded).

 

This makes me think that the app just stops executing after a certain point as other wise the logger would have logged the exceptions which has prevented the photos from getting uploaded(network failure etc).

 

What could be the possible explanation for this? If there was some problem in the code(deadlocks, other logical errors etc) it would have been reflected in the simulator as well correct? However the app works with 100% accuracy in the simulator. Could it be a memory saturation thing?

 

Please share your knowledge.

 

Regards,

Tridib.

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

Re: Sudden app freeze during data upload.

How do you force exit your application?

 

Have you looked at the Event log at the time of the failure.  Alternatively connect your device to an IDE and do on-device debugging, this will display the Event log and you may be able to watch your application process and then fail.

 

That said, remember that the Simulator is only an approximation, there are areas, most notably networking, that are significantly different on the device.  In fact your problem sounds like you might be running your upload on the Event Thread.  Are you certain you are doing the upload in the background?  How do you start your upload Thread?

New Contributor
tridibmanna
Posts: 9
Registered: ‎11-17-2010
My Device: Not Specified

Re: Sudden app freeze during data upload.

Actually we haver tested in India with the Device itself having Airtel Service provider and it  is uploading seemless. But in US with Sprint Service provider in the same device it is uploading 8 images out of 10 images. the Logger that we have given in the Build reflects as i have said previously that we are getting 7 successfully upload in the logger.But after the 8th upload the Logger is showing nothing.

 

We thought it may be connection Time out and handled as such so that the Build sends a email from the Device during failure.We have tested that effect from the Simulator as well as from the Device over here in India. But in US  after uploading the 8th image the the application stops doing anything.

 

We are using different threads for uploading than the main thread.

 

I am showing you the part of the code which is doing HTTP Connection :

 

----------------------------------  >>>>>>>>>>>>>>>>

 

int _contentLength = 0;
            _contentLength = postData.length;
              connection = (HttpConnection) Connector.open(strRequestURL,Connector.READ_WRITE,true);

 

            connection.setRequestProperty("Content-Length", ""+_contentLength);
            debug += "-->2";
            
            try{
                    outputStream = connection.openOutputStream();
                    debug += "-->3";
                   
                    try{
                    outputStream.write(postData);
               
                    } catch (Exception e) {
                   
                      Logger.getInstance().log(" NetRequest.java >>>> outputStream.write Exception:"+e, this.getClass());
                    
                     }
                    outputStream.flush();  // if any Exception Comes here  then rewriteshould not be done
                     }
                
                    } catch (Exception e) {
                   }finally{        //ari added 10.11.2010

             try{
            if(outputStream != null)//ari added
            outputStream.close();
                } catch (Exception e) {
                }

                   }
            debug += "-->4";
            // END - POST Data

            responseCode = connection.getResponseCode();
            debug += "-->R:"+responseCode;
            Logger.getInstance().log("NetRequest.java - responseCode:"+responseCode, this.getClass());
            if (responseCode == HttpConnection.HTTP_OK) {
                inputStream = connection.openInputStream();
            } else {

                inputStream = null;
                outputStream = null;
                error = "Invalid Response:" + responseCode;
            }
        } catch (Exception e) {

            debug += "-->"+e.toString();
            inputStream = null;
            error = "Unable to connect the server.";
            try {
                 
                   if(inputStream != null){//ari added 9.11.2010
                inputStream.close();
                   }
           
                if(connection != null){//ari added 9.11.2010
                connection.close();
                   }
            } catch (Exception ex) {
              
                 }

        }

         } catch (Exception ex) {
       Logger.getInstance().log("NetRequest.java- inside - Exception :"+ex, this.getClass());
                 }
        return inputStream;
        
    }// End of method

 

--------------------------------  <<<<<<<<<<<<<<<<<<<<<<

 

Can somebody can give me any clue ?

 

 

 

 

 

 

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

Re: Sudden app freeze during data upload.

Just to clarify, the app itself does not freeze or does completely freeze?  I'm guessing that the app does not actually freeze, however the photo transfer freezes.

 

I'm not "convinced" with the http connection code you have shown us and I'm hoping you have only given selected parts of it.  There seems to be a lot missing.  For example, you do not set the request type to POST, you do not describe your content type and most importantly, you do not get the response code from your request, so the failure could actually be a server problem with your 7th request that goes completely unrecorded.  So has the Server actually received and processed (and responded to) the images that you have already sent it?

 

And what is the point of your input stream? 

 

I would recommend that you code 'full' http connection code.  The sample provided in HttpConnection class should help you  I would also suggest that you add a few more logging statements to track the progress. 

 

However I have an idea.  What size are these images?  Do you attempt to send them all on the same http connection, or is it a connection per image?  Basically I am wondering if you are hitting some sort of connection limit.

 

Also can you tell us what connection method you are using? I am presuming it is not WiFi. 

 

New Contributor
tridibmanna
Posts: 9
Registered: ‎11-17-2010
My Device: Not Specified

Re: Sudden app freeze during data upload.

ya the code i have given is just a aprt of it... actually we have found that the Server is receiving the 8th image..but thats the last one...after that nothng is recorded... we are not using wifi but 2G connection network of Service provider...

 

we are connecting each TIME for each upload of images... in a complete session...

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

Re: Sudden app freeze during data upload.

"ya the code i have given is just a aprt of it..."

Can you confirm that you are indeed setting a type for the data you are posting:

connection.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, ...);

What are you setting?

 

"2G connection network of Service provider..."

I am not familiar with Sprint.  But is this direct TCP or WAP?  What are you specifying as your connection suffix?

 

As you are connecting each time, probably this is not a size thing, but out of interest,  how big are the images you are sending?

New Contributor
tridibmanna
Posts: 9
Registered: ‎11-17-2010
My Device: Not Specified

Re: Sudden app freeze during data upload.

Well Peter let me start off by expresing my thanks for your steady interest and efort to solve this issue. After all it is becoming more like a one on one chat in a public place.  :smileyhappy:

 

I will share the code tomorrow morning our time as it is not here in this computer and would update on the TCP/WAP thing as soon as i find out about it.

 

The typical image size is less than 80kb. Pretty sure it is not too large to cause any discomfort right?

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

Re: Sudden app freeze during data upload.

I'm not sure I can help you solve this issue.  I'm not in the US and have no experience of Sprint.  But what you are seeing seems, well, not logical or reasonable so I'm happy to help try to tie it down if I can.

 

The minimum size at which I would expect some discomfort is 128 KB, so I think that 80 Kb is fine.  Mind you, you might be converting it from binary to some other form (e.g. text for XML), which would increase the number of bytes involved. 

 

I have actually written something similar to this that transferred images taken on the Blackberry to the server.  I actually did not compress the images, so they were full size 1.5 MB.  However I chunked them up into 65 KB chunks and had some processing on the Server put these together.  So I know this is all possible. 

New Contributor
tridibmanna
Posts: 9
Registered: ‎11-17-2010
My Device: Not Specified

Re: Sudden app freeze during data upload.

The whole code that we are using :

 

 

// JAVA Imports
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
// RIM Imports
import net.rim.device.api.system.DeviceInfo;
// Application Imports
import com.common.Data;
import com.common.util.AppConstants;
import com.log.Logger;



public class NetRequest {

    public HttpConnection connection;
    public InputStream inputStream;
    public static OutputStream outputStream;// ari changed for Reload of Chunk 8.11.2010
    private String strRequestURL;
    public String error = "";
    public String errorDownload = null;
    public String downloadContent = null;
    private int chunkNumber = 0;
    private String isLastChunk = "false";
    private String SeriesStartTag = "";
    private int selectNumber = 0;// ari for number selected for upload
    public static String debug = "";
    private final String networkParam = ";deviceside=true";

      public NetRequest(int chunkNumber, String isLastChunk,int x) {
          try{
        this.chunkNumber = chunkNumber;
        this.isLastChunk = isLastChunk;
        this.selectNumber=x;
          } catch (Exception ex) {
          }

    }// End of constructor


    /**
     * This method fetch data( as a Input Stream) from server in POST method.
     *
     * @param strURL    Request URL of server.
     * @return          the data as a inputStream.
     */

        public synchronized InputStream getResponseM(String strURL, byte[] postData, String filename) {

            try{
        strRequestURL = strURL;
        int responseCode;
        try {
            strRequestURL += networkParam;
            debug += "-->" + networkParam;
          
            int _contentLength = 0;
            _contentLength = postData.length;
              connection = (HttpConnection) Connector.open(strRequestURL,Connector.READ_WRITE,true);
            debug += "-->1";
            connection.setRequestMethod(HttpConnection.POST);
            connection.setRequestProperty("DeviceID", "" + Integer.toHexString(DeviceInfo.getDeviceId()));
            connection.setRequestProperty("ImageName",filename );
            connection.setRequestProperty("ChunkNumber", "" + chunkNumber);
            connection.setRequestProperty("SeriesStartTag", "" + Data.getInstance().getSeriesStartTag());
            connection.setRequestProperty("IsLastChunk", isLastChunk);
            connection.setRequestProperty("ImageCnt", "" +AppConstants.checkedNumber);//ari added
            String ImageValue=Data.getInstance().getImageCounterValue();
            connection.setRequestProperty("ImageCntValue", "" +ImageValue);//ari added

            if(Data.getInstance().getIsInfoOn()) {
                connection.setRequestProperty("Description", Data.getInstance().getDescription());
           
               
            }
            connection.setRequestProperty("Content-Length", ""+_contentLength);
            debug += "-->2";
            
            try{
                    outputStream = connection.openOutputStream();
                    debug += "-->3";
                    if(!postData.equals(AppConstants.postDataPrev)){ // ari added 10.11.2010 for RewriteChk 10.11.2010
                    try{
                    outputStream.write(postData);
                    AppConstants.postDataPrev=postData;
                    } catch (Exception e) {
                      AppConstants.postDataPrev=null;
                      Logger.getInstance().log(" NetRequest.java >>>> outputStream.write Exception:"+e, this.getClass());
                    
                     }
                    outputStream.flush();  // if any Exception Comes here  then rewriteshould not be done
                     }
                
                    } catch (Exception e) {
                   }finally{        //ari added 10.11.2010

             try{
            if(outputStream != null)//ari added
            outputStream.close();
                } catch (Exception e) {
                }

                   }
            debug += "-->4";
            // END - POST Data

            responseCode = connection.getResponseCode();
            debug += "-->R:"+responseCode;
            Logger.getInstance().log("NetRequest.java - responseCode:"+responseCode, this.getClass());
            if (responseCode == HttpConnection.HTTP_OK) {
                inputStream = connection.openInputStream();
            } else {

                inputStream = null;
                outputStream = null;
                error = "Invalid Response:" + responseCode;
            }
        } catch (Exception e) {

            debug += "-->"+e.toString();
            inputStream = null;
            error = "Unable to connect the server.";
            try {
                 
                   if(inputStream != null){//ari added 9.11.2010
                inputStream.close();
                   }
           
                if(connection != null){//ari added 9.11.2010
                connection.close();
                   }
            } catch (Exception ex) {
              
                 }

        }

         } catch (Exception ex) {
       Logger.getInstance().log("NetRequest.java- inside - Exception :"+ex, this.getClass());
                 }
        return inputStream;
        
    }// End of method

        
    
}// End of class

 

 

 

----------------- <<<<<<<<<<<<<<<<<

 

 

This is the Connection code we are using

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

Re: Sudden app freeze during data upload.

[ Edited ]

You have not responded to a couple of my earlier questions:

 

It seems you are NOT sending a content type

connection.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, ...);

Is this deliberate or an omission?  Content type may not be important for your Server but may be important to the gateway that your request is passed through. 

 

You have not told us what connection suffix you are using.

 

These both have a bearing on the way your POST will be processed..

 

Also looking at this code, it seems that this was GET code that someone has transformed into POST code.  Would that be fair?