mongodb 3.x driver Android compatibility

前端 未结 3 473
粉色の甜心
粉色の甜心 2020-12-03 19:55

I\'m developing an Android app that use the java mongodb driver 3.0.3 to connect to every instance of mongodb.

The connector code to a generic istance is:

         


        
3条回答
  •  醉话见心
    2020-12-03 20:09

    It looks to me like the ManagementFactory is a red herring, as the driver catches that exception and falls back to using a random number instead.

    The real problem appears to be that the driver needs to authenticate with SCRAM-SHA-1, the implementation of which imports the following classes:

    import javax.crypto.Mac;
    import javax.crypto.SecretKeyFactory;
    import javax.crypto.spec.PBEKeySpec;
    import javax.crypto.spec.SecretKeySpec;
    import javax.security.sasl.SaslClient;
    import javax.security.sasl.SaslException;
    

    I suspect that these are not available in the Android platform, which is not a complete implementation of the Java Runtime Environment.

    One thing you could try would be to run against MongoDB 2.6, against which the driver's authentication implementation only relies on java.security.MessageDigest.

    Another thing to think about is putting a REST service between the mobile app and MongoDB that is responsible for proxying all interactions with the database. The REST application can be run in an environment where the MongoDB driver will be fully functional.

提交回复
热议问题