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: 14
Registered: ‎04-05-2011
My Device: 8320 Curve
My Carrier: No carrier, only developing

IOCancelledException: Send/receive was cancelled ... (why?)

[ Edited ]
Hello,
 
I have received the following exception and can find almost no mention of it on the forums:

IOCancelledException: Send/receive was cancelled

According to the Javadoc, this is "Thrown if a send or receive is cancelled for some reason"
 
I get this when using code from the RIM sample push application, (sample-push-enabled-app-1.0.1.11-sources.jar), slightly modified of course to hit our Push stuff..  I can't find a link to this source otherwise I'd provide it...
 
I am using a Blackberry 9700 device running 5.0.0.296 and I have BIS up and running on it.  The app actually does appear get timely notification of a new push message, but fails to process it. 
 
The failure happens at the following line in the PushMessageReader class in the 'process()' method:
 
String msgId = httpConn.getHeaderField( MESSAGE_ID_HEADER );
 
It is the first line that attempts to run a method in httpConn, which is not null, BTW... it is derived from a 'Connection' object that is tested to be an 'instanceof' HttpServerConnection... so it seems to be a legitimate object at this point.
 
Clearly something works, because I only get this exception shortly after sending a push message from our servers.
 
Can anyone help me or tell me what the possible cause of this would be?  I don't know whether this is a push issue specifically, but I can't track down anywhere in RIM's code that would be 'cancelling' this connection....
 
Thanks,
iluomo
Contributor
Posts: 14
Registered: ‎04-05-2011
My Device: 8320 Curve
My Carrier: No carrier, only developing

Re: IOCancelledException: Send/receive was cancelled ... (why?)

For what it's worth, I had (previous to my post above) commented OUT the section that allows PushLib43 to work, as I found it odd that the //#ifdef HANDHELD_VERSION_50 directive would allow PushLib43 to be instantiated instead of PushLib50, even though I was using the 5.0+ device I have described in the above post.

 

I altered the code BACK to allow for PushLib43 (I still REALLY want to know why this is the one that gets instantiated and what then is the meaning of HANDHELD_VERSION_50)....

 

Anyway, using PushLib43, it seems to be working ok on my BB 9700 (same device mentioned in previous post)... however, I'm afraid that I won't get the benefit of the 5.0 features..... so if possible I'd like someone to shed some light on the questions:

 

1. Why is HANDHELD_VERSION_50 pre-processor directive evaluating to FALSE on my device,

2. Why would 43 work where 50 is failing? (when I force it to use PushLib50)

 

-iluomo

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: IOCancelledException: Send/receive was cancelled ... (why?)

For anyone else who finds this, make sure you do not call PushInputStream.accept() before you read from it because it will close it out and you will get the IOCancelledException.

Trusted Contributor
Posts: 174
Registered: ‎09-04-2011
My Device: Bold
My Carrier: at&t

Re: IOCancelledException: Send/receive was cancelled ... (why?)

I have the same experience here.

 

At Push SDK, there are couple cod file which we could load onto device. When I loaded SamplePushEnabledApp5_0.cod onto my device BOLD 9700 (OS 5.0), I would get the same exception as you did when a push message is reached at client side. When I loaded SamplePushEnabledApp4_6.code onto the device, I am able to receive the push message.  Then I loaded theSamplePushEnabled cmpiled wth PushLIb 5.0 by myself for debugging and attached debugger to device, somehow device could not receive push message any more. Any idea?

 

 

Here is the code to process the push message:

    public static void process( PushInputStream pis, Connection conn ) {
        Logger.log( "Reading incoming push message ..." );

        try {

            HttpServerConnection httpConn;
            if( conn instanceof HttpServerConnection ) {
                httpConn = (HttpServerConnection) conn;
            } else {
                throw new IllegalArgumentException( "Can not process non-http pushes, expected HttpServerConnection but have "
                        + conn.getClass().getName() );
            }

            String msgId = httpConn.getHeaderField( MESSAGE_ID_HEADER );

            String msgType = httpConn.getType();
            String encoding = httpConn.getEncoding();

            Logger.log( "Message props: ID=" + msgId + ", Type=" + msgType + ", Encoding=" + encoding );
                        
            if( !alreadyReceived( msgId ) ) {
                byte[] binaryData;
                
                if(msgId == null) {
                    msgId = String.valueOf( System.currentTimeMillis() );
                }
                
                if( msgType == null ) {
                    Logger.warn( "Message content type is NULL" );                    
                } else if( msgType.indexOf( MESSAGE_TYPE_TEXT ) >= 0 ) {
                    // a string
                    int size = pis.read( buffer );
                    binaryData = new byte[size];
                    System.arraycopy( buffer, 0, binaryData, 0, size );
                    PushMessage message = new PushMessage(msgId, System.currentTimeMillis(), binaryData, true, true );
                    PushController.onMessage( message );
                } else if( msgType.indexOf( MESSAGE_TYPE_IMAGE ) >= 0 ) {
                    // an image in binary or Base64 encoding
                    int size = pis.read( buffer );
                    if( encoding != null && encoding.equalsIgnoreCase( "base64" ) ) {
                        // image is in Base64 encoding, decode it
                        Base64InputStream bis = new Base64InputStream( new ByteArrayInputStream( buffer, 0, size ) );
                        size = bis.read( imageBuffer );
                    }
                    
                    binaryData = new byte[ size ];
                    System.arraycopy( buffer, 0, binaryData, 0, size );
                    PushMessage message = new PushMessage(msgId, System.currentTimeMillis(), binaryData, false, true );
                    PushController.onMessage( message );
                } else {
                    Logger.warn( "Unknown message type " + msgType );                    
                }
            } else {
                Logger.warn( "Received duplicate message with ID " + msgId );
            }

            // perform application acknowledgment            
            if( PushConfig.isApplicationAcknoledgementSupported() ) {                
                pis.accept();                
            }
        } catch( Exception e ) {
            Logger.warn( "Failed to process push message: " + e );
        } finally {
            PushUtils.close( conn, pis, null );
        }
    }

 As we could see the PushInputStream.accept is called at the end of code at here:

            if( PushConfig.isApplicationAcknoledgementSupported() ) {                
                pis.accept();   

 which should not cause the stream got cancelled while we are reading at the beginning at line: String msgId = httpConn.getHeaderField( MESSAGE_ID_HEADER ) unless 5.0 Push API has some bug inside it which already called accept.

 

Could anyone shed some lights on this?

Contributor
Posts: 12
Registered: ‎10-31-2012
My Device: 9320, developer
My Carrier: Telus

Re: IOCancelledException: Send/receive was cancelled ... (why?)

[ Edited ]

I get iluomo's error on one 5.0 device, but not another 5.0 device. Here's what I know about the devices...

Working: OS version 5.0.0.419, BIS only.

Failing: OS version 5.0.0.337, BES and BIS.

 

iluomo's device: 5.0.0.296, BIS only (afaik)

 

Maybe this problem occurs only on certain device versions?

 

I searched for the OS versions listed above to see if there were any bug fixes that related to Push, but did not find anything.

Highlighted
Contributor
Posts: 12
Registered: ‎10-31-2012
My Device: 9320, developer
My Carrier: Telus

Re: IOCancelledException: Send/receive was cancelled ... (why?)

The device had trouble, which was OS version 5.0.0.337, was updated to 5.0.0.973. The problem was fixed with the OS upgrade.