09-27-2009 05:04 PM - edited 09-27-2009 05:06 PM
Hello,
I am getting a strange error when opening a ssl connection to a server. The error occurs both on the simulator and the actual device (BB 8310, V4.5). The first time the connection is established, it functions correctly. When the application exits, the disconnect function is triggered and returns no exceptions. However, when trying to reconnect i recieve the error javax.microedition.io.ConnectionNotFoundException. If I erase the simulator files and run the appliction again it functions correctly, but again, only the first time. I found a post with the same problem but no answer. However, if i run the same application on the 8900 or 9000 simulator or device, the connection functions correctly each time.
private void connect()throws Exception{
String ipAddress = loadIP();
String url = "ssl://" + ipAddress + ":9876;deviceside=true";
connection = (SecureConnection)Connector.open(url);
_out = new StringOutputStream (new DataOutputStream(connection.openOutputStream()));
_out.flush();
_in = new StringInputStream (new DataInputStream(connection.openInputStream()));
read = new readThread();
read.start();
}
public void disconnect(){
try{
_in.close();
}catch(Exception e3){
System.out.println("_IN.CLOSE() EXCEPTION: "+e3.toString());
}
try{
_out.close();
}catch(Exception e2){
System.out.println("_OUT.CLOSE() EXCEPTION: "+e2.toString());
}
try{
connection.close();
}catch(Exception e4){
System.out.println("CONNECTION.CLOSE() EXCEPTION: "+e4.toString());
}
}
The actual exception is thrown by the line:
connection = (SecureConnection)Connector.open(url);
09-28-2009 06:39 AM - edited 09-28-2009 06:43 AM
09-28-2009 07:24 AM
09-28-2009 03:34 PM
I trimmed out all extraneous code to test the connection and the issue still occurs. Here is the entire code that produces the javax.microedition.io.ConnectionNotFoundException in v4.5
import java.io.*; import net.rim.device.api.ui.UiApplication; import javax.microedition.io.*; class TestApp extends UiApplication{ SecureConnection connection = null; public static void main(String[] args){ new TestApp().enterEventDispatcher(); } public TestApp() { try{ connect(); }catch(Exception e){ System.out.println("CONNECT 1 ERROR: "+e.toString()); } try{ disconnect(); }catch(Exception e){ System.out.println("DISCONNECT ERROR: "+e.toString()); } try{ connect(); }catch(Exception e){ System.out.println("CONNECT 2 ERROR: "+e.toString()); } } private void connect()throws Exception{ connection = (SecureConnection)Connector.open("ssl://10.192.72.
131:9876;deviceside=true"); } public void disconnect()throws Exception{ connection.close(); } }
Output in v4.5:
Started TestApp(156)
Foreground TestApp(156)
SSL:->CH
SSL:<-SH
SSL:<-SKE
SSL:<-SHD
SSL:->CKE
SSL:->CCS
TLS:->F
TLS:<-F
SSL: Ok
CONNECT 2 ERROR: javax.microedition.io.ConnectionNotFoundException
Output in v4.6:
Started TestApp(211)
Foreground TestApp(211)
SSL:->CH
SSL:<-SH
SSL:<-SKE
SSL:<-SHD
SSL:->CKE
SSL:->CCS
TLS:->F
TLS:<-F
SSL: Ok
SSL:->CH
SSL:<-SH
SSL:<-SKE
SSL:<-SHD
SSL:->CKE
SSL:->CCS
TLS:->F
TLS:<-F
SSL: Ok
Any help on this would be greatly appreciated!
09-28-2009 04:31 PM - edited 09-28-2009 04:39 PM
Interesting!
Try the following two things separately:
1. Add a delay (say, 10 seconds) between the first disconnect() and the second connect().
2. Establish a socket:// connection to the same IP+port, then wrap it into a TLS10Connection using "new TLS10Connection(socketConnection)".
09-28-2009 07:30 PM
1. The time difference does not appear to have any effect on the appearance of the ConnectionNotFoundException
2. Exact same behaviour on the 8310. The connection functions as expected the first time, and then any subsequent reconnections fail. The exception given now though is Java.lang.illegalArgumentException. I have verified that the arguments being passed are the same for a successful run and a non successful run. Again, the TLS10Connection functions correctly for each connection on the BB 9000, v4.6
09-28-2009 07:44 PM - edited 09-28-2009 07:57 PM
Where does the IllegalArgumentException occur (Connector.open or TLS10Connection)? Would you please post the stack trace?
P.S. You can obtain the stack trace by catching Throwable instead of Exception. In this case the stack trace will automatically be logged in the EventLog and the Debugger will also break (by default) as soon as the exception is thrown.
09-28-2009 09:39 PM - edited 09-28-2009 09:49 PM
IllegalArgumentException occurs at TLS10Connection.
Stack Trace:
CertificateChainFactory.createCertificateChains( Certificate, Certificate[], KeyStore, String )
CertificateUtilities.buildCertificateChains( Certificate, Certificate[], KeyStore, String )
CertificateUtilities.buildCertificateChains( Certificate, Certificate[], KeyStore )
SSLHandshakeProtocol.determineBestCertificateChain
SSLHandshakeProtocol.clientHello( )
SSLHandshakeProtocol.connect( )
SSLRecordProtocol.connect( )
TLS10Connection.TLS10Connection( StreamConnection, String, boolean, TLSRecordProtocol )
TLS10Connection.TLS10Connection( StreamConnection, String, boolean )
TLS10Connection.TLS10Connection( StreamConnection, String )
Locals:
Name: Value: Type:
Exception thrown: @303F4000 java.lang.IllegalArgumentException
certificate null net.rim.device.api.crypto.certificate.Certificate
certificatePool null Certificate[]
emailAddress null java.lang.String
==================================================
When switching the connection back to:
String url = "ssl://" + ipAddress + ":9876;deviceside=true;"; connection = (SecureConnection)Connector.open(url);
Here is the stack trace produced when i get ConnectionNotFoundException:
Protocol.doConnection( URL, int, boolean )
Protocol.openPrim( String, int, boolean )
RIMConnector.open( int, String, int, boolean, FirewallContext )
RIMConnector.open( int, String, int, boolean )
Connector.open( String, int, boolean )
Protocol.openPrim( String, int, boolean )
RIMConnector.open( int, String, int, boolean, FirewallContext )
RIMConnector.open( int, String, int, boolean )
Connector.open( String )
Locals:
Name: Value: Type:
Exception thrown: @4BDE2000 javax.microedition.io.ConnectionNotFoundException
hostName @4C35A000 "192.168.0.101" java.lang.String
mode 3 int
port 9876 int
startHandshake true boolean
09-29-2009 04:52 AM
09-29-2009 09:05 AM