cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect to the MobiLink Server on Android using HTTPS?

Former Member
0 Kudos
4,566
SyncParms sp = _conn.createSyncParms(SyncParms.HTTPS_STREAM, "ml_username", "script_version");
StreamHTTPSParms streamParms = (StreamHTTPSParms) syncParms.getStreamParms();
streamParms.setHost( host );
streamParms.setPort( port );
_conn.synchronize(sp);

I have started my MobiLink server correctly:

<Main> https.2500: RSA_TLS: This secure stream is being encrypted using security technology from Certicom Corp.
<Main> This software is using security technology from Certicom Corp.
<Main> MobiLink server started

If I try to connect to the ML server through my android app I get Error code 224. (I have no problems connecting through HTTP)

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member

The next thing to verify is that the 2nd parameter to DatabaseManager.createConfigurationFileAndroid() is a valid Context object. Eg.

ConfigFileAndroid config = DatabaseManager.createConfigurationFileAndroid(
        "test.udb",
        getApplicationContext());
Former Member
0 Kudos

When executing DatabaseManager.createConfigurationFileAndroid the second parameter has the value: android.app.Application@44ef4458 (I can see this in debug mode). Also, when executing the same code but trying to connect to an HTTP server i have no problems, so I asume it is a valid context object. Any other suggestions?

Former Member
0 Kudos

Everything seems right. You say you are using the Android emulator? Which platform are you targetting? Can you give a small test program that reproduces the error? Thanks.

Former Member
0 Kudos

I modified our custdb sample to use HTTPS data sync (pasting in some of the code you provided), but still could not reproduce the problem.

It occurs to me that it could be the MobiLink server that could not find a library. Where do you see the error message with code 224? In the ML server log? A ULjException in the client application? Also, please give us the exact text of the error message.

The below is the ULjException that I get in the custdb application if I manually remove libmlcrsa12.so from the emulator:

08-24 10:50:08.448: ERROR/CustDB(273): com.ianywhere.ultralitejni12.implementation.JniException: UltraLiteJ Error[-1305]: MobiLink communication error -- code: 224, parameter: libmlcrsa12.so, system code: 0

Former Member
0 Kudos

The error is the same as you posted:

com.ianywhere.ultralitejni12.implementation.JniException: UltraLiteJ Error[-1305]: MobiLink communication error -- code: 224, parameter: libmlcrsa12.so, system code: 0

but I have data/data/<package>/lib/libmlcrsa12.so in the emulator.

Former Member
0 Kudos

I am almost out of ideas. You could check that the libmlcrsa12.so that is in the emulator is byte-for-byte the same as the one in the SQL Anywhere install.

If that is the case, the only other thing is that something in your application is different from the applications we use to test with. Could you package up a complete Eclipse project that shows the problem? (eg. using the ML server command line for our custdb sample, with the sample rasroot.crt in the install) If we can reproduce the problem, then we can fix it. Thanks.

Former Member
0 Kudos

PS You can email me the sample Eclipse project at firstname.lastname [at] sybase.com

Andy Quick Sybase, an SAP company

Former Member
0 Kudos

Sebastian - We cannot reproduce this issue here: our samples using HTTPS do work. You could test your environment by trying the CustDB sample included with SQL Anywhere and changing StreamHTTPParms to StreamHTTPSParms, to see if that project works for you. Otherwise, emailing the project as suggested or opening a tech support case look like the ways forward.

Former Member

Error code 224 is "Failed to load library" (see here).

It looks like you need to include the library libmlcrsa12.so in the same folder as the UltraLite library (the libsarmeabi subdirectory of your project). You can find libmlcrsa12.so in the UltraLite\\UltraLiteJ\\Android\\ARM subdirectory of your SQL Anywhere application.

If you have any issues with certificates for HTTPS, you may find something in a recent blog post on the subject: see here.

Former Member
0 Kudos

In my project, I have the library libmlcrsa12.so in my libs/armeabi folder. When I deploy my project to the emulator I found the libmlcrsa12.so and libultralitej12.so under data/data/<my-project-package>/lib/

I've also created my HTTPS certificates and started my MobiLink server correctly, but still can't connect through my app.

Thanks for your help.

Former Member
0 Kudos

Are you still getting Error Code 224? As I say, that's "Failed to load library". If it's not a missing library, then I am not sure what would be causing it.

Former Member
0 Kudos

Yes, i am still getting error code 224. The library is not missing, it is just not loading.

Former Member
0 Kudos

Here is my code:

Connection _conn;
ConfigPersistent _config;

public void onCreate(Bundle savedInstanceState) {
    try{
        super.onCreate(savedInstanceState);

    InputStream is = getResources().openRawResource(R.raw.cert);
    FileOutputStream os = openFileOutput("cert.pem", MODE_PRIVATE);
    byte[] buff = new byte[4096];
    int n;
    for(;;) {
        n = is.read(buff);
    if (n < 0) break;
    os.write(buff, 0, n);
    }

        _config = DatabaseManager.createConfigurationFileAndroid("DATABASE_NAME", getApplicationContext());
        _config.setLazyLoadIndexes(true);
        _conn = DatabaseManager.connect(_config);
        _conn = DatabaseManager.connect(_config);

        SyncParms syncParms = _conn.createSyncParms(SyncParms.HTTPS_STREAM,_user,_version );
    syncParms.setPassword("passwordd");

        StreamHTTPSParms streamParms = (StreamHTTPSParms) syncParms.getStreamParms();
    streamParms.setHost( _host );
    streamParms.setPort( _port );
    streamParms.setTrustedCertificates("/data/data/<package>/files/cert.pem");
        _conn.synchronize( syncParms );
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I am using an Android 2.2 emulator.
Thanks for your help.

Former Member

One thing I notice in this code fragment is that the ConfigFileAndroid object that is returned by DatabaseManager.createConfigurationFileAndroid() is not stored in a variable. You must actually pass this object as an argument to DatabaseManager.createDatabase() or connect(). Using a ConfigPersistent object that was created without going through createConfigurationFileAndroid() would cause a problem like this.

Former Member
0 Kudos

I edited the code, i was actually doing what you say ... buy still get the error.